C# 具有大参数的WCF服务
我已经研究了很多类似的话题,但还没有找到一个有助于解决这个问题的 拥有一个接收XML进行处理的WCF服务。我从中读取的XML文件约为600K 该调用适用于小xml文件(大多数情况下),但对于较大的文件,我会遇到以下错误: System.ServiceModel.Security.MessageSecurityException:C# 具有大参数的WCF服务,c#,wcf,wcf-client,C#,Wcf,Wcf Client,我已经研究了很多类似的话题,但还没有找到一个有助于解决这个问题的 拥有一个接收XML进行处理的WCF服务。我从中读取的XML文件约为600K 该调用适用于小xml文件(大多数情况下),但对于较大的文件,我会遇到以下错误: System.ServiceModel.Security.MessageSecurityException: 从另一方收到未担保或未正确担保的故障。有关故障代码和详细信息,请参见内部FaultException 其中内部异常为: System.ServiceModel.Faul
从另一方收到未担保或未正确担保的故障。有关故障代码和详细信息,请参见内部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_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"
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“无法激活
如果您认为能够理解日志文件在这里会有所帮助,请使用svcTraceViewer。只需确保您已正确设置跟踪。我的博客上有一篇关于这个的文章。 关于大型有效载荷,您可能想看看这篇MSDN文章。 特别是流数据
System.ServiceModel.ServiceActivationException
The requested service, 'http://../SapListener.svc' could not be activated.
这可能是编译错误或配置无效
是WCF 4.0吗?然后可以删除自定义配置并使用自动绑定。我还建议您尝试wsHttpBinding以外的绑定,如basicHttpBinding。我能够通过以下配置实现此功能: 服务器:
<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_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数据如果可能并且客户可以接受,您可以将文件分解成更小的块并发送,前提是您在客户端没有数字证书等和排序选项。谢谢。。。我使用的是svcTraceViewer:\没有明显的错误或警告,只有信息和启动/停止。我想我只是不知道该找什么。我会仔细看看那些文章。我最初没有使用流媒体的原因是因为我需要所有的数据来处理它。。。我正在对xml运行linq查询,在WCF端读取所有xml之前,这是没有意义的,一旦收到文档,就可以像平常一样处理它。我没有使用WCF完成这项工作,但我无法想象整个管道必须依赖于流。流式传输在客户端和服务器端之间。一旦服务器“接收”了文档,所有其他处理都应该保持不变。当然,但我的理解是,流式处理的好处是,您不需要等待数据进入才开始处理。我想我可以这样做,仅仅是为了绕开计算缓冲区的大小;我看到的错误可能会在这个过程中消失…对于大文件它总是失败吗?是的。。。小的通常可以工作,虽然我有时会遇到一些问题,但通常重启服务或重试都可以解决问题顺便问一下,是否存在这样的情况:它在本地工作,但不针对远程客户端?也就是说,您有一个在本地运行的测试客户机,它发送大量内容,并且没有失败?对于哪些场景有效,哪些不有效,这让人有些困惑。有一次我确信它在本地工作,但当我将它部署到服务器上时,我不会发誓,尽管很可能配置无效,因为不需要重新编译。不幸的是,在使用3.5时,我们还要小心最大数组对象数和最大对象大小等。类似的内容在WCF中没有很好的文档记录,有时很难诊断。感谢您的警告。。。我会调查这些