python客户端通过suds调用C++服务器时出现,C++端已接收到响应的soap命令,在soap_begin_recv接口中的fparse调用处返回错误码soap error = 1000(即SOAP_STOP), 解析失败;用C++客户端调用webservice则能正常响应,求大神们指引!
python代码如下:
from suds.client import Client
url = 'http://127.0.0.1:8000/?wdsl'
client = Client(url)
print (client)
result = client.service.GetSum(1,2)
C++代码:
int http_get(struct soap *soap)
{
FILE*fd = NULL;
fd = fopen("KDNet.wsdl", "rb"); //open WSDL file to copy
if (!fd)
{
return 404; //return HTTP not found error
}
soap->http_content = "text/xml"; //HTTP header with text /xml content
soap_response(soap,SOAP_FILE);
for(;;)
{
size_t r = fread(soap->tmpbuf,1, sizeof(soap->tmpbuf), fd);
if (!r)
{
break;
}
if (soap_send_raw(soap, soap->tmpbuf, r))
{
break; //cannot send, but little we can do about that
}
}
fclose(fd);
soap_end_send(soap);
return SOAP_OK;
}
void main()
{
CBindingServer cBindingServer;
cBindingServer.accept_flags |= SO_LINGER;
cBindingServer.accept_timeout = 5;
cBindingServer.linger_time = 1;
cBindingServer.WeatherWSSoapService_init(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT);
cBindingServer.fget = http_get;
SOCKET hSoap = cBindingServer.bind(NULL, 8000, 100);
if (INVALID_SOCKET == hSoap)
{
cBindingServer.destroy();
return;
}
while(1)
{
SOCKET hSocket = cBindingServer.accept(); //python命令可以收到
if (INVALID_SOCKET == hSocket)
{
Sleep(10);
continue;
}
CBindingServer * pSoap = cBindingServer.copy();
int nRet = pSoap->serve(); //这个里面解析失败,直接进入SOAP_STOP
printf("server error %d\n", nRet);
}
cBindingServer.destroy();
soap_end(&cBindingServer);
soap_done(&cBindingServer);
return;
}
BindingServer 类中方法实现:
int BindingServer ::GetSum(_ns1__GetSumReq *ns1__GetSumReq, _ns1__GetSumRsp *ns1__GetSumRsp)
{
printf("!!!!!!!\n");
return 0;
}
wsdl文件内容:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../ver20/util/onvif-wsdl-viewer.xsl"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:trp="http://www.hh.com.cn/ver10/HFS/wsdl"
targetNamespace="http://www.hh.com.cn/ver10/HFS/wsdl">
<wsdl:types>
<xs:schema targetNamespace="http://www.hh.com.cn/ver10/HFS/wsdl"
xmlns:tt="http://www.hh.com.cn/ver10/schema/HFSStruct/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" version="1.0">
<xs:import namespace="http://www.hh.com.cn/ver10/schema/HFSStruct/" schemaLocation="HFSStruct.xsd" />
<!-- Message Request/Responses elements -->
<!-- GetSumReq -->
<xs:element name="GetSumReq">
<xs:complexType>
<xs:sequence>
<xs:element name="nFirst" type="xs:unsignedInt" minOccurs="1" maxOccurs="1" />
<xs:element name="nSecond" type="xs:unsignedInt" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- GetSumRsp -->
<xs:element name="GetSumRsp">
<xs:complexType>
<xs:sequence>
<xs:element name="nErrorCode" type="xs:unsignedInt" minOccurs="1" maxOccurs="1" />
<xs:element name="nSum" type="xs:unsignedInt" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="GetSumReq">
<wsdl:part name="parameters" element="trp:GetSumReq"/>
</wsdl:message>
<wsdl:message name="GetSumRsp">
<wsdl:part name="parameters" element="trp:GetSumRsp"/>
</wsdl:message>
<wsdl:portType name="Port">
<wsdl:operation name="GetSum">
<wsdl:input message="trp:GetSumReq"/>
<wsdl:output message="trp:GetSumRsp"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Binding" type="trp:Port">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetSum">
<soap:operation soapAction="http://www.kedacom.com.cn/ver10/KD/wsdl/GetSum"/>
<wsdl:input>
<soap:body parts="parameters" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body parts="parameters" use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="WebService">
<wsdl:port name="WebServiceSoap" binding="trp:Binding">
<soap:address location="http://localhost:1552/WebService" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
这两天搞得我蛋都快碎了,不知是协议之前匹配是否有问题,或者有没大神能够提供一整套python通过suds调用C++服务的demo,万分感谢