2009-09-10 81 views
2

我想通過WCF發送一個長字符串,大約64k字符長。發送長字符串時,我得到HTTP錯誤400.但是,當我發送較短的字符串時,一切正常。 這是我使用的WCF接口和app.config。WCF太長的字符串

我的消息協定:

[MessageContract] 
public class MessageClass 
{ 
    [MessageHeader(MustUnderstand = true)] 
    public string id; 

    [MessageBodyMember(Order=1)] 
    public string realMessage; // Long string 
} 

我曾嘗試值上升到改變的app.config設置:

<bindings> 
    <basicHttpBinding> 
    <binding 
     name="ws" 
     transferMode="Streamed" 
     messageEncoding="Mtom" 
     maxReceivedMessageSize="10067108864"> 
     <readerQuotas 
     maxDepth="32" 
     maxStringContentLength="2147483647" 
     maxArrayLength="2147483647" 
     maxBytesPerRead="4096" 
     maxNameTableCharCount="16384" /> 
     <security mode="None"> 
     <transport clientCredentialType="None"/> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 

有,我應該改變任何其他的價值?

回答

5

您還需要設置「MAXBUFFERSIZE」和「maxBufferPoolSize」你的綁定:

<bindings> 
    <basicHttpBinding> 
    <binding 
     name="ws" 
     transferMode="Streamed" 
     messageEncoding="Mtom" 
     maxReceivedMessageSize="10067108864" 
     maxBufferSize="500000" maxBufferPoolSize="500000"> 
     <readerQuotas 
     maxDepth="32" 
     maxStringContentLength="2147483647" 
     maxArrayLength="2147483647" 
     maxBytesPerRead="4096" 
     maxNameTableCharCount="16384" /> 
     <security mode="None"> 
     <transport clientCredentialType="None"/> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 

那些還默認爲WCF的標準綁定64K。不過,由於您使用的是「transferMode = Streamed」,這確實不應該是一個問題 - 也許還有其他事情正在發生。如何增加sendTimeout設置?也許你的服務只是花了很長時間迴應。

Marc

+0

maxBufferSize和maxBufferPoolSize解決了我的問題,謝謝! – Tuoski 2009-09-10 06:33:34

3

請參閱basicHttpBinding @http://msdn.microsoft.com/en-us/library/ms731361.aspx的maxReceivedMessageSize屬性。同時,默認值是65,536 KB。

+1

我在我的配置中設置了maxReceivedMessageSize =「10067108864」。 – Tuoski 2009-09-10 06:03:33

+0

根據本文引用的鏈接,maxReceivedMessageSize是一個整數值。 10,067,108,864對於32位整數值可能太小。 – 2009-09-10 06:16:55