【发布时间】:2014-06-05 21:17:10
【问题描述】:
我有用于 wcf 服务的 webHttpBinding。无法将大型 xml 文件 (1MB) 发布到服务,出现以下错误 RequestEntityTooLarge (413) 不是以下之一:OK (200)、Created (201)、Accepted (202)、NonAuthoritativeInformation (203)、NoContent (204)、重置内容 (205)、部分内容 (206)"} System.Exception {System.ArgumentOutOfRangeException}
这是 wcf 服务的配置..
<service name="abc" >
<endpoint address="http://localhost:8741/LTLInboundService/" binding="webHttpBinding" behaviorConfiguration="WebHttpBehaviour" contract="abc" name="webHttpBinding_LTLInboundService" >
</endpoint>
</service>
<webHttpBinding>
<binding name="webHttpBinding_LTLInboundService" closeTimeout="00:10:00"
openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
transferMode="Streamed"
useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</webHttpBinding>
这是失败的代码..
using (HttpClient client = new HttpClient("http://localhost:8741/LTLInboundService" + "/SendCompletionReports"))
{
// Initalise a response object
HttpResponseMessage response = null;
string responseFilePath = Path.Combine(@"c:\Samir\abc.xml");
string xmlData = System.IO.File.ReadAllText(responseFilePath);
// Create a content object for the request
HttpContent content = HttpContent.Create(xmlData, Encoding.UTF8, "text/xml");
// Make the request and retrieve the response
response = client.Post("http://localhost:8741/LTLInboundService" + "/SendCompletionReports", content);
// Throw an exception if the response is not a 200 level response
response.EnsureStatusIsSuccessful();
// Retrieve the content of the response for processing
response.Content.LoadIntoBuffer();
}
response.EnsureStatusIsSuccessful(); 语句失败。
知道如何在开发和生产中解决这个问题吗?
【问题讨论】:
标签: c# xml wcf visual-studio