[英]WCF Service with large parameters
我已經看過許多關於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”無法激活。
如果您認為能夠從日志文件中解脫出來對您有所幫助,請使用svcTraceViewer。 只要確保您已正確設置跟蹤即可。 我的博客上有一篇關於此的文章。 svcTraveViewer調試WCF服務
關於大型有效負載,您可能需要看一下這篇MSDN文章。 http://msdn.microsoft.com/en-us/library/ms733742.aspx
特別是流數據。
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: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
如果可能並為客戶端所接受,您可以將文件分解為較小的塊,然后進行發送,前提是您沒有客戶端的數字證書等和排序選項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.