Search code examples
wcfappfabricservicebus

Windows Service Bus 1.0, Appfabric, Netmessagingbinding failuring


I seem to run into the same problem over and over again when I am trying to host a WCF service in Windows Server AppFabric that uses netmessagingbinding to receive messages from Windows Service Bus 1.0 queues. AppFabric aborts the service, so if I press F5 on service?wsdl then I sometimes get failures, sometimes I get a nice WSDL generated. Where is my mistake? It is rather impossible to find an example that uses AppFabric, netmessagingbinding and Windows Service Bus (not Azure), so I haven't been able to finde my mistake...

[ServiceContract]
public interface ISBMessageService
{
    [OperationContract(IsOneWay = true, Action = "DoSomething")]
    [ReceiveContextEnabled(ManualControl = true)]
    void DoSomething(string something);
}

[ServiceBehavior]
public class SBMessageService : ISBMessageService
{
    [OperationBehavior]
    public void DoSomething(string something)
    {
        Trace.WriteLine(String.Format("You sent {0}", something));

        // Get the BrokeredMessageProperty from the current OperationContext
        var incomingProperties = OperationContext.Current.IncomingMessageProperties;
        var property = incomingProperties[BrokeredMessageProperty.Name] as BrokeredMessageProperty;

        ReceiveContext receiveContext;

        if (ReceiveContext.TryGet(incomingProperties, out receiveContext))
        {
            receiveContext.Complete(TimeSpan.FromSeconds(10.0d));
        }
        else
        {
            throw new InvalidOperationException("...");
        }             
    }
}

<?xml version="1.0"?>
<configuration>
  <appSettings>
  <!-- Service Bus specific app setings for messaging connections -->
  <add key="Microsoft.ServiceBus.ConnectionString"       
      value="Endpoint=sb://LRNcomp/LRNnamespace"/>
  </appSettings>
 <system.web>
     <compilation debug="true" targetFramework="4.0"/>
     <httpRuntime/>
 </system.web>
 <system.serviceModel>
  <!-- These <extensions> will not be needed once our sdk is installed-->
    <extensions>
      <bindingElementExtensions>
        <add name="netMessagingTransport"      type="Microsoft.ServiceBus.Messaging.Configuration.NetMessagingTransportExtensionElement, Microsoft.ServiceBus, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  </bindingElementExtensions>
  <bindingExtensions>
    <add name="netMessagingBinding" type="Microsoft.ServiceBus.Messaging.Configuration.NetMessagingBindingCollectionElement, Microsoft.ServiceBus, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  </bindingExtensions>
  <behaviorExtensions>
    <add name="transportClientEndpointBehavior" type="Microsoft.ServiceBus.Configuration.TransportClientEndpointBehaviorElement, Microsoft.ServiceBus, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  </behaviorExtensions>
</extensions>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="True" httpHelpPageEnabled="True"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="securityBehavior">
      <transportClientEndpointBehavior>
        <tokenProvider>
          <sharedSecret issuerName="owner" issuerSecret="somthing"/>
        </tokenProvider>
      </transportClientEndpointBehavior>
    </behavior>
  </endpointBehaviors>
</behaviors>
<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>
<services>
  <service name="SBExamples.SBMessageService">
    <endpoint name="Service1" address="sb://LRNcomp:9354/LRNnamespace/test/myqueue2" binding="netMessagingBinding" bindingConfiguration="messagingBinding" contract="SBExamples.ISBMessageService" behaviorConfiguration="securityBehavior"/>
  </service>
</services>
</system.serviceModel>
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
  <!--
    To browse web app root directory during debugging, set the value below to true.
    Set to false before deployment to avoid disclosing web app folder information.
  -->
  <directoryBrowse enabled="true"/>
</system.webServer>
</configuration>

Solution

  • An error in the WCF contract generated many strange exceptions, like my transport channel was aborted. Proper sharing of contract between sender and receiver did the trick.