您的位置:首页 > 其它

gsoap

2016-01-19 00:00 281 查看
摘要: wsdl2h,soapcpp2
测试wsdl文件

安装

aptitude install libcgsi-gsoap-dev

wsdl到h文件

wsdl2h test.wsdl
用法:wsdl2h -o 头文件名 WSDL文件名或URLwsdl2h

wsdl2h常用选项

-o 文件名,指定输出头文件
-n 名空间前缀 代替默认的ns
-c 产生纯C代码,否则是C++代码
-s 不要使用STL代码
-t 文件名,指定type map文件,默认为typemap.dat
-e 禁止为enum成员加上名空间前缀
生成(-I/usr/share/gsoap/import/:包含头文件)

用法soapcpp2 头文件例:soapcpp2 ayandy.h

将生成下面这些文件soapStub.h // soap的存根文件,定义了ayandy.h里对应的远程调用模型
soapC.c soapH.h // soap的序列和反序列代码,它已经包含了soapStub.h,服务器端与客户端都要包含它
soapClient.c soapClientLib.c // 客户端代码,soapClientLib.c文件则只是简单地包含soapClient.c和soapC.c
soapServer.c soapServerLib.c // 服务器端代码,soapServerLib.c文件则只是简单地包含soapServer.c和soapC.c
ServiceSoap.nsmap ServiceSoap12.nsmap // 名空间定义,服务器端与客户端都要包含它
soapServiceSoapProxy.h soapServiceSoap12Proxy.h // 客户端的C++简单包装(如果头文件是纯C代码,这两个文件就不会生成)

soapcpp2常用选项

-C 仅生成客户端代码

-S 仅生成服务器端代码

-L 不要产生soapClientLib.c和soapServerLib.c文件

-c 产生纯C代码,否则是C++代码(与头文件有关)
-I 指定import路径(见上文)
-x 不要产生XML示例文件
-i 生成C++包装,客户端为xxxxProxy.h(.cpp),服务器端为xxxxService.h(.cpp)。

测试wsdl文件

//位置: http://www.cs.fsu.edu/~engelen/calc.wsdl <?xml version="1.0" encoding="UTF-8"?>
<definitions name="calc"
targetNamespace="http://websrv.cs.fsu.edu/~engelen/calc.wsdl"
xmlns:tns="http://websrv.cs.fsu.edu/~engelen/calc.wsdl"
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:calc"
xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/"
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:calc"
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:calc"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
</schema>

</types>

<message name="addRequest">
<part name="a" type="xsd:double"/>
<part name="b" type="xsd:double"/>
</message>

<message name="addResponse">
<part name="result" type="xsd:double"/>
</message>

<message name="subRequest">
<part name="a" type="xsd:double"/>
<part name="b" type="xsd:double"/>
</message>

<message name="subResponse">
<part name="result" type="xsd:double"/>
</message>

<message name="mulRequest">
<part name="a" type="xsd:double"/>
<part name="b" type="xsd:double"/>
</message>

<message name="mulResponse">
<part name="result" type="xsd:double"/>
</message>

<message name="divRequest">
<part name="a" type="xsd:double"/>
<part name="b" type="xsd:double"/>
</message>

<message name="divResponse">
<part name="result" type="xsd:double"/>
</message>

<message name="powRequest">
<part name="a" type="xsd:double"/>
<part name="b" type="xsd:double"/>
</message>

<message name="powResponse">
<part name="result" type="xsd:double"/>
</message>

<portType name="calcPortType">
<operation name="add">
<documentation>Service definition of function ns__add</documentation>
<input message="tns:addRequest"/>
<output message="tns:addResponse"/>
</operation>
<operation name="sub">
<documentation>Service definition of function ns__sub</documentation>
<input message="tns:subRequest"/>
<output message="tns:subResponse"/>
</operation>
<operation name="mul">
<documentation>Service definition of function ns__mul</documentation>
<input message="tns:mulRequest"/>
<output message="tns:mulResponse"/>
</operation>
<operation name="div">
<documentation>Service definition of function ns__div</documentation>
<input message="tns:divRequest"/>
<output message="tns:divResponse"/>
</operation>
<operation name="pow">
<documentation>Service definition of function ns__pow</documentation>
<input message="tns:powRequest"/>
<output message="tns:powResponse"/>
</operation>
</portType>

<binding name="calc" type="tns:calcPortType">
<SOAP:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="add">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:calc" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:calc" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="sub">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:calc" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:calc" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="mul">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:calc" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:calc" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="div">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:calc" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:calc" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="pow">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:calc" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:calc" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>

<service name="calc">
<documentation>gSOAP 2.7.9k generated service definition</documentation>
<port name="calc" binding="tns:calc">
<SOAP:address location="http://websrv.cs.fsu.edu/~engelen/calcserver.cgi"/>
</port>
</service>

</definitions>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: