Server side WCF (.svc) service stops working after exception

662 Views Asked by At

I'm using a duplex ReliableSecureProfile in WCF and the server will stop listening to new requests if an exception occurs on any client.

How can I make the server more resilient to failures that happen to any single client? Everything works again if I restart the server or redeploy

My client code looks like this:

            CustomBinding rspBinding = new CustomBinding();
            rspBinding.Elements.Add(new ReliableSessionBindingElement());
            rspBinding.Elements.Add(new MakeConnectionBindingElement());
            rspBinding.Elements.Add(new TextMessageEncodingBindingElement());
            rspBinding.Elements.Add(new HttpTransportBindingElement());

            DuplexChannelFactory<IProcessDataDuplex> channelFactory =
                new DuplexChannelFactory<IProcessDataDuplex>
                    (new CallbackHandler(), rspBinding, serviceAddress);

            //
            // The problem always occurs on this line.
            //
            reusableSW = new LC.Utils.WCF.ServiceWrapper<IProcessDataDuplex>(channelFactory);

My web.config looks like this:

   <system.serviceModel>

    <behaviors>
      <serviceBehaviors>
        <behavior name="rspServiceBehavior">
          <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"  />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <useRequestHeadersForMetadataAddress>
            <defaultPorts>
              <add scheme="http" port="80" />
              <add scheme="https" port="443" />
            </defaultPorts>
          </useRequestHeadersForMetadataAddress>
        </behavior>
      </serviceBehaviors>



    </behaviors>
    <bindings>
      <customBinding>
        <!-- Reliable Secure Profile -->
        <binding name="rspBinding">
          <reliableSession />
          <MakeConnectionBindingElement/>
          <textMessageEncoding />
          <httpTransport />
        </binding>
      </customBinding>

      <netTcpBinding>
        <binding portSharingEnabled="true" >
          <security mode="None" />
        </binding>
      </netTcpBinding>

    </bindings>

    <extensions>
      <bindingElementExtensions>

        <!-- Reliable Secure Profile -->
        <add name="MakeConnectionBindingElement" type="Microsoft.Samples.ReliableSecureProfile.MakeConnectionElement, Microsoft.Samples.ReliableSecureProfile.MakeConnectionChannel" />

      </bindingElementExtensions>
    </extensions>

    <services>


      <!-- Reliable Secure Profile -->
      <service behaviorConfiguration="rspServiceBehavior" name="Microsoft.Samples.ReliableSecureProfile.RSPService">
        <endpoint binding="customBinding" bindingConfiguration="rspBinding"
            contract="Microsoft.Samples.ReliableSecureProfile.IProcessDataDuplex"
            listenUriMode="Explicit">
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
            contract="IMetadataExchange" />
        <host>
        </host>
      </service>

      <!--<service name="WcfTcpTest.Service1" >
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:1337/Service1/" />
          </baseAddresses>
        </host>
        <endpoint address="" binding="netTcpBinding" contract="WcfTcpTest.IService1">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
      </service>-->

    </services>
    <protocolMapping>
      <clear/>
      <!-- removes all defaults which you may or may not want. -->
      <!-- If not, use <remove scheme="http" /> -->
      <add scheme="http" binding="customBinding" bindingConfiguration="rspBinding"/>
    </protocolMapping>
    <serviceHostingEnvironment
      aspNetCompatibilityEnabled="false"

      multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
1

There are 1 best solutions below

0
On BEST ANSWER

I can't reproduce this issue anymore (where the server simply stops responding). I think the issue is related to VS2010's desire to catch handled exceptions and stop all threads as explained here:

Getting an Unhandled Exception in VS2010 debugger even though the exception IS handled