C++ gSOAP 文件生成
看起来 gSoap“忘记”生成了很多东西。我使用
wsdl2h.exe -o NumOpsService.h http://192.168.2.113/numops.wsdl
soapcpp2.exe -x -l -I..\..\import -C NumOpsService.h
并且都运行没有错误或警告。当我将这些文件包含到我的项目中时,结果发现在 soapH.h
中声明了几个函数,但缺少应位于 soapC.cpp
中的相应实现。
缺少以下功能:
SOAP_FMAC3 void SOAP_FMAC4 soap_markelement(struct soap*, const void*, int);
SOAP_FMAC3 int SOAP_FMAC4 soap_putelement(struct soap*, const void*, const char*, int, int);
SOAP_FMAC3 void *SOAP_FMAC4 soap_getelement(struct soap*, int*);
SOAP_FMAC3 int SOAP_FMAC4 soap_putindependent(struct soap*);
SOAP_FMAC3 int SOAP_FMAC4 soap_getindependent(struct soap*);
SOAP_FMAC3 int SOAP_FMAC4 soap_ignore_element(struct soap*);
SOAP_FMAC3 void * SOAP_FMAC4 soap_instantiate(struct soap*, int, const char*, const char*, size_t*);
SOAP_FMAC3 int SOAP_FMAC4 soap_fdelete(struct soap_clist*);
SOAP_FMAC3 void* SOAP_FMAC4 soap_class_id_enter(struct soap*, const char*, void*, int, size_t, const char*, const char*);
SOAP_FMAC3 void* SOAP_FMAC4 soap_container_id_forward(struct soap*, const char*, void*, size_t, int, int, size_t, unsigned int);
SOAP_FMAC3 void SOAP_FMAC4 soap_container_insert(struct soap*, int, int, void*, size_t, const void*, size_t);
怎么会发生这种情况?是 numops.wsdl
文件有问题吗?我用来生成的文件看起来像这样:
<definitions name="NumOps"
targetNamespace="http://192.168.2.113/numops.wsdl"
xmlns:tns="http://192.168.2.113/numops.wsdl"
xmlns:xsd1="http://192.168.2.113/testtypes.xsd"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetNamespace="http://192.168.2.113/testtypes.xsd"
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="AddValRequest">
<complexType>
<all>
<element name="fVal1" type="float"/>
<element name="fVal2" type="float"/>
</all>
</complexType>
</element>
<element name="AddValResponse">
<complexType>
<all>
<element name="fResult" type="float"/>
</all>
</complexType>
</element>
</schema>
</types>
<message name="AddValInput">
<part name="body" element="xsd1:AddValRequest"/>
</message>
<message name="AddValOutput">
<part name="body" element="xsd1:AddValResponse"/>
</message>
<portType name="NumOpsPortType">
<operation name="AddVal">
<input message="tns:AddValInput"/>
<output message="tns:AddValOutput"/>
</operation>
</portType>
<binding name="NumOpsSoapProxy" type="tns:NumOpsPortType">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="AddVal">
<soap:operation soapAction="http://192.168.2.113/index.php"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="NumOpsService">
<port name="NumOpsPort" binding="tns:NumOpsSoapProxy">
<soap:address location="http://192.168.2.113/index.php"/>
</port>
</service>
</definitions>
我是gSOAP的新手,不幸的是,文档并没有那么过多,并且互联网上似乎没有人以前遇到过这个问题,或者也许我正在寻找错误的方向。
我已将生成的所有文件(NumOpsService.h
除外)包含到我的项目中,并添加了 stdsoap2.h
和 stdsoap2.cpp
。由于缺少函数而无法编译的源代码如下所示:
#include <stdio.h>
#include "NumOpsSoapProxy.nsmap"
#include "soapNumOpsSoapProxyProxy.h"
int main() {
NumOpsSoapProxy proxy;
_ns2__AddValRequest request;
_ns2__AddValResponse response;
request.fVal1 = 10;
request.fVal2 = 20;
if(proxy.__ns1__AddVal(&request, &response) == SOAP_OK) {
printf("%d + %d = %d\n", request.fVal1, request.fVal2, response.fResult);
}
else {
printf("Request failed.\n");
}
}
It's looking like gSoap "forgot" to generate a lot of stuff. I used
wsdl2h.exe -o NumOpsService.h http://192.168.2.113/numops.wsdl
soapcpp2.exe -x -l -I..\..\import -C NumOpsService.h
And both run through without errors or warnings. When I include the files into my project, it turns out several functions have been declared in soapH.h
but the respective implementation which should be located in soapC.cpp
is missing.
The following functions are missing:
SOAP_FMAC3 void SOAP_FMAC4 soap_markelement(struct soap*, const void*, int);
SOAP_FMAC3 int SOAP_FMAC4 soap_putelement(struct soap*, const void*, const char*, int, int);
SOAP_FMAC3 void *SOAP_FMAC4 soap_getelement(struct soap*, int*);
SOAP_FMAC3 int SOAP_FMAC4 soap_putindependent(struct soap*);
SOAP_FMAC3 int SOAP_FMAC4 soap_getindependent(struct soap*);
SOAP_FMAC3 int SOAP_FMAC4 soap_ignore_element(struct soap*);
SOAP_FMAC3 void * SOAP_FMAC4 soap_instantiate(struct soap*, int, const char*, const char*, size_t*);
SOAP_FMAC3 int SOAP_FMAC4 soap_fdelete(struct soap_clist*);
SOAP_FMAC3 void* SOAP_FMAC4 soap_class_id_enter(struct soap*, const char*, void*, int, size_t, const char*, const char*);
SOAP_FMAC3 void* SOAP_FMAC4 soap_container_id_forward(struct soap*, const char*, void*, size_t, int, int, size_t, unsigned int);
SOAP_FMAC3 void SOAP_FMAC4 soap_container_insert(struct soap*, int, int, void*, size_t, const void*, size_t);
How can this happen? Is it a problem with the numops.wsdl
file? The file I'm using to generate looks like this:
<definitions name="NumOps"
targetNamespace="http://192.168.2.113/numops.wsdl"
xmlns:tns="http://192.168.2.113/numops.wsdl"
xmlns:xsd1="http://192.168.2.113/testtypes.xsd"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetNamespace="http://192.168.2.113/testtypes.xsd"
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="AddValRequest">
<complexType>
<all>
<element name="fVal1" type="float"/>
<element name="fVal2" type="float"/>
</all>
</complexType>
</element>
<element name="AddValResponse">
<complexType>
<all>
<element name="fResult" type="float"/>
</all>
</complexType>
</element>
</schema>
</types>
<message name="AddValInput">
<part name="body" element="xsd1:AddValRequest"/>
</message>
<message name="AddValOutput">
<part name="body" element="xsd1:AddValResponse"/>
</message>
<portType name="NumOpsPortType">
<operation name="AddVal">
<input message="tns:AddValInput"/>
<output message="tns:AddValOutput"/>
</operation>
</portType>
<binding name="NumOpsSoapProxy" type="tns:NumOpsPortType">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="AddVal">
<soap:operation soapAction="http://192.168.2.113/index.php"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="NumOpsService">
<port name="NumOpsPort" binding="tns:NumOpsSoapProxy">
<soap:address location="http://192.168.2.113/index.php"/>
</port>
</service>
</definitions>
I'm new to gSOAP, the documentation unfortunately is not that excessive, and noone on the internet seems to have had this problem before, or maybe I'm looking in the wrong direction.
I've included all files generated (except for NumOpsService.h
) into my project and also added stdsoap2.h
and stdsoap2.cpp
. The source that won't compile because of the missing functions looks like this:
#include <stdio.h>
#include "NumOpsSoapProxy.nsmap"
#include "soapNumOpsSoapProxyProxy.h"
int main() {
NumOpsSoapProxy proxy;
_ns2__AddValRequest request;
_ns2__AddValResponse response;
request.fVal1 = 10;
request.fVal2 = 20;
if(proxy.__ns1__AddVal(&request, &response) == SOAP_OK) {
printf("%d + %d = %d\n", request.fVal1, request.fVal2, response.fResult);
}
else {
printf("Request failed.\n");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的评论升级为答案:
My comment promoted to an answer: