【问题标题】:What is the proper configuration for a WCF 4 REST service?WCF 4 REST 服务的正确配置是什么?
【发布时间】:2011-07-08 18:58:15
【问题描述】:

很抱歉发布此信息,但这让我发疯了。我在 VS2010 的 WCF4 REST 模板中使用路由。我将 maxreceivedmessagesize 属性设置为某个庞大的数字,当我尝试将 xml 提交给服务时,它仍然给我一个 HTTP 状态代码 400。我打开了跟踪,消息告诉我它仍设置为默认消息大小。这让我觉得问题在于我的 web.config 设置方式有些细微差别。有人可以快速了解一下,让我知道他们的想法吗?

我一直都在这方面,多一双眼睛对我会有很大的好处。提前致谢!

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>
  </system.webServer>

  <system.serviceModel>

    <bindings>
      <webHttpBinding>
        <binding name="" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed"  openTimeout="00:25:00" closeTimeout="00:25:00" sendTimeout="00:25:00" receiveTimeout="00:25:00" maxBufferSize="2147483647">
          <readerQuotas maxDepth="64"
                 maxStringContentLength="2147483647"
                 maxArrayLength="2147483647"
                 maxBytesPerRead="2147483647"
                 maxNameTableCharCount="2147483647"/>
        </binding>
      </webHttpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <dataContractSerializer maxItemsInObjectGraph="9000000"/>

          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>


    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <standardEndpoints>
      <webHttpEndpoint>
        <!-- 
            Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
            via the attributes on the <standardEndpoint> element below
        -->
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="2147483647" transferMode="Streamed" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"/>
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>

  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="traceListener"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData= "c:\logs\Traces.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>

</configuration>

【问题讨论】:

    标签: wcf web-config http-status-code-400 maxreceivedmessagesize


    【解决方案1】:

    您的 OperationContract 属性是什么样的? 您是否设置了 WebMessageFormat.Xml 的 RequestFormat 和 ResponseFormat? 另外,你的 BodyStyle 应该是 WebMessageBodyStyle.WrappedRequest

    由于没有条目,我假设您在 IIS 下运行它。 如果是这样,请确保您有正确配置的 .svc 文件。

    另外,您可以检查 global.asax 以确保 url 确实指向 wcf 服务。我只是在猜测,但我确定它不是消息大小属性的一件事

    【讨论】:

      【解决方案2】:

      好的,我想通了;问题实际上出在客户端上。它没有序列化我试图在 http 帖子中提交的对象。当我根据测试服务器上的服务检查它时,我更正了帖子的 xml,现在它可以正常工作了。谢谢!

      【讨论】:

      • 我也面临同样的问题。我还没有找到解决方案。能否请您更具体一点。当您说“它没有序列化我试图在 http 帖子中提交的对象”时。你到底做了什么来修复它?
      猜你喜欢
      • 1970-01-01
      • 2016-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-23
      • 1970-01-01
      相关资源
      最近更新 更多