wcf - WCF 4 REST 服务的正确配置是什么?

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

很抱歉发布此事,但这让我抓狂。我在 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>

最佳答案

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

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

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

关于wcf - WCF 4 REST 服务的正确配置是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6629140/

相关文章:

c# - 在 .Net Core Web API 中使用 web.config 文件

c# - 在没有 Web.Config 的情况下配置表单例份验证

asp.net-mvc - 在没有 Visual Studio 的情况下获取 SQL Server 的连接字符串

ravendb - 当 NServiceBus 尝试安排超时时,Raven 返回 400 "Request Too Long"错误

node.js - 如何在 Sequelize 的地方使用动态过滤器?

c# - 带有 HTTPStatusCodeResult 的自定义错误消息在本地主机上不起作用

.net - 此消息无法支持操作,因为它已被复制

.net - 在不同级别更改了InotifyPropertyChange的简单MVVM

c# - WCF路由服务-动态错误处理

.net-3.5 - 客户端连接到 WCF 托管端点时触发事件