[英]WCF RestFull “413 Request Entity Too Large”
嗨我在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請求實體太大”
[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);
}
}
這是我的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>
編輯:我在這里找到解決方案:
maxReceivedMessageSize沒有修復413:請求實體太大
該帖子的第一個回復。
添加bindingConfiguration屬性。
<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:
<system.servicemodel>
<bindings>
<webHttpBinding>
<binding maxbufferpoolsize="2147483647"
maxreceivedmessagesize="2147483647"
maxbuffersize="2147483647">
</binding>
</webHttpBinding>
</bindings>
</system.servicemodel>
您需要設置maxbufferpoolsize
, maxreceivedmessagesize
和maxbuffersize
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.