Remote server returned an unexpected response. (41

2019-09-04 04:39发布

问题:

When I upload a photo from my WP7 to my WCF web service I get '413 Request Entity Too Large', and no matter what I do, I cannot stop it from happening.

My binding information for the web service is:

<bindings>
  <basicHttpBinding>
    <binding name="uploadfilebinding" closeTimeout="10:01:00"
      maxBufferSize="2147483646" maxBufferPoolSize="2147483646"
      maxReceivedMessageSize="2147483646" openTimeout="10:01:00"
      receiveTimeout="10:10:00" sendTimeout="10:01:00"
      messageEncoding="Mtom" transferMode="StreamedRequest">
      <readerQuotas maxDepth="2147483646" maxStringContentLength="2147483646"
                    maxArrayLength="2147483646" maxBytesPerRead="2147483646"
                    maxNameTableCharCount="2147483646" />
    </binding>
  </basicHttpBinding>
</bindings>

As you can see I have set maxReceivedMessageSize to the highest I can, but to no avail, Can anyone help me please?

My server is 'Windows Server 2008 R2 Standard' and the service is running under .NET 4.

Thanks in advance,

Lee

P.S. If you need anymore information, please ask and I'll post it.

Thanks for the replies:

As this is a WP7 app, the client configuration file is a hidden file called 'ServiceReferences.ClientConfig' that is created by the service, and the binding in there is now:

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IMbcSync" closeTimeout="10:01:00"
      maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" openTimeout="10:01:00"
      receiveTimeout="10:10:00" sendTimeout="10:01:00"
      transferMode="StreamedResponse">
    </binding>
  </basicHttpBinding>
</bindings>

But I'm still getting the same error. Any more suggestions would be much appreciated?

Lee

回答1:

There are multiple places that you may increase to the maximum possible size. Some of them are WCF related and some of them are IIS related. In addition to the options mentioned in the comments, try to increase the followings (maxRequestLength, and maxAllowedContentLength) in your config file on the server side to take care of the IIS side too:

<system.web>
  <httpRuntime maxRequestLength="2147483647" useFullyQualifiedRedirectUrl="true"   executionTimeout="14400"/>
</system.web>

  <system.webServer>
   <modules runAllManagedModulesForAllRequests="true"/>
    <security>
     <requestFiltering allowDoubleEscaping="true">
      <requestLimits maxAllowedContentLength="2147483647"/>
      <fileExtensions allowUnlisted="true"/>
      <verbs allowUnlisted="true"/>
     </requestFiltering>
    </security>
  </system.webServer>


标签: wcf c#-4.0 iis-7