【发布时间】:2014-06-04 21:37:21
【问题描述】:
您好,我使用 WCF RestFull 服务,使用 JsonNet 序列化我的对象 我有这个有这个方法: User 对象有一个像这样的属性类型 byte[]
public class User
{
public int Id {get;set;}
public string UserName {get;set}
public byte[] Photo {get;set;}
}
但是当我发布的照片大小超过 41 Kb 时,得到了 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>
编辑:我在这里找到解决方案:
maxReceivedMessageSize not fixing 413: Request Entity Too Large
帖子的第一个回复。
添加 bindingConfiguration 属性。
<service behaviorConfiguration="serviceBehavior" name="Aloes.Services.Service">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="svcBinding"
contract="Aloes.Services.IService" />
</service>
【问题讨论】: