1

我正在尝试在 c++ 客户端中使用 gSoap 来使用以下代码访问 salesforce.com API:

struct soap soap;

soap_init(&soap);

_ns1__login loginReq;
_ns1__loginResponse loginRes;

loginReq.username = "XXXX";
loginReq.password = "XXXX";

if(soap_call___ns1__login(&soap,NULL,NULL,&loginReq,&loginRes) == 0){
    qDebug() << loginRes.result->sessionId;
} else {
    soap_print_fault(&soap, stderr);
    soap_print_fault_location(&soap, stderr);
}

这没有问题,但是运行时会产生以下错误:

SOAP 1.1 fault: SOAP-ENV:Client [no subcode]
"Validation constraint violation: tag name or namespace mismatch in element <soapenv:Envelope>"
Detail: [no detail]
HTTP/1.1 500 Internal Server Error
Server: 
Content-Type: text/xml; charset=UTF-8
Content-Length: 625
Date: Fri, 29 Apr 2011 00:56:17 GMT
Connection: close

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode>UNKNOWN_EXCEPTION</faultcode><faultstring>UNKNOWN_EXCEPTION: Premature end of file.</faultstring><detail><sf:UnexpectedErrorFault xsi:type="sf:UnexpectedErrorFault"><sf:exceptionCode>UNKNOWN_EXCEPTION</sf:exceptionCode><sf:exceptionMessage>Premature end of file.</sf:exceptionMessage></sf:UnexpectedErrorFault></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
<!-- ** HERE ** -->

我已经运行了一个数据包捕获,除了 HTTP 标头中的“Content-Length”显示为 0 之外,一切看起来都是正确的:

POST /services/Soap/c/21.0 HTTP/1.1
Host: login.salesforce.com
User-Agent: gSOAP/2.7
Content-Type: text/xml; charset=utf-8
Content-Length: 0
Connection: close
SOAPAction: ""

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="urn:sobject.enterprise.soap.sforce.com" xmlns:ns3="urn:fault.enterprise.soap.sforce.com" xmlns:ns1="urn:enterprise.soap.sforce.com"><SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><ns1:login><ns1:username>XXXX</ns1:username><ns1:password>XXXX</ns1:password></ns1:login></SOAP-ENV:Body></SOAP-ENV:Envelope>

如果有人对我哪里出错有任何见解,将不胜感激。

我在 Debian 6.0 上使用 gSoap 2.7 使用 g++ 4.4.5 进行编译,如果有帮助的话。

4

2 回答 2

2

这是一个非常古老的问题,但我最近遇到了同样的问题。对我来说,问题是我混合了 c++ 代码和 c 代码。我编译了 stdsoap2.c 而不是 stdsoap2.cpp 并且由于某种原因这阻止了对内容长度的正确计数。一旦我创建了正确的对象并重新链接到它,该解决方案就可以完美运行

于 2014-03-03T10:31:12.127 回答
1

从您提供的数据包捕获中,还有一个关键点需要观察。SOAPAction 字段为空。

这是我的应用程序的示例数据包捕获:

POST /ws/smi/v1/IndexService HTTP/1.1
Host: somevalidwebservice.com
User-Agent: gSOAP/2.8
Content-Type: text/xml; charset=utf-8
Content-Length: 1180
Connection: close
SOAPAction: "http://www.somevalidwebservice.com/ws/smi/v1/getIndex"

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://www.somevalidwebservice.com/ws/smi/v1"
<SOAP-ENV:Header></SOAP-ENV:Header><SOAP-ENV:Body><nsGlobal:getIndexRequest></nsGlobal:getIndexRequest>

您能否检查是否正确指定了 SOAP Action 参数?

于 2011-04-29T07:47:23.160 回答