c++ - gSOAP 到 WCF。应用程序/soap+xml;字符集=utf-8

标签 c++ wcf gsoap

我在 http://calculator.gear.host/Service1.svc 上运行了简单的网络服务

WCF 测试客户端 调用时没有问题,从 gSOAP c++ 客户端调用时出错。

HTTP/1.1 415 Cannot process the message because the content type 'application/soap+xml; charset=utf-8; action="http://tempuri.org/IService1/GetData"' was not the expected type 'text/xml; charset=utf-8'.

Fiddler 上的数据包:

WCF 测试客户端

请求

 POST http://calculator.gear.host/Service1.svc HTTP/1.1
    Content-Type: text/xml; charset=utf-8
    SOAPAction: "http://tempuri.org/ICalculator/GetData"
    Host: calculator.gear.host
    Content-Length: 158
    Expect: 100-continue
    Accept-Encoding: gzip, deflate
    Connection: Keep-Alive

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><GetData xmlns="http://tempuri.org/"><value>77</value></GetData></s:Body></s:Envelope>

gSOAP

请求

POST http://calculator.gear.host/Service1.svc HTTP/1.1
Host: calculator.gear.host
User-Agent: gSOAP/2.8
Content-Type: application/soap+xml; charset=utf-8; action="http://tempuri.org/IService1/GetData"
Content-Length: 536
Connection: close
SOAPAction: "http://tempuri.org/IService1/GetData"

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns4="http://schemas.datacontract.org/2004/07/WcfService2" xmlns:ns3="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:ns1="http://tempuri.org/"><SOAP-ENV:Body><ns1:GetData><ns1:value>55</ns1:value></ns1:GetData></SOAP-ENV:Body></SOAP-ENV:Envelope>

回答

HTTP/1.1 415 Cannot process the message because the content type 'application/soap+xml; charset=utf-8; action="http://tempuri.org/IService1/GetData"' was not the expected type 'text/xml; charset=utf-8'.
Cache-Control: private
Content-Length: 0
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Set-Cookie: ARRAffinity=7ac8ab2e2023ddbeb7d4f86322b3ed25bc003394df0030ed244a6fc5c10ec47c;Path=/;Domain=calculator.gear.host
Set-Cookie: WAWebSiteSID=9095f7410a074a959c2084564368b742; Path=/; HttpOnly
Date: Tue, 28 Jul 2015 15:03:28 GMT
Connection: close

最佳答案

我对不是使用 gSOAP 生成的服务有同样的问题(可能使用 C# 中的某些工具)。 对于您的客户端 gSOAP,使用选项 -1(生成 SOAP 1.1 绑定(bind))重新编译您的 WSDL 文件 (soapcpp2.exe)。 这对我有用。

关于c++ - gSOAP 到 WCF。应用程序/soap+xml;字符集=utf-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31680457/

相关文章:

WCF WebInvoke 响应格式

c# - 如何更改 WCF 服务的默认显示

c++ - 使用 gsoap 的多个同时客户端

web-services - 如何在 Ubuntu 中部署 gSOAP Web 服务?

c++ - Win32 项目生成 MFC 错误

c++ - 使用模板基类中的常量

WCF REST 参数不能包含句点?

C++ 为谓词和值重载 std::count_if()

c++ - 将仅 header 库包含到多个文件中会产生链接器错误

c - 运行 gsoap 应用程序时出现段错误