Search code examples
wcfappfabricservicebus

WCF and Windows Server Service Bus Endpoints


I need to develop a Windows Server Service Bus topic subscriber (yes, Windows Server and not Azure), and in order to abstract away from the reading, start worker thread, ..., cycle and to take advantage of AppFabric management capabilities, i had the following idea:

  • Develop a WCF service
  • Define a Windows Server Service Bus endpoint

And the questions are:

  1. A publisher must use the Service Contract to send messages to the topic?
  2. What should the configuration file look like?

Thanks in advance.


Solution

  • To help future related problems here is the required configuration

    Extensions required both in publisher and subscriber configuration:

    <extensions>
      <behaviorExtensions>
        <add name="transportClientEndpointBehavior" type="Microsoft.ServiceBus.Configuration.TransportClientEndpointBehaviorElement, Microsoft.ServiceBus, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </behaviorExtensions>
    
      <bindingExtensions>
        <add name="netMessagingBinding" type="Microsoft.ServiceBus.Messaging.Configuration.NetMessagingBindingCollectionElement, Microsoft.ServiceBus, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </bindingExtensions>
    </extensions>
    

    Note: The Microsoft.ServiceBus assembly is required both in the publisher as well in the subscriber. The package is available in Nuget.

    Subscriber side configuration:

    <bindings>
      <netMessagingBinding>
        <binding name="messagingBinding" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:03:00" sendTimeout="00:03:00" sessionIdleTimeout="00:01:00" prefetchCount="-1">
          <transportSettings batchFlushInterval="00:00:01" />
        </binding>
      </netMessagingBinding>
    </bindings>
    
    <behaviors>
      <endpointBehaviors>
        <behavior name="securityBehavior">
          <messageInterceptorBehavior/>
          <transportClientEndpointBehavior>
            <tokenProvider>
              <windowsAuthentication>
                <stsUris>
                  <stsUri value="https://[SERVER]:9355/[NAMESPACE]" />
                </stsUris>
              </windowsAuthentication>
            </tokenProvider>
          </transportClientEndpointBehavior>
    </behavior>
    
    <endpoint listenUri="sb://[SERVER]/[NAMESPACE]/[TOPIC]/Subscriptions/[SUBSCRIPTIONNAME]"
                  address="sb://[SERVER]/[NAMESPACE]/[TOPIC]"
                  behaviorConfiguration="securityBehavior" binding="netMessagingBinding"
                  bindingConfiguration="messagingBinding" name="InsuranceService"
                  contract="[WCF_CONTRACT_NAME]" />
    

    Publisher configuration:

    <bindings>
      <netMessagingBinding>
        <binding name="InsuranceService" closeTimeout="00:03:00" openTimeout="00:03:00"
          receiveTimeout="00:03:00" sendTimeout="00:03:00" prefetchCount="-1"
          sessionIdleTimeout="00:01:00">
          <transportSettings batchFlushInterval="00:00:01" />
        </binding>
      </netMessagingBinding>
    </bindings>
    
    <behaviors>
      <endpointBehaviors>
        <behavior name="securityBehavior">
          <messageInterceptorBehavior/>
          <transportClientEndpointBehavior>
            <tokenProvider>
              <windowsAuthentication>
                <stsUris>
                  <stsUri value="https://[SERVER]:9355/[NAMESPACE]" />
                </stsUris>
              </windowsAuthentication>
            </tokenProvider>
          </transportClientEndpointBehavior>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    
    <client>
      <endpoint address="sb://[SERVER]/[NAMESPACE]/[TOPIC]"
        behaviorConfiguration="securityBehavior" binding="netMessagingBinding"
        bindingConfiguration="InsuranceService" contract="PushVoucherService.ISubscriber"
        name="InsuranceService" />
    </client>