How do I setup config files for WCF Data Service (odata) with EF 6

限于喜欢 提交于 2019-12-06 07:24:11

问题


I have a data service up and running, but I'm getting this error:

The remote server returned an error: (413) Request Entity Too Large.

I have tried a number of things to fix this with no luck. I have set the uploadReadAheadSize on the Web Site and the Data Service in IIS to the max setting. I have also tried a number of different setups for the config files.

Here is the current app.config for the client:

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

I have tried both bindings, WCFWebBinding and WCFHttpBinding.

Here is the web service 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>

Again, I have tried both bindings. I don't know what else can be done. Any help would be great.


回答1:


I have found a solution to this problem. The web.config must have a service added that names the service and has a contract set to "System.Data.Services.IRequestHandler"

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

My system complained about both the name of the service and the contract (attribute is invalid warnings). The namespace of my service is PSIDataService and the class name is PSIWcfDataService, so I ignored the complaint. The contract name had the same warning. I knew the interface existed, so I ignored that warning, too.

A webHttpBinding is also required.

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

I got the idea for this fix from Malvin Ly (malvinly.com/2011/05/09/wcf-data-services-and-maxreceivedmessagesize) So thanks Malvin! I don't like the warnings, but this solved my problem.



来源:https://stackoverflow.com/questions/23664086/how-do-i-setup-config-files-for-wcf-data-service-odata-with-ef-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!