且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

远程服务器返回了意外的响应:(400)错误的请求。 wcf

更新时间:2023-08-31 20:00:58

我们应该将 [WebGet] / [WebInvoke] 添加到自动接口生成的操作,以便保持服务器和客户端之间绑定的一致性。它位于自动生成的客户端代理类中。

我们通过添加服务引用来使用WCF服务,使用WebHttpBinding创建服务时会有所不同。这种类型的服务通常称为Restful风格的服务,我们可以通过在浏览器中输入服务地址直接调用它。

https://docs.microsoft.com/zh-cn/ dotnet / framework / wcf / feature-details / how-to-create-a-basic-wcf-web-http-service

因此,如果我们想通过使用客户端来使用该服务代理类,我们需要保持服务器和客户端之间绑定的一致性,就像WCF SOAP服务一样。

如果问题仍然存在,请随时与我联系。

We are supposed to add [WebGet]/[WebInvoke] to the auto-generated operation of the interface so that it maintains consistency of binding between server and client. It located in the auto-generated client proxy class.
We consume the WCF service by adding service reference, there is a difference when the service is created with WebHttpBinding. This type of service is typically called Restful style service, we could call it directly by inputting the service address in the browser.
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-create-a-basic-wcf-web-http-service
So if we want to consume the service by using a client proxy class, we need to maintain the consistency of binding between the server and client, just like the WCF SOAP service.
Feel free to contact me if the problem still exists.