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



我在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>

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

在VS2010调试器中获取未处理的异常,即使异常IS已处理

相关内容

  • 没有找到相关文章

最新更新