gpt4 book ai didi

Azure 上的 WCF REST 失败并显示 "413 Request Entity Too Large"

转载 作者:行者123 更新时间:2023-12-03 04:37:31 25 4
gpt4 key购买 nike

我已在 Azure 上部署了 RESTful WCF 服务。其中一项合约操作应该获取从客户端上传的图像文件(不大于 500kb)。目前,我的解决方案在 Azure 计算机/存储模拟器中运行没有任何问题。但是,当我将解决方案部署到 Azure 时,从客户端上传(图像大小为 133kb)失败,并显示 413 请求实体太大。 Azure 似乎忽略了我在 web.config 中设置的配置(在 Azure 模拟器中正确选择了该配置)。

任何有关如何解决此问题的帮助将不胜感激。以下是我的代码的相关片段。

界面

namespace HappyBabiesSvc
{
[ServiceContract]
public interface IHappyBabies

[OperationContract]
[WebInvoke(UriTemplate = "/v1.0/locations/{locationID}/images",
Method = "PUT")]
void UploadNewImage(string locationID, Stream imageToUpload);

服务实现

<%@ ServiceHost Language="C#" Debug="true" Service="HappyBabiesSvc.HappyBabiesSvc" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>

Web.config

<system.serviceModel>    
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint maxReceivedMessageSize="655360"/>
</webHttpEndpoint>
</standardEndpoints>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false"/>
<services>
<service name="HappyBabiesSvc.HappyBabiesSvc" behaviorConfiguration="ServiceConfiguration">
<endpoint address="" binding="webHttpBinding"
name="HappyBabiesService"
contract="HappyBabiesSvc.IHappyBabies" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding maxBufferSize="655360"
maxReceivedMessageSize="655360" transferMode="Streamed">
<readerQuotas maxDepth="655360" maxStringContentLength="655360"
maxArrayLength="655360" maxBytesPerRead="655360" maxNameTableCharCount="655360" />
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>

最佳答案

仅尝试具有单个参数的方法,即 Stream 。流参数应该是单独的。

[OperationContract] [WebInvoke(UriTemplate = "/v1.0/locations/{locationID}/images",Method = "PUT")] void UploadNewImage(Stream imageToUpload);

关于Azure 上的 WCF REST 失败并显示 "413 Request Entity Too Large",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18023453/

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