-->

What is the proper configuration for a WCF 4 REST

2019-02-25 07:49发布

问题:

Sorry to post about this, but it's driving me nuts. I am using routes in the WCF4 REST template in VS2010. I set the maxreceivedmessagesize property to some gargantuan number, and it still gives me an HTTP status code 400 when I try to submit xml to the service. I turned on tracing, and the message tells me that it's still set to the default message size. This makes me think that the problem is some nuance in how I have my web.config set up. Could somebody take a quick peak at it and let me know what they think?

I've been around and around with this, and an extra set of eyes would be of great benefit to me. Thanks in advance!

<?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>

回答1:

What does your OperationContract attribute look like? Have you set the RequestFormat and ResponseFormat the WebMessageFormat.Xml? Also, you BodyStyle should be WebMessageBodyStyle.WrappedRequest

Since there is no entry, I'm assuming you are running it under IIS. if thats the case, make sure you have a properly configured .svc file.

Also, you might check your global.asax to make sure the url actually points to the wcf service. I'm just guessing but the one thing I'm sure its not is the message size property



回答2:

OK, I figured it out; the problem was actually on the client. It wasn't serializing the object that I was trying to submit in the http post. When I checked it against a service on the test server, I corrected the xml for the post and now it's working properly. Thanks!