蓝字为关键字,等号=后面为关键字值。

一、介绍

我们用的webservice是根据gsoap编译工具来实现,gSOAP的编译器能够自动的将用户定义的本地化的C或C++数据类型转变为符合XML语法的数据结构。同时gSOAP能够根据标准化的wsdl(完全符合wsdl书写格式)文件来生成本地需要的C或C++源代码以确定发送接收XML文件的格式;

二、使用说明

当前我们用到的gSOAP版本是2.8.3,下面是生成源码的wsdl文件;如果想要生成C代码,则在生成源码时指定-c选项;例如wsdl文件名称为host.wsdl,依据以下两步生成源码:

wsdl2h –c –s –o host.h host.wsdl(具体使用可以查看帮助,依据wsdl文件生成c头文件)

soapcpp2 –c host.h(依据c指定的头文件生成c源码)

一个简单host.wsdl文件:(/**/注释栏为wsdl说明)

------------------------------------------------华丽的分割线-------------------------------------

 1 <?xml version="1.0" encoding="UTF-8"?>/*指定版本及编码格式*/
 2 /*definitions是wsdl根元素,下面通常包含以下元素,即types/ message/ portType/ operation/ binding/ service */
 3 <definitions name="MessageInfo"
 4     xmlns:tns="http://messageinfo.com"
 5     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 6     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 7     xmlns="http://schemas.xmlsoap.org/wsdl/"
 8     targetNamespace="http://messageinfo.com">
 9 /*types是数据类型定义的元素 其应用主要是schema定义格式类型*/
10 <types>
11  <schema targetNamespace="http://messageinfo.com"
12          xmlns="http://www.w3.org/2001/XMLSchema">
13    <complexType name="StatisticsRequest">
14     <sequence>
15      <element name="request" type="string"/>
16     </sequence>
17    </complexType>
18    <complexType name="StatisticsResponse">
19     <sequence>
20      <element name="AllPaketsnum" type="unsignedLong"/>
21      <element name="WormTypenum" type="unsignedLong"/>
22      <element name="Reverse1" type="string"/>
23     </sequence>
24    </complexType>
25   </schema>
26 </types>
27 /* message描述通信消息的数据结构的抽象化类型定义 */
28 <message name="GetMessageRequest">
29  <part name="Operateget" type="tns:StatisticsRequest"/>
30 </message>
31 <message name="GetMessageResponse">
32  <part name="Operateput" type="tns:StatisticsResponse"/>
33 </message>
34 /* portType描述服务和服务的方法 */
35 <portType name="MessagePortType">
36  <operation name="GetMessageRepq">
37   <input message="tns:GetMessageRequest"/>
38   <output message="tns:GetMessageResponse"/>
39  </operation>
40 </portType>
41 /* 描述通信协议,注意rpc document literal encoded各种匹配组合使用*/
42 <binding name="MessageSoapBinding" type="tns:MessagePortType">
43  <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
44  <operation name="GetMessageRepq">
45   <soap:operation style="rpc" soapAction=""/>
46    <input>
47     <soap:body use="literal" namespace="http://messageinfo.com"/>
48    </input>
49    <output>
50     <soap:body use="literal" namespace="http://messageinfo.com"/>
51    </output>
52   </operation>
53 </binding>
54 /*service描述webservice访问点的集合*/
55 <service name="MessageService">
56  <documentation>Stat Message Service Topsec Ips provide</documentation>
57  <port name="MessageSerPort" binding="tns:MessageSoapBinding">
58    <soap:address location="http://localhost:80"/>
59  </port>
60 </service>
61 
62 </definitions>
View Code

相关文章:

  • 2021-08-22
  • 2021-07-01
  • 2022-01-07
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-27
  • 2021-11-24
  • 2021-10-21
相关资源
相似解决方案