0

我正在尝试为我的 wcf odata 服务增加 maxReceivedMessageSize。我有另一个 Web 服务将值发布到我的 wcf 服务以将值插入 sql。我在发帖

{
A:1,
B:1,
C:3,
D:4,
}

这引发了一个错误。远程服务器返回错误:(400) 错误请求。如果我发布下面的值,它插入成功。

{
A:1
}

那么有人可以帮我解决这个错误吗?网上有一些例子试图修改下面的网络配置,但它们不适合我,因为我没有服务合同。

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <!-- Create a custom binding for our service to enable sending large amount of data -->
        <binding name="MyBasicHttpBinding"
        maxBufferPoolSize="2147483647"
        maxReceivedMessageSize="2147483647"
        maxBufferSize="2147483647">
        <readerQuotas
          maxArrayLength="2147483647"
          maxBytesPerRead="2147483647"
          maxDepth="2147483647"
          maxNameTableCharCount="2147483647"
          maxStringContentLength="2147483647" />

        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <!-- Enable the serializer to serialize greater number of records -->
        <behavior name="WCFServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <!-- Bind the WCF service to our custom binding -->
      <service behaviorConfiguration="WCFServiceBehavior"
      name="WcfDataService">
        <endpoint address="" binding="basicHttpBinding"
        bindingConfiguration="MyBasicHttpBinding"
        contract=" `WHICH I DONT HAVE, OR I HAVE IT BUT I AM NOOB` "/>
      </service>
    </services>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
     multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

我的 WCF 使用 ADO.net 实体模型

public class WcfDataService : DataService< DataModel.DataModelEntities >
{
    // This method is called only once to initialize service-wide policies.
    public static void InitializeService(DataServiceConfiguration config)
    {        
        // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
        // Examples:
        config.SetEntitySetAccessRule("*", EntitySetRights.All); 
       // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
    }
}
4

1 回答 1

1

合同是来自 Microsoft.Data.Services 的 System.Data.Services.IRequestHandler。

我的配置:

<system.serviceModel>
<services>
  <service name="ODataSampleRun.DemoDataService" behaviorConfiguration="Behavior">
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
    <endpoint contract="System.Data.Services.IRequestHandler" binding="customBinding" bindingConfiguration="RawODataService" address="http://localhost:9090/DemoDataService" behaviorConfiguration="test" />
  </service>
</services>
<bindings>
  <webHttpBinding>
    <binding name="NoneWebBinding">
      <security mode="None" />
    </binding>
  </webHttpBinding>
    <customBinding>
        <binding name="RawODataService">
            <webMessageEncoding webContentTypeMapperType="ODataSampleRun.RawContentTypeMapper, ODataSampleRun, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
            <httpTransport manualAddressing="true" maxReceivedMessageSize="524288000" transferMode="Streamed" />
        </binding>
    </customBinding>
</bindings>
<behaviors>
  <endpointBehaviors>
    <behavior name="test">
      <webHttp faultExceptionEnabled="true" />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="Behavior">
      <serviceMetadata httpGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>

于 2012-09-12T08:06:25.820 回答