【问题标题】:WCF REST on Azure fails with "413 Request Entity Too Large"Azure 上的 WCF REST 因“413 请求实体太大”而失败
【发布时间】:2013-08-04 02:40:18
【问题描述】:

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

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

界面

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>

【问题讨论】:

  • 你解决了吗? Azure 也有类似的问题,完全忽略了我的配置,并且我也从 Azure WCF 服务收到 413 错误。
  • 是的。问题是 Visual Studio 没有在部署过程中上传配置文件。在您的实例上启用 rdp,远程登录并手动复制配置文件,以查看您的问题是否与我的问题根源一样。

标签: wcf azure wcf-binding azure-web-roles


【解决方案1】:

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

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

猜你喜欢
  • 1970-01-01
  • 2016-09-08
  • 2020-02-05
  • 2016-01-20
  • 2011-02-22
  • 1970-01-01
  • 2016-11-14
  • 1970-01-01
  • 2015-05-03
相关资源
最近更新 更多