我有一個WCF服務,我用C#寫的,它傳遞給調用者(一個C#WPF應用程序)實例化對象的集合。但是,如果我返回的集合具有太多對象,那麼在大約10秒後,客戶端調用會失敗,並且會出現泛型異常(本身包含一系列通用內部異常)。這裏是異常和內部異常:由於太多數據傳遞WCF服務調用失敗?
{「,而接收到http://myserver/MyAppService/MyAppService.svc HTTP響應時發生錯誤這可能是由於 服務端點不使用HTTP協議綁定這可能 也可因。 HTTP請求上下文被服務器 中止(可能由於服務關閉)。請參閱服務器日誌以獲取更多 詳細信息。「}
{」底層連接已關閉:接收方發生意外錯誤。「}
{「無法從傳輸連接讀取數據:現有連接被遠程主機強制關閉「}
{」一個現有的連接被強行關閉遠程主機「}
的問題是100%reproduceable和肯定是涉及到集合的大小,而不是內容。我知道這一點,因爲如果我將單個集合分解爲多個較小的集合並將它們一次一個地傳遞回來,它就可以正常工作。只有當他們在一起並且收集到很大時,這纔是一個問題。
我試着將客戶端的app.config
文件中的maxReceivedMessageSize
屬性增加到2147483647,但錯誤仍然存在。也嘗試增加超時時間,但沒有影響。以下是app.config
文件中的屬性。我試着增加幾乎每個號碼下面2147483647,試圖改變maxBufferPoolSize
爲0,但沒有運氣:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_iMyAppService"
closeTimeout="01:00:00" openTimeout="01:00:00"
receiveTimeout="01:00:00" sendTimeout="01:00:00"
allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="524288"
maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas
maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384" maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="WSHttpBinding_iMyAppService"
closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas
maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
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 name="CurrencyConvertorSoap"
address="http://www.webservicex.net/CurrencyConvertor.asmx"
binding="basicHttpBinding"
bindingConfiguration="CurrencyConvertorSoap"
contract="CurrencyConverterService.CurrencyConvertorSoap" />
<endpoint name="CurrencyConvertorSoap12"
address="http://www.webservicex.net/CurrencyConvertor.asmx"
binding="customBinding"
bindingConfiguration="CurrencyConvertorSoap12"
contract="CurrencyConverterService.CurrencyConvertorSoap" />
<endpoint name="WSHttpBinding_iMyAppService"
address="http://myserver/MyAppService/MyAppService.svc"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_iMyAppService"
contract="MyAppService.iMyAppService" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint name="BasicHttpBinding_iMyAppService"
address="http://myserver/MyAppService/MyAppService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_iMyAppService"
contract="MyAppService.iMyAppService" />
</client>
還有什麼更好的改變或添加,使這項工作?
謝謝!
該死的......當我看到你的回覆時,我確實充滿希望,但不幸的是,除非我沒有做對。但我將此添加到我的app.config: <行爲NAME = 「Behaviors.EndpointBehavior」> endpointBehaviors> ,然後這對我端點行:behaviorConfiguration =「Behaviors.EndpointBehavior」但是,再次......沒有工作不幸。同樣的錯誤。感謝您的幫助。 –
Nullqwerty
2012-02-17 20:01:52
我不在我的電腦上,但我非常確定您需要在主機*和*客戶端上進行設置?你有沒有嘗試過(這與@ felan的設置是一樣的)。 – 2012-02-17 20:09:04
我嘗試了Felan的建議,但那並不能解決它。我試圖將maxitemsinobjectgraph的行爲添加到服務器端web.config中,但這並沒有實現。我無法將Felan添加到服務器端,雖然因爲web.config沒有這些選項,所以我不知道該把它放在哪裏。 – Nullqwerty 2012-02-17 20:38:09