我有一個簡單的Web服務,它需要2個參數,一個是簡單的xml安全令牌,另一個通常是一個長xml字符串。它適用於短字符串,但更長的字符串會提供400錯誤消息。 maxMessageLength沒有做任何事情來允許更長的字符串。WCF - 如何接受長字符串作爲參數
3
A
回答
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>
相關問題
- 1. 將查詢字符串參數添加到WCF服務操作接受流
- 2. 字符串作爲參數
- 3. 如何在objc_msgSend()中傳遞直接字符串作爲參數?
- 4. 如何使用GET傳遞連接字符串作爲參數?
- 5. WCF太長的字符串
- 6. WCF接口作爲參數
- 7. 字符串文字參數不被接受到constexpr函數
- 8. 爲什麼插入和子串字符串方法不接受無符號的64位整數作爲參數?
- 9. Wcf post方法與長json字符串參數
- 10. WCF/Rest/UriTemplate可變長度查詢字符串參數列表?
- 11. Erlang如何接受字符串?
- 12. 作爲ASMX公開的WCF服務將不接受參數
- 13. NHibernate的 - 設置長字符串作爲參數查詢
- 14. ResourceBundle/Propertie文件接受參數{0}中的字符串數組
- 15. Grails日期被接受爲字符串
- 16. 字符串參數間接
- 17. 如何傳遞字符串數組作爲函數參數
- 18. 接受單字典或字典列表作爲函數參數
- 19. 如何把字符串作爲連接字符串到app.config?
- 20. 如何同時接受字符串或無參數以提升Python函數
- 21. 接受字符串值
- 22. 通過接受字符串
- 23. 如何使用字符串作爲關鍵字參數?
- 24. 內置字符串格式與字符串連接作爲日誌參數
- 25. 通字符串作爲參數
- 26. 傳遞字符串作爲參數
- 27. 以參數作爲字符串
- 28. 參數化查詢作爲字符串
- 29. SQL添加字符串作爲參數
- 30. 字符串作爲參數(C++)
多久了您的字符串的回答後?你用什麼合同? 我有MessageContract和字符串是64k字符長。 – Tuoski 2009-09-09 13:51:05