简体   繁体   中英

How to configure the message size for a WCF web role (Currently getting HTTP error code 500)

Thank you all!

We were able to solve this problem simply by changing the binding element name from "basicHttpBinding" to "webHttpBinding".

Silly, I know..


Hello,

I am trying to implement a web role using WCF, that will receive JSON objects and store them in the Azure storage. During the integration tests I got a 400 error code. I then discovered that WCF has a very small message size (~65535), and that I need to configure it to be larger. The configuration I am currently using causes a 500 error code whenever I try to post an HTTP request to my service (the request never reaches my code).

The Web.config file I am using looks like this:

<?xml version="1.0" encoding="UTF-8"?>

  <system.web>

    <compilation debug="true" targetFramework="4.0" />

  </system.web>

  <system.serviceModel> 

    <diagnostics>

      <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxSizeOfMessageToLog="5000000" />

      <endToEndTracing activityTracing="false" />

    </diagnostics>

    <services>

      <service name="MyWebRole.RequestHandler" behaviorConfiguration="RequestHandlerbehavior">

        <endpoint address="http://localhost:9001/" binding="basicHttpBinding" bindingConfiguration="conf" name="MyDefaultEndpoint"

                                contract="MyWebRole.IRequestHandler" />

      </service>

    </services>   

    <bindings>

      <basicHttpBinding>

        <binding name="conf" maxBufferSize="5000000" maxReceivedMessageSize="5000000" useDefaultWebProxy="true">

          <readerQuotas maxDepth="5000000" maxStringContentLength="5000000" maxArrayLength="5000000" maxBytesPerRead="5000000" maxNameTableCharCount="5000000" />

        </binding>

      </basicHttpBinding>

    </bindings>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

    <behaviors>

      <serviceBehaviors>

        <behavior name="RequestHandlerbehavior">

          <serviceMetadata httpGetEnabled="true" />

          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

      </serviceBehaviors>

    </behaviors>

  </system.serviceModel>

  <system.webServer>

    <modules runAllManagedModulesForAllRequests="true" />

  </system.webServer>

</configuration>

Can you please help me get my requests through to my WCF service?

Thanks!

Have you tried increasing the message receive size on your binding? Such as...

maxReceivedMessageSize="1048576"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM