且构网

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

在 C# 中,将 Soap 请求头从 text/xml 更改为 soap/xml 以获取 asmx webservice

更新时间:2023-01-15 12:43:51

Content Type text/xml;服务不支持 charset=utf-8

这通常是客户端/服务器绑定中的不匹配,其中服务中的消息版本使用 SOAP 1.2(期望application/soap+xml) 并且客户端中的版本使用 SOAP 1.1(发送文本/xml).WSHttpBinding 使用 SOAP 1.2,BasicHttpBinding使用 SOAP 1.1.

它通常似乎是一侧的 wsHttpBinding 和另一个是 basicHttpBinding.

您可以将客户端的配置更改为使用 SOAP 1.2 的 WSHttpBinding,它会影响内容类型标头.

I need to call a webservice. I generated a proxy and invoked the method. But it keeps failing. Because the API is expecting soap/xml in the header whereas the proxy client generated in Visual studio is sending text/xml in header.

Question: Is it possible to change the value of the Content-Type header for a generated proxy client?

Content Type text/xml; charset=utf-8 was not supported by service

this is usually a mismatch in the client/server bindings, where the message version in the service uses SOAP 1.2 (which expects application/soap+xml) and the version in the client uses SOAP 1.1 (which sends text/xml). WSHttpBinding uses SOAP 1.2, BasicHttpBinding uses SOAP 1.1.

It usually seems to be a wsHttpBinding on one side and a basicHttpBinding on the other.

You can change the configuration on the client side to WSHttpBinding which uses SOAP 1.2 and it will affect the content type header.