WCF 服务 413 无论我更改哪个配置项

WCF Service 413 no matter which config item I change

几天来我一直在努力解决这个问题,但无济于事。当我尝试使用 IIS Express 在 Visual Studio 中进行调试以及将我的生产网站部署到机器 运行 IIS 7.5.

时,都会发生这种情况。

我使用 HttpWebRequest 从 Visual Studio 单元测试中调用了该服务,在 Fiddler 4 中,同样的错误。所以我不认为这是 WCF 客户端配置,因为我没有使用它。

无论我在我的配置文件中做了什么更改,我总是得到这个异常:

"Exception thrown: 'System.ServiceModel.ProtocolException' in 
System.ServiceModel.dll

Additional information: The maximum message size quota for incoming messages 
(65536) has been exceeded. To increase the quota, use the 
MaxReceivedMessageSize property on the appropriate binding element."

我附加的以下 Web.config 是针对不在我服务器根目录下的应用程序。

我正在使用 Ajax 使用 json 端点进行呼叫。

我这辈子都弄不明白为什么我会得到 64K 的限制,尤其是考虑到我已经将所有项目添加到 webHttpBinding 中,如下所示。

我还更改了 httpRuntime 元素,添加了 maxRequestLength 项,更改了请求过滤、安全设置和一大堆其他没有影响的东西。

另请注意,我已打开跟踪。 .svclog 文件没有告诉我更多信息。

在此先感谢您的帮助。

 <?xml version="1.0"?>
 <configuration>
    <appSettings>
       <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
       <add key="FactoryType" value="Production"/>
       <add key="TravelRequestConnectionString" value="Data Source=ITLCS.benderson.com;Initial Catalog=TestTravelRequestSite;User Id=XXXX;Password=XXXXX"/>
    </appSettings>
    <system.web>
       <compilation debug="true" targetFramework="4.6.1" />
       <httpRuntime targetFramework="4.6.1"/>
       <membership defaultProvider="ADMembershipProvider">
          <providers>
             <clear />
             <add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName" />
          </providers>
       </membership>
    </system.web>
    <system.serviceModel>
       <services>
          <service name="TravelRequestWebService.TravelRequestService">
             <endpoint
                 address="web"
                 binding="basicHttpBinding"
                 contract="TravelRequestWebService.ITravelRequestService" />
             <endpoint
                 address="json"
                 binding="webHttpBinding"
                 behaviorConfiguration="jsonBehavior"
                 contract="TravelRequestWebService.ITravelRequestService" />
             <endpoint
                 address=""
                 binding="basicHttpBinding"
                 contract="TravelRequestWebService.ITravelRequestService" />
          </service>
       </services>
       <behaviors>
          <serviceBehaviors>
             <behavior name="defaultBehavior">
                <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
                <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="true"/>
             </behavior>
             <behavior name="bigBehavior">
                <dataContractSerializer maxItemsInObjectGraph="200"/>
             </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
             <behavior name="WebBehavior">
                <webHttp/>
             </behavior>
             <behavior name="jsonBehavior">
                <enableWebScript/>
             </behavior>
          </endpointBehaviors>
       </behaviors>
       <bindings>
          <webHttpBinding>
             <binding name="webHttpBinding" allowCookies="true"
                      maxReceivedMessageSize="20000000"
                      maxBufferSize="20000000">
             </binding>
          </webHttpBinding>
          <basicHttpBinding>
             <binding name="basicHttpBinding" allowCookies="true"
                      maxReceivedMessageSize="20000000"
                      maxBufferSize="20000000">
             </binding>
          </basicHttpBinding>
       </bindings>
       <protocolMapping>
          <add binding="basicHttpsBinding" scheme="https" />
       </protocolMapping>
       <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
       <modules runAllManagedModulesForAllRequests="true"/>
       <!--
         To browse web app root directory during debugging, set the value below to true.
         Set to false before deployment to avoid disclosing web app folder information.
       -->
       <directoryBrowse enabled="true"/>
    </system.webServer>
    <system.diagnostics>
       <sources>
          <source name="System.ServiceModel"
                  switchValue="Information, ActivityTracing"
                  propagateActivity="true">
             <listeners>
                <add name="xml" />
             </listeners>
          </source>
          <source name="CardSpace">
             <listeners>
                <add name="xml" />
             </listeners>
          </source>
          <source name="System.IO.Log">
             <listeners>
                <add name="xml" />
             </listeners>
          </source>
          <source name="System.Runtime.Serialization">
             <listeners>
                <add name="xml" />
             </listeners>
          </source>
          <source name="System.IdentityModel">
             <listeners>
                <add name="xml" />
             </listeners>
          </source>
       </sources>
       <sharedListeners>
          <add name="xml"
               type="System.Diagnostics.XmlWriterTraceListener"
               initializeData="c:\log\Traces.svclog" />
       </sharedListeners>
    </system.diagnostics>
 </configuration>

尝试将您的配置更改为:

  <service name="TravelRequestWebService.TravelRequestService">
     <endpoint
         address="web"
         binding="basicHttpBinding"
         bindingConfiguration="basicHttpBinding"
         contract="TravelRequestWebService.ITravelRequestService" />
     <endpoint
         address="json"
         binding="webHttpBinding"
         behaviorConfiguration="jsonBehavior"
         bindingConfiguration="webHttpBinding"
         contract="TravelRequestWebService.ITravelRequestService" />
     <endpoint
         address=""
         binding="basicHttpBinding"
         contract="TravelRequestWebService.ITravelRequestService" />
  </service>

线索是错误消息中消息大小的 64K 默认限制。这暗示您的绑定配置未被 WCF 使用。配置与端点绑定的名称相同这一事实增加了混乱。