服务器端WCF(.svc)服务在异常后停止工作

时间:2011-05-30 22:47:10

标签: wcf exception web-config svc reliable-secure-profile

我在WCF中使用双工ReliableSecureProfile,如果在任何客户端上发生异常,服务器将停止侦听新请求。

如何让服务器对任何单个客户端发生的故障更具弹性?如果我重新启动服务器或重新部署

,一切都会再次运行

我的客户端代码如下所示:

            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);

我的web.config看起来像这样:

   <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 个答案:

答案 0 :(得分:0)

我无法再重现此问题(服务器只是停止响应)。我认为这个问题与VS2010希望捕获处理异常并停止所有线程有关,如下所述:

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

相关问题