我正在尝试通过以下代码在c++客户端中使用gSoap来访问salesforce.com应用程序接口:
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>如果任何人对我的错误之处有任何见解,将不胜感激。
我正在使用Debian6.0上的gSoap 2.7,使用g++ 4.4.5编译,如果这有任何帮助的话。
发布于 2014-03-03 18:31:12
这是一个非常古老的问题,但我最近也遇到了同样的问题。对我来说,问题是我把c++代码和c代码混在一起了。我编译了stdsoap2.c而不是stdsoap2.cpp,由于某种原因,这阻止了对content-length进行正确的计数。一旦我创建了正确的对象并重新链接到它,解决方案就完美地工作了
发布于 2011-04-29 15:47:23
从您提供的数据包捕获中,还有另一个关键点需要观察。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操作参数?
https://stackoverflow.com/questions/5826953
复制相似问题