远程服务器返回了意外响应:(400) Bad Request WCF REST
Posted
技术标签:
【中文标题】远程服务器返回了意外响应:(400) Bad Request WCF REST【英文标题】:The remote server returned an unexpected response: (400) Bad Request WCF REST 【发布时间】:2015-06-11 07:19:47 【问题描述】:我发现了类似的帖子,但我尝试过的所有方法都不起作用。你能告诉我我做错了什么吗?首先是我的客户端配置,其次是我的服务器配置。 一开始我以为是因为我尝试接收大量数据,但这不是我的问题。
<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】:跳出来的一件事是客户端配置中的<client>
配置,特别是地址属性。
address="http://localhost:56923/TestService.svc?wsdl"
首先,您说您使用的是 REST,因此 WSDL 文件在其中不起作用(它用于 SOAP 服务)。
其次,WSDL文件不是服务,是Web S服务D描述L anguage 文件,它描述了 Web 服务,以便客户端可以为其构建代理(同样,这是针对 SOAP,而不是 REST)。
尝试将客户端配置中的地址更改为服务文件:
address="http://localhost:56923/TestService.svc"
【讨论】:
我更改了地址,但它仍然没有t work, not I get another one. It tells me: The contract attribute is invalid according to its datatype 'clientcontracttype'. I added the endpoint for client also in service configuration, but I can
t 在客户端和服务器配置中使用相同的合同..以上是关于远程服务器返回了意外响应:(400) Bad Request WCF REST的主要内容,如果未能解决你的问题,请参考以下文章
远程服务器返回了意外响应:(400) Bad Request WCF REST
WCF LIST 传输大数据,远程服务器返回了意外响应 400