具有大参数的WCF服务

时间:2011-01-27 18:25:36

标签: c# wcf wcf-client

我在SO上看了很多类似的主题,但没有找到一个对此有帮助的主题。

拥有一个接受XML处理的WCF服务。我正在读取的XML文件大约是600K。

该调用适用于小型xml文件(大多数情况下),但在较大的文件中,我收到错误:

  

System.ServiceModel.Security.MessageSecurityException:
  从另一方收到了无担保或不正确安全的故障。请参阅内部FaultException以获取故障代码和详细信息。

内部异常是:

  

System.ServiceModel.FaultException:
  邮件无法处理。这很可能是因为“http://tempuri.org/ISapListener/ProcessSapRoles”操作不正确,或者因为邮件包含无效或过期的安全上下文令牌,或者因为绑定之间存在不匹配。如果服务因不活动而中止通道,则安全上下文令牌将无效。要防止服务中止空闲会话,请过早增加服务端点绑定的接收超时。

就像我说的......它适用于小文件,我的打开,发送,接收,关闭和不活动超时都设置为10分钟。它在大约20-30秒内失败。

此外,服务器和客户端上的时钟完全同步(我已经看到发布作为答案)。

我目前的配置文件(我玩了很多设置):

服务器:

<bindings>
  <wsHttpBinding>
    <binding name="wsHttpBinding_Custom" closeTimeout="00:00:10"
             openTimeout="00:01:00" receiveTimeout="00:10:00"
             sendTimeout="00:10:00" bypassProxyOnLocal="false" 
             transactionFlow="false" hostNameComparisonMode="StrongWildcard"
             messageEncoding="Text" textEncoding="utf-8" 
             useDefaultWebProxy="true" allowCookies="false"
             maxReceivedMessageSize="1024768"            
             maxBufferPoolSize="1024768" >
      <readerQuotas maxDepth="32" maxBytesPerRead="4096" 
                    maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00" 
                       enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None" 
                   realm="" />
        <message clientCredentialType="Windows" 
                 negotiateServiceCredential="true"
                 algorithmSuite="Default" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="CSA.GS3.Services.SapListenerBehavior" 
           name="CSA.GS3.Services.SapListener">
    <endpoint address="" binding="wsHttpBinding"  
              bindingConfiguration="wsHttpBinding_Custom" 
              contract="CSA.GS3.Services.ISapListener">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" 
              contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="CSA.GS3.Services.SapListenerBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

客户端:

<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_ISapListener1" 
             closeTimeout="00:10:00" openTimeout="00:10:00" 
             receiveTimeout="00:10:00" sendTimeout="00:10:00"
             bypassProxyOnLocal="false" transactionFlow="false"
             hostNameComparisonMode="StrongWildcard"
             messageEncoding="Text" textEncoding="utf-8" 
             useDefaultWebProxy="true" allowCookies="false"
             maxBufferPoolSize="1024768" 
             maxReceivedMessageSize="1024768">
      <readerQuotas maxDepth="32" maxBytesPerRead="4096" 
                    maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
                       enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="Windows" 
                 negotiateServiceCredential="true"
                 algorithmSuite="Default" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="http://gs3-test.us.tycoelectronics.com/SapListener/SapListener.svc"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ISapListener1"
            contract="Gs3TestSapListener.ISapListener" 
            name="WSHttpBinding_ISapListener1">
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>
</client>

我确实在服务上启用了跟踪,但我无法理解日志文件。

我在使用配置设置时收到的其他例外情况:

  

System.ServiceModel.Security.SecurityNegotiationException
  无法打开安全通道,因为与远程端点的安全协商失败。

  

System.ServiceModel.ServiceActivationException
  无法激活所请求的服务“http://../SapListener.svc”。

4 个答案:

答案 0 :(得分:0)

如果您认为能够理解日志文件会对此有所帮助,请使用svcTraceViewer。只需确保您确实正确设置了跟踪。我的博客上有一篇关于此的文章。 svcTraveViewer Debugging WCF Services

关于大型有效负载,您可能需要查看此MSDN文章。 http://msdn.microsoft.com/en-us/library/ms733742.aspx

特别是流式数据。

答案 1 :(得分:0)

System.ServiceModel.ServiceActivationException
The requested service, 'http://../SapListener.svc' could not be activated.

这可能是编译错误,配置无效。

是WCF 4.0吗?然后,您可以删除自定义配置并使用自动绑定。我还建议你尝试除wsHttpBinding以外的绑定,比如basicHttpBinding。

答案 2 :(得分:0)

我能够通过以下配置使用它:

服务器:

<bindings>
  <wsHttpBinding>
    <binding name="wsHttpBinding_Custom"
             closeTimeout="00:10:00"
             openTimeout="00:10:00"
             receiveTimeout="00:10:00"
             sendTimeout="00:10:00"
             maxReceivedMessageSize="2097152"
             bypassProxyOnLocal="false" transactionFlow="false" 
             hostNameComparisonMode="StrongWildcard"
             maxBufferPoolSize="2097152" messageEncoding="Text"
             textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxBytesPerRead="4096" 
                    maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None" 
                   realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true" 
                 algorithmSuite="Default" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

客户:

<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_ISapListener1" closeTimeout="00:10:00"
             openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
             bypassProxyOnLocal="false" transactionFlow="false" 
             hostNameComparisonMode="StrongWildcard"
             maxBufferPoolSize="2097152" 
             maxReceivedMessageSize="2097152"
             messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
             allowCookies="false">
      <readerQuotas maxDepth="32" maxBytesPerRead="4096" 
                    maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
                       enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None"
                   realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                 algorithmSuite="Default" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

我能看到的唯一区别是我碰到了maxReceivedMessageSize和maxBufferPoolSize ...也许我错过了其他的东西?如果这是问题,那么问题是我的呼叫开销是为我发送的600K xml数据添加额外的400 + K

答案 3 :(得分:0)

如果客户端可能并且可以接受,您可以将文件分解为更小的块并发送,只要您没有客户端的数字证书等和排序选项。

相关问题