rest – 无法通过web.config设置maxReceivedMessageSize

前端之家收集整理的这篇文章主要介绍了rest – 无法通过web.config设置maxReceivedMessageSize前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我现在已经调查了过去两小时的400-BadRequest代码.
很多sugestions用于确保正确设置bindingConfiguration属性,在我的情况下,确实如此.

现在,在摧毁我所在的建筑物之前,我需要你的帮助:-)

我运行WCF RestFull服务(非常轻量级,使用此资源获取灵感:http://msdn.microsoft.com/en-us/magazine/dd315413.aspx),它(现在)接受通过POST动词提供的XmlElement(POX).

在实现真正的客户端之前,我目前只使用Fiddler的请求构建器(因为这是混合环境).

当我为小于65K的XML执行此操作时,它工作正常 – 更大,它会抛出此异常:
已超出传入邮件的最大邮件大小限额(65536).要增加配额,请在相应的绑定元素上使用MaxReceivedMessageSize属性.

这是我的web.config文件(我甚至包括了客户端标签(绝望的时候!)):

<system.web>
    <httpRuntime maxRequestLength="1500000" executionTimeout="180"/>
  </system.web>
  <system.serviceModel>
    <diagnostics>
      <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
    </diagnostics>
    <bindings>
      <webHttpBinding>
        <binding name="WebHttpBinding" maxReceivedMessageSize="1500000" maxBufferPoolSize="1500000" maxBufferSize="1500000" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00">
          <readerQuotas maxStringContentLength="1500000" maxArrayLength="1500000" maxBytesPerRead="1500000" />
          <security mode="None"/>
        </binding>
      </webHttpBinding>
    </bindings>
    <client>
      <endpoint address="" binding="webHttpBinding" bindingConfiguration="WebHttpBinding" contract="Commerce.ICatalogue"/>
    </client>
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="Catalogue">
        <endpoint address="" 
                  behaviorConfiguration="RestFull" 
                  binding="webHttpBinding"
                  bindingConfiguration="WebHttpBinding" 
                  contract="Commerce.ICatalogue" />
        <!-- endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" / -->
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="RestFull">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/>
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

提前感谢任何有助于使用> 65K XML进行成功通话的帮助;-)

解决方法

好吧,这个真的让我很难解决,我会让别人干掉.
事实上,我使用了<%@ ServiceHost Factory =“System.ServiceModel.Activation.WebServiceHostFactory”Service =“fullQualifiedClassName”%>这是一个很好且简单的工厂实现方法.

然而,这种方法有它的缺点;由于web.config文件中不需要任何配置,因此WebServiceHostFactory类不会从web.config文件中读取.
我知道;我可以从这个类继承,并进行适当的更改,因此它可能确实从配置文件中读取,但这似乎有点超出范围.

我的解决方案是回到更传统的实施WCF的方式; <%@ ServiceHost Service =“fullQualifiedClassName”CodeBehind =“〜/ App_Code / Catalogue.cs”%>,然后在web.config文件中使用我已经配置的值.

这是我修改过的web.config文件(关于Maddox头痛):

<system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="XmlMessageBinding" maxReceivedMessageSize="5000000" maxBufferPoolSize="5000000" maxBufferSize="5000000" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00">
          <readerQuotas maxStringContentLength="5000000" maxArrayLength="5000000" maxBytesPerRead="5000000" />
          <security mode="None"/>
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service name="fullyQualifiedClassName" behaviorConfiguration="DevelopmentBehavior">
        <endpoint name="REST" address="" binding="webHttpBinding" contract="fullyQualifiedInterfaceName" behaviorConfiguration="RestEndpointBehavior" bindingConfiguration="XmlMessageBinding" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="RestEndpointBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="DevelopmentBehavior">
          <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/>
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
        <behavior name="ProductionBehavior">
          <serviceDebug httpHelpPageEnabled="false" includeExceptionDetailInFaults="false"/>
          <serviceMetadata httpGetEnabled="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

此更改的另一个好处是,您现在可以直接从.NET引用您的WCF-rest服务;在整个解决方案中,使用Factory模型和我的XmlElement实现无法做到这一点.

我希望这可以帮助其他类似问题…

猜你在找的HTML相关文章