WCF RestFull“413 请求实体太大" [英] WCF RestFull "413 Request Entity Too Large"
问题描述
我使用 WCF RestFull 服务工作,使用 JsonNet 序列化我的对象我有这个方法:User 对象有一个像这样的属性类型 byte[]
Hi I working whit a WCF RestFull services, using JsonNet to serialize my objects I have this have this method: The User object have a property type byte[] like this
public class User
{
public int Id {get;set;}
public string UserName {get;set}
public byte[] Photo {get;set;}
}
但是我发了一张照片大小超过 41 Kb 的 POST 得到了 HttpStatusCode413 请求实体太大"
but wen I make a POST whit a Photo's size more than 41 Kb a got the HttpStatusCode "413 Request Entity Too Large"
[WebInvoke(Method = "PUT",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "/user/{id}/")]
public Stream EditUser(string id, Stream input)
{
try
{
string json = input.ConvertToString();
User usr = json.FromJSON<User>();
usr.Update();
return null;
}
catch (Exception ex)
{
SetInternalServerErrorResponse();
return GetResponseError(ex);
}
}
这是我的网络配置
<bindings>
<basicHttpBinding>
<binding name="" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647">
<readerQuotas maxDepth="35" maxStringContentLength="65536000" maxArrayLength="65536000" maxBytesPerRead="65536000" />
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="svcBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647">
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
</security>
</binding>
</webHttpBinding>
</bindings>
我在这里找到解决方案:
I find the solution here:
maxReceivedMessageSize 未修复 413:请求实体太大
帖子的第一个回复.
添加 bindingConfiguration 属性.
Adding the bindingConfiguration proprety.
<service behaviorConfiguration="serviceBehavior" name="Aloes.Services.Service">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="svcBinding"
contract="Aloes.Services.IService" />
</service>
推荐答案
要克服此错误,您需要在配置文件(app.config 或 web.config)中配置 WebHttpBinding:
To overcome this error you need to configure WebHttpBinding in your config file (app.config or web.config):
<system.servicemodel>
<bindings>
<webHttpBinding>
<binding maxbufferpoolsize="2147483647"
maxreceivedmessagesize="2147483647"
maxbuffersize="2147483647">
</binding>
</webHttpBinding>
</bindings>
</system.servicemodel>
您需要设置maxbufferpoolsize
、maxreceivedmessagesize
和maxbuffersize
.
这篇关于WCF RestFull“413 请求实体太大"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!