WCF oData通过Web服务插入

时间:2012-08-14 09:05:17

标签: json wcf odata maxreceivedmessagesize

我正在尝试为我的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;
    }
}

1 个答案:

答案 0 :(得分:1)

Contract是来自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>