Search code examples
wcfazureserviceazureservicebusbus

Connecting IIS deployed WCF service with Azure service bus


I am trying to connect an on premise WCF service with azure service bus now i have went over the documentation and they have examples only for sf hosted wcf services but not when the service is hosted on a IIS server and all you have is the url from which you can consume the service. I have set up my IIS server for preload and always running to true, but i don't have idea how to connect the service. So i would like to ask if someone of you has already done that to point me in the right direction or at least to point me to some viable documentation from which i can learn how to do that.

Thank You.


Solution

  • Okay I know how this looks like, answering my own question but yesterday when I asked it I was was on the brink of throwing my laptop out of the window :).

    The irritating thing is that tutorials that Microsoft and the azure community provides are only addressing the issue when you are hosting the wcf service in a console application and not IIS which should principle-wise be the same but for some reason was not. So here is the part of the web config for connecting an on premise wcf service deployed on corporate IIS not visible outside the corporate network.

    <behaviors>
          <serviceBehaviors>
            <behavior name="">
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="ServiceBusBehavior">
              <transportClientEndpointBehavior>
                <tokenProvider>
                  <!--Endpoint=sb://bus-weather.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=e/JdrCvjy/l8nuYYCHXdfssfsfsfsfsfsfsM=-->
                  <sharedAccessSignature keyName="RootManageSharedAccessKey" key="e/JdrCvjy/l8nuYYCHXdfssfsfsfsfsfsfsM=" />
                </tokenProvider>
              </transportClientEndpointBehavior>
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
        <services>
          <service name="connectServiceBus.GetWeather">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="DefaultBinding" contract="connectServiceBus.IGetWeather"/>
            <endpoint address="sb://bus-weather.servicebus.windows.net/weatherSRV" binding="netTcpRelayBinding" behaviorConfiguration="ServiceBusBehavior" contract="connectServiceBus.IGetWeather"/>
          </service>
        </services>
        <bindings>
          <basicHttpBinding>
            <binding name="DefaultBinding" />
          </basicHttpBinding>
          <netTcpRelayBinding>
            <binding name="ServiceBusBinding" />
          </netTcpRelayBinding>
        </bindings>
    

    Just add the above snippet in the <system.serviceModel> tag of the web config of your wcf service and you should be done, please note that you have to install the service bus NuGet package.
    The testing client can be a simple console application as in the examples. For the beginners in azure as me, don't worry if the tags light up blue as non existent it will work. Keep calm and develop :)