2008-09-25 58 views
3

我有一個簡單的Web服務,它需要2個參數,一個是簡單的xml安全令牌,另一個通常是一個長xml字符串。它適用於短字符串,但更長的字符串會提供400錯誤消息。 maxMessageLength沒有做任何事情來允許更長的字符串。WCF - 如何接受長字符串作爲參數

回答

2

您應該刪除配額限制。 這裏是你如何使用Tcp綁定來完成代碼。 我添加了一些代碼,顯示刪除超時問題,因爲通常發送非常大的參數會導致超時問題。所以明智地使用代碼... 當然,您也可以在配置文件中設置這些參數。

 NetTcpBinding binding = new NetTcpBinding(SecurityMode.None, true); 

     // Allow big arguments on messages. Allow ~500 MB message. 
     binding.MaxReceivedMessageSize = 500 * 1024 * 1024; 

     // Allow unlimited time to send/receive a message. 
     // It also prevents closing idle sessions. 
     // From MSDN: To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.’ 
     binding.ReceiveTimeout = TimeSpan.MaxValue; 
     binding.SendTimeout = TimeSpan.MaxValue; 

     XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas(); 

     // Remove quotas limitations 
     quotas.MaxArrayLength = int.MaxValue; 
     quotas.MaxBytesPerRead = int.MaxValue; 
     quotas.MaxDepth = int.MaxValue; 
     quotas.MaxNameTableCharCount = int.MaxValue; 
     quotas.MaxStringContentLength = int.MaxValue; 
     binding.ReaderQuotas = quotas; 
3

配額我只是做了所有在web.config

<bindings> 
    <wsHttpBinding> 
    <binding name="WSHttpBinding_IPayroll" maxReceivedMessageSize="6553600"> 
     <security mode="None"/> 
     <readerQuotas maxDepth="32" 
        maxStringContentLength="6553600" 
        maxArrayLength="16384" 
        maxBytesPerRead="4096" 
        maxNameTableCharCount="16384" /> 
    </binding> 
    </wsHttpBinding> 
</bindings> 
+0

多久了您的字符串的回答後?你用什麼合同? 我有MessageContract和字符串是64k字符長。 – Tuoski 2009-09-09 13:51:05