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

时间:2015-06-11 07:19:48

标签: wcf

我发现了类似的帖子,但我尝试过的所有内容都无效。你能告诉我我做错了什么吗?首先是我的客户端配置和第二个我的服务器配置。 首先我认为这是因为我尝试接收大量数据,但在我的情况下这不是问题。

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

1 个答案:

答案 0 :(得分:0)

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

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

首先,您说您正在使用REST,因此WSDL文件不起作用(它适用于SOAP服务)。

其次,WSDL文件不是服务,它是 W eb S 服务 D escription L anguage文件,它描述了Web服务,因此客户端可以为其构建代理(同样,这是针对SOAP而不是REST)。

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

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