gpt4 book ai didi

c# - WCF 休息满 "413 Request Entity Too Large"

转载 作者:行者123 更新时间:2023-12-02 21:26:14 30 4
gpt4 key购买 nike

您好,我使用 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 的 POST 时,得到了 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);
}
}

这是我的网络配置

<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

该帖子的第一个回复。

添加绑定(bind)配置属性。

  <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>

您需要设置maxbufferpoolsizemaxreceivedmessagesizemaxbuffersize

关于c# - WCF 休息满 "413 Request Entity Too Large",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24048023/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com