如何使用EF 6为WCF数据服务(odata)设置配置文件

时间:2014-05-14 20:04:21

标签: wcf odata wcf-data-services

我已启动并运行数据服务,但我收到此错误:

  

远程服务器返回错误:(413)请求实体太大。

我已经尝试过许多方法来解决这个问题而没有运气。 我已将网站上的uploadReadAheadSize和IIS中的数据服务设置为最大设置。 我还为配置文件尝试了许多不同的设置。

以下是客户端的当前app.config:

  <system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_ILogging" />
    <binding name="WCFHttpBinding"
             maxReceivedMessageSize="2147483647"
             maxBufferSize="2147483647"
             maxBufferPoolSize="2147483647">
      <readerQuotas maxArrayLength="2147483647"
                    maxDepth="2147483647"
                    maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647"
                    maxStringContentLength="2147483647"/>
    </binding>
  </basicHttpBinding>
  <webHttpBinding>
    <binding name="WCFWebBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
    </binding>
  </webHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost/PSIDataService/PSIWcfDataService.svc"
            binding="webHttpBinding" bindingConfiguration="WCFWebBinding"
            name="WCFWebBinding" contract="*"/>
</client>

我已尝试过两种绑定,WCFWebBinding和WCFHttpBinding。

这是web服务web.config。

  <system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <basicHttpBinding>
    <binding name="WCFHttpBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpBinding>
  <webHttpBinding>
    <binding name="WCFWebBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
    </binding>
  </webHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost/PSIDataService/PSIWcfDataService.svc"
      binding="basicHttpBinding"
      bindingConfiguration="WCFHttpBinding"
      name="WCFHttpBinding"
      contract="*"/>

</client>

同样,我尝试了两种绑定。我不知道还能做些什么。任何帮助都会很棒。

1 个答案:

答案 0 :(得分:5)

我找到了解决这个问题的方法。 web.config必须添加一个服务,该服务命名服务并且合同设置为&#34; System.Data.Services.IRequestHandler&#34;

<system.serviceModel>
<services>
  <service name="PSIDataService.PSIWcfDataService">
    <endpoint bindingConfiguration="msgSize" 
              address="" 
              binding="webHttpBinding" 
              contract="System.Data.Services.IRequestHandler"/>
  </service>
</services>

我的系统抱怨服务名称和合同(属性是无效警告)。我的服务的命名空间是PSIDataService,类名是PSIWcfDataService,所以我忽略了投诉。合同名称具有相同的警告。我知道界面存在,所以我也忽略了这个警告。

还需要webHttpBinding。

  <bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_ILogging" />
  </basicHttpBinding>
  <webHttpBinding>
    <binding name="msgSize" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/>
  </webHttpBinding>
</bindings>

我从Malvin Ly那里得到了这个修复的想法(malvinly.com/2011/05/09/wcf-data-services-and-maxreceivedmessagesize)所以感谢Malvin!我不喜欢警告,但这解决了我的问题。

相关问题