gSOAP与.NET的兼容性
我正在使用gSOAP创建一个由基于Linux的系统托管的web服务 我从以下头文件(gSOAP与.NET的兼容性,.net,web-services,wsdl,gsoap,.net,Web Services,Wsdl,Gsoap,我正在使用gSOAP创建一个由基于Linux的系统托管的web服务 我从以下头文件(mytest.h)开始: 然后运行gSOAP编译器,以获得相应的骨架/存根类和相应的WSDL。我使用soapcpp2-e-jmytest.h运行编译器,并获得以下WSDL: <?xml version="1.0" encoding="UTF-8"?> <definitions name="mytest" targetNamespace="urn:mytest" xmlns:tns="urn:
mytest.h
)开始:
然后运行gSOAP编译器,以获得相应的骨架/存根类和相应的WSDL。我使用soapcpp2-e-jmytest.h运行编译器,并获得以下WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="mytest"
targetNamespace="urn:mytest"
xmlns:tns="urn:mytest"
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:ns="urn:mytest"
xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:HTTP="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:MIME="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:DIME="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/"
xmlns:WSDL="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetNamespace="urn:mytest"
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:ns="urn:mytest"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
</schema>
</types>
<message name="setdata">
<part name="data" type="ns:testStruct"/><!-- ns__setdata::data -->
</message>
<message name="getdata">
</message>
<message name="testStruct">
<part name="field1" type="xsd:string"/><!-- ns__getdata::field1 -->
<part name="field2" type="xsd:string"/><!-- ns__getdata::field2 -->
</message>
<portType name="mytestPortType">
<operation name="setdata">
<documentation>Service definition of function ns__setdata</documentation>
<input message="tns:setdata"/>
</operation>
<operation name="getdata">
<documentation>Service definition of function ns__getdata</documentation>
<input message="tns:getdata"/>
<output message="tns:testStruct"/>
</operation>
</portType>
<binding name="mytest" type="tns:mytestPortType">
<SOAP:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="setdata">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:mytest" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
</operation>
<operation name="getdata">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:mytest" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:mytest" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="mytest">
<documentation>gSOAP 2.8.17r generated service definition</documentation>
<port name="mytest" binding="tns:mytest">
<SOAP:address location="http://localhost/mytest"/>
</port>
</service>
</definitions>
函数ns_uuusetdata的服务定义
函数ns\uu getdata的服务定义
gSOAP 2.8.17r生成的服务定义
然后,使用此WSDL,我想在C#(VS2013)中创建一个简单的客户端,但当我尝试导入WSDL时,Visual Studio失败,出现以下错误:
自定义工具错误:无法导入Web服务/架构。不能
从命名空间“urn:mytest”导入绑定“mytest”。无法导入
操作“setdata”。缺少数据类型“urn:mytest:testStruct”
为什么??有什么想法吗?好的,找到了解决方案
我复制/粘贴链接页面的相关内容:
class test__X {
long id;
};
int test__f(test__X, bool &);
int test__g(test__X &);
这是中缺少响应包装器结构的典型示例
测试。问题是doc/lit样式需要测试X
定义为架构元素,因为它是的响应消息
测试。因为它也被定义为complexType,冲突
出现
在这种情况下,必须将响应参数包装在结构中,
比如:test_uug(struct test_ugresult{test_uux;}&)
基本类型(如bool)不需要包装,因为gSOAP
将为您生成一个响应消息test\u frespose
因此,在我的例子中,我必须修改我的mytest.h
,如下所示:
#ifndef MYTEST_H
#define MYTEST_H
//gsoap ns service name: mytest
//gsoap ns service namespace: urn:mytest
//gsoap ns service location: http://localhost/mytest
struct ns__testStruct {
char *field1;
char *field2;
};
int ns__setdata(struct ns__testStruct data, void);
int ns__getdata(struct ns__getDataResponse { struct ns__testStruct d; } *data);
#endif // MYTEST_H
#ifndef MYTEST_H
#define MYTEST_H
//gsoap ns service name: mytest
//gsoap ns service namespace: urn:mytest
//gsoap ns service location: http://localhost/mytest
struct ns__testStruct {
char *field1;
char *field2;
};
int ns__setdata(struct ns__testStruct data, void);
int ns__getdata(struct ns__getDataResponse { struct ns__testStruct d; } *data);
#endif // MYTEST_H