gSoap:HTTP标头,内容长度:0

时间:2011-04-29 01:34:12

标签: c++ soap salesforce gsoap

我正在尝试使用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进行编译,如果有任何帮助的话。

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分: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参数吗?