2008-09-25 61 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