[英]WCF RestFull “413 Request Entity Too Large”
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 嗨我在WCF RestFull服务工作,使用JsonNet来序列化我的对象我有这个方法:User对象有一个属性类型byte []喜欢这个
public class User
{
public int Id {get;set;}
public string UserName {get;set}
public byte[] Photo {get;set;}
}
but wen I make a POST whit a Photo's size more than 41 Kb a got the HttpStatusCode "413 Request Entity Too Large" 但是我发了一张照片,照片的大小超过41 Kb,得到了HttpStatusCode“413请求实体太大”
[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);
}
}
this is my webconfig 这是我的webconfig
<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>
EDIT: I find the solution here: 编辑:我在这里找到解决方案:
maxReceivedMessageSize not fixing 413: Request Entity Too Large maxReceivedMessageSize没有修复413:请求实体太大
The first response for the post. 该帖子的第一个回复。
Adding the bindingConfiguration proprety. 添加bindingConfiguration属性。
<service behaviorConfiguration="serviceBehavior" name="Aloes.Services.Service">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="svcBinding"
contract="Aloes.Services.IService" />
</service>
To overcome this error you need to configure WebHttpBinding in your config file (app.config or web.config): 要克服此错误,您需要在配置文件(app.config或web.config)中配置WebHttpBinding:
<system.servicemodel>
<bindings>
<webHttpBinding>
<binding maxbufferpoolsize="2147483647"
maxreceivedmessagesize="2147483647"
maxbuffersize="2147483647">
</binding>
</webHttpBinding>
</bindings>
</system.servicemodel>
You need to set the maxbufferpoolsize
, maxreceivedmessagesize
and maxbuffersize
. 您需要设置
maxbufferpoolsize
, maxreceivedmessagesize
和maxbuffersize
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.