[英]How do you convert a pollingDuplex binding into a custom binding?
我在我的Silverlight Web應用程序和WCF Web服務之間的通信中使用pollingDuplex綁定。 直到我嘗試將大量數據以xmlString的形式從Web應用程序發送到Web服務之前,它一直運行良好。 然后我得到了錯誤信息:
“格式化程序嘗試對消息進行反序列化時引發了異常:對操作'SendUserSelection'的請求消息主體進行反序列化時出錯。讀取XML數據時,已超出最大字符串內容長度配額(8192)。可以通過更改來增加此配額創建XML閱讀器時使用的XmlDictionaryReaderQuotas對象的MaxStringContentLength屬性。”
我發現為了增加MaxStringContentLength屬性,我必須將pollingDuplex綁定轉換為自定義綁定( http://blogs.msdn.com/b/silverlightws/archive/2010/04/04/some-known-wcf- issue-in-silverlight-4.aspx )。 我的問題是我該怎么做?
在Web服務的web.config文件中定義的我的pollingDuplex綁定如下所示:
<pollingDuplex>
<binding name="myPollingDuplex" closeTimeout="00:10:00" openTimeout="00:10:00"
receiveTimeout="00:10:00" sendTimeout="00:10:00" duplexMode="MultipleMessagesPerPoll" />
端點:
<endpoint address="" binding="pollingDuplex" bindingConfiguration="myPollingDuplex" contract="WebApplication.Web.MainWS"/>
Web應用程序端用於實例化Web服務客戶端的代碼:
this.client = new MainWSRef.MainWSClient(new PollingDuplexHttpBinding { DuplexMode = PollingDuplexMode.MultipleMessagesPerPoll },
new EndpointAddress("http://localhost:1981/MainWS.svc"));
我嘗試了以下方法:
<customBinding>
<binding name="myPollingDuplex" closeTimeout="00:10:00" openTimeout="00:10:00"
receiveTimeout="00:10:00" sendTimeout="00:10:00">
<pollingDuplex duplexMode="MultipleMessagesPerPoll">
</pollingDuplex>
<textMessageEncoding>
<readerQuotas maxDepth="32" maxStringContentLength="5242880"
maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</customBinding>
終點:
<endpoint address="" binding="customBinding" bindingConfiguration="myPollingDuplex" contract="WebApplication.Web.MainWS"/>
Web應用程序端的代碼:
CustomBinding binding = new CustomBinding(new PollingDuplexBindingElement(), new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement());
this.client = new MainWSRef.MainWSClient(binding, new EndpointAddress("http://localhost:1981/MainWS.svc"));
當我嘗試運行代碼時,出現以下錯誤消息:
“遠程服務器返回錯誤:NotFound。”
難道我做錯了什么? 我將不勝感激任何建議。
當我指定ReceiveTimeout="02:00:00"
,出現相同的錯誤,如果沒有,它將正常工作。 我嘗試找出如何正確設置ReveiveTimeout。
更新:我認為它的工作,這就是我的服務器web.config:
<customBinding>
<binding name="SLDuplexService" receiveTimeout="02:00:00">
<pollingDuplex duplexMode="MultipleMessagesPerPoll"
maxPendingSessions="2147483647" maxPendingMessagesPerSession="2147483647" maxOutputDelay="00:00:05"
inactivityTimeout="02:00:00" />
<binaryMessageEncoding/>
<httpTransport transferMode="StreamedResponse"/>
</binding>
</customBinding>
請注意,receiveTimeout是綁定的屬性,而inactivityTimeout是pollingDuplex的屬性。 如果您不希望在10分鍾后出現故障通道,則必須設置兩個超時時間。
您還必須在客戶端上指定超時,那就是我的代碼:
PollingDuplexHttpBinding binding = new PollingDuplexHttpBinding(PollingDuplexHttpSecurityMode.None, PollingDuplexMode.MultipleMessagesPerPoll);
binding.InactivityTimeout = new TimeSpan(2,0,0);
binding.ReceiveTimeout = new TimeSpan(2, 0, 0);
_client = new SLDuplexServiceClient(binding, new EndpointAddress("http://localhost/LpSystem.ServiceInterface.Web/SLDuplexService/SLDuplexService.svc"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.