远程服务器返回意外响应:(400) 错误请求 WCF REST



我找到了类似的帖子,但我尝试过的所有内容都不起作用。你能告诉我我做错了什么吗?首先是我的客户端配置,其次是我的服务器配置。首先,我认为这是因为我尝试接收大量数据,但这不是我的问题。

<appSettings>
  <add key="webpages:Version" value="3.0.0.0" />
  <add key="webpages:Enabled" value="false" />
  <add key="ClientValidationEnabled" value="true" />
  <add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
  <authentication mode="None" />
  <compilation debug="true" targetFramework="4.5" />
  <httpRuntime maxRequestLength="32768" targetFramework="4.5" />
</system.web>
<system.serviceModel>
  <client>
    <endpoint address="http://localhost:56923/TestService.svc?wsdl"
              behaviorConfiguration="webBehavior" 
              binding="webHttpBinding"
              bindingConfiguration="webHttpBinding"
              contract="TestService.TestService"
              name="WcfServiceApp.TestService" />
  </client>
  <bindings>
    <webHttpBinding>
      <binding name="webHttpBinding" 
               maxBufferSize="2097151"
               maxBufferPoolSize="2097151"
               maxReceivedMessageSize="2097151">
        <readerQuotas maxDepth="128" 
                      maxStringContentLength="2147483647"
                      maxArrayLength="16384" 
                      maxBytesPerRead="4096" 
                      maxNameTableCharCount="16384" />
      </binding>
    </webHttpBinding>
  </bindings>
  <behaviors>
    <endpointBehaviors>
      <behavior name="webBehavior">
        <webHttp />
        <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
      </behavior>
    </endpointBehaviors>
  </behaviors>
</system.serviceModel>
<system.webServer>
  <modules>
    <remove name="FormsAuthentication" />
  </modules>
</system.webServer>

<system.web>
  <compilation debug="true" targetFramework="4.5" />
  <httpRuntime maxRequestLength="32768" targetFramework="4.5"/>
</system.web>
<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
      <behavior name="webBehavior">
        <webHttp />
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <bindings>
    <webHttpBinding>
      <binding name="webHttpBinding" 
               maxBufferSize="2097151" 
               maxBufferPoolSize="2097151" 
               maxReceivedMessageSize="2097151">
        <readerQuotas maxDepth="128" 
                      maxStringContentLength="2097151"
                      maxArrayLength="16384" 
                      maxBytesPerRead="4096" 
                      maxNameTableCharCount="16384" />
      </binding>
    </webHttpBinding>
  </bindings>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
  <directoryBrowse enabled="true"/>
</system.webServer>

出的一件事是客户端配置中的<client>配置,特别是地址属性。

address="http://localhost:56923/TestService.svc?wsdl"

首先,你说你正在使用 REST,所以 WSDL 文件在其中没有发挥作用(它用于 SOAP 服务)。

其次,WSDL 文件不是服务,它是 Web Service Description Language 文件,它描述了 Web 服务,以便客户端可以为它构建代理(同样,这是针对 SOAP,而不是 REST)。

尝试将客户端配置中的地址更改为仅服务文件:

address="http://localhost:56923/TestService.svc"

最新更新