0

我想发送到我的 WCF WebRole 的大量数据存在问题。我得到 (413) 太大的数据错误。我在 Azure 和 WCF 中很新。我创建了一个用于将图像发送到 WCF (LargeObject.svc) 的新服务,并尝试为其配置绑定和端点。

这是服务器端代码:

 <system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IImage" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
      <readerQuotas maxDepth="32"
               maxArrayLength="200000000"
               maxStringContentLength="200000000"/>
    </binding>
    <binding name="BasicHttpBinding_IRouteService"/>
  </basicHttpBinding>
  <customBinding>
    <binding name="CustomBinding_IRouteService">
      <binaryMessageEncoding />
      <httpTransport />
    </binding>
  </customBinding>
</bindings>
<client>
  <endpoint address="http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IRouteService"
    contract="Route.IRouteService" name="BasicHttpBinding_IRouteService" />
  <endpoint address="http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc/binaryHttp"
    binding="customBinding" bindingConfiguration="CustomBinding_IRouteService"
    contract="Route.IRouteService" name="CustomBinding_IRouteService" />
  <endpoint address="http://127.0.0.1:81/Implementation/LargeObject.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IImage"
            contract="ILargeObject" name="BasicHttpBinding_IImageSvc"/>
</client>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
      <dataContractSerializer maxItemsInObjectGraph="1048576" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

我在 Windows Phone 中还有一个客户端应用程序,代码:

string endPointAddress = (Application.Current as TravelerMobile.App).ServerUriString("LargeObject.svc");

        LargeObjectClient client = new LargeObjectClient(new BasicHttpBinding(),
            new EndpointAddress(endPointAddress));


        MemoryStream stream = new MemoryStream();
        WriteableBitmap wb = new WriteableBitmap(image);
        wb.SaveJpeg(stream, image.PixelWidth, image.PixelHeight, 0, 100);
        byte[] byteImage = stream.ToArray();

        client.AddImageAsync(new LargeObject.AddImageRequest
        {
            Image = byteImage,
            Latitude = latitude,
            Longitude = longitude,
            UserId = Helpers.GetUserId()
        });

我还尝试通过设置 maxRevieved 和 maxBuffered 属性在客户端配置 BasicHttpBinding,但它仍然不起作用。

有任何想法吗?

ps 这是一个 Windows Azure WCF 项目,所以我有一个默认端点 - 但我不知道如何设置它 maxReceivedMessageSize 。

4

1 回答 1

0

我在 stackoverflow 上找到了以下链接,他们遇到了同样的问题,希望它也对你有用,Azure WCF Webrole 错误:远程服务器返回了意外响应:(413)请求实体太大

当您在 MaxReceivedMessageSize 中设置了要传输的最大字节数时,我认为您应该在 ReaderQuotas 标记中执行此操作。

另一件事,您必须考虑,我不知道您使用的是什么类型的存储,但有些存储不允许您上传超过 4MB 的文件。例如,对于每个块块,块的最大大小为 4 MB,页块的最大大小为 4 MB。

您也可以在 msdn 上查看此链接,他们遇到了同样的问题:http ://social.msdn.microsoft.com/Forums/en-US/windowsazuredata/thread/39bfad06-97c0-4a98-b9fb-87879bab9414

于 2013-02-19T20:57:29.827 回答