资源预览内容
第1页 / 共9页
第2页 / 共9页
第3页 / 共9页
第4页 / 共9页
第5页 / 共9页
第6页 / 共9页
第7页 / 共9页
第8页 / 共9页
第9页 / 共9页
亲,该文档总共9页全部预览完了,如果喜欢就下载吧!
资源描述
C+借助 gSOAP 快速实现服务端和客户端 潘孙友 2012/06/08 目录目录 1. gSOAP 简介 2 2. 用 gSOAP 在 C+中提供 WebService 服务 . 2 2.1. 编写 WSDL 2 2.2. 通过 gSOAP 生成框架代码 2 2.3. 编译并运行服务程序 4 2.4. 测试服务接口 5 3. 用 gSOAP 在 C+中调用 WebService 服务 . 6 3.1. 获取 WSDL 6 3.2. 通过 gSOAP 生成客户端 C+代码. 6 3.3. 编译并调用远程服务 8 1. gSOAP 简介简介 gSOAP 工具可以从 WSDL 文件生成 C+服务端框架和客户端框架, 大大简化 WebService 服务 端及客户端代码的编写(基本不用再写了)。 gSOAP 可从以下地址下载: http:/en.sourceforge.jp/projects/sfnet_gsoap2/downloads/gSOAP/gsoap_2.8.8.zip/ 文档,请阅读: doc/ gSOAP 2.8.0 User Guide.htm 已经非常非常详细。 2. 用用 gSOAP 在在 C+中提供中提供 WebService 服务服务 2.1. 编写编写 WSDL 手工编写;使用 myeclips 的图形界面工具来编写 示例中的 wsdl/ zyccbIbsService.wsdl 仅仅提供了一个接口,名字是 Control。 2.2. 通过通过 gSOAP 生成框架代码生成框架代码 每次 wsdl/ zyccbIbsService.wsdl (这里只是个示例,肯定不叫这个名字这里只是个示例,肯定不叫这个名字) 有改改动,都需要执 行 wsdl/updateSource.bat/sh 来重新生成代码。 详见 gsoapSampleServer/wsdl/updateSource.sh/bat 示例中生成的所有东西在: gsoapSampleServer/src/ gsoapAutoGenCode, 生成文件的名称以及生成文件的名称以及 路径可以在生成时指定路径可以在生成时指定。 服务端所需要的文件如下:服务端所需要的文件如下: src/ gsoapAutoGenCode/autoGen_C.cpp 通过 wsdl 生成的代码,完全不需要修改完全不需要修改。 虽然autoGen_zyccbIbsService.cpp中有些 方法没有实现,但我们不在这里修改,而是 另外新建个 cpp 文件, 比如 serviceIMPL.cpp src/ gsoapAutoGenCode/autoGen_H.h src/ gsoapAutoGenCode/autoGen_Stub.h src/gsoapAutoGenCode/autoGen_zyccbIbsService.cpp src/ gsoapAutoGenCode/autoGen_zyccbIbsService.h / gsoap-2.8/stdsoap2.cpp 这是 gSOAP 自身的文件,也不需要修改不需要修改。 / gsoap-2.8/*.h src/gsoapSampleServer.cpp serviceIMPL.cpp 补充了 src/serviceIMPL.cpp autoGen_zyccbIbsService.cpp 中未实现的 代码。gsoapSampleServer.cpp 中实例化 WebService 服务对象. 示例: root gsoapSampleServer#pwd /mnt/wine/coding/gsoapSample/gsoapSampleServer root gsoapSampleServer#cd wsdl/ root wsdl#sh updateSourceCode.sh 1. 初始化环境 /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/db2inst1/sqlli b/bin:/home/db2inst1/sqllib/adm:/home/db2inst1/sqllib/misc:/home/db2inst1/sqllib/db2tss/bin: /gsoap-2.8/bin/linux386 2. 编译 wsdl 至.h * The gSOAP WSDL/Schema processor for C and C+, wsdl2h release 2.8.8 * Copyright (C) 2000-2012 Robert van Engelen, Genivia Inc. * All Rights Reserved. This product is provided “as is“, without any warranty. * The wsdl2h tool is released under one of the following two licenses: * GPL or the commercial license by Genivia Inc. Use option -l for details. Saving /src/gsoapAutoGenCode/serviceInternal.h Reading type definitions from type map file typemap.dat Reading file zyccbIbsService.wsdl. Done reading zyccbIbsService.wsdl To complete the process, compile with: soapcpp2 /src/gsoapAutoGenCode/serviceInternal.h or to generate C+ proxy and object classes: soapcpp2 -j /src/gsoapAutoGenCode/serviceInternal.h 3. 编译.h 至服务端框架代码(客户端可选, 去掉-S 同时生成客户端代码) * The gSOAP code generator for C and C+, soapcpp2 release 2.8.8 * Copyright (C) 2000-2012, Robert van Engelen, Genivia Inc. * All Rights Reserved. This product is provided “as is“, without any warranty. * The soapcpp2 tool is released under one of the following two licenses: * GPL or the commercial license by Genivia Inc. Using project directory path: /src/gsoapAutoGenCode/ Saving /src/gsoapAutoGenCode/autoGen_Stub.h annotated copy of the input declarations Using zyccbIbs service name: zyccbIbs Using zyccbIbs service style: document Using zyccbIbs service encoding: literal Using zyccbIbs service location: http:/127.0.0.1:5299/zyccbIbs Using zyccbIbs schema namespace: aps.org/zyccbIbs Saving /src/gsoapAutoGenCode/autoGen_zyccbIbsService.h service class Saving /src/gsoapAutoGenCode/autoGen_zyccbIbsService.cpp service class Saving /src/gsoapAutoGenCode/zyccbIbs.nsmap namespace mapping table Saving /src/gsoapAutoGenCode/autoGen_H.h interface declarations Saving /src/gsoapAutoGenCode/autoGen_C.cpp XML serializers Compilation successful 如果上面显示(Compilation successful), 则代码已生成在 /src/gsoapAutoGenCode, 按回车退出 root wsdl# 2.3. 编译并运行服务程序编译并运行服务程序 root gsoapSampleServer#make g+ -g -Wall -I. -I./src -I./inc -DWITH_NONAMESPACES -I/gsoap-2.8 -c /gsoap-2.8/stdsoap2.cpp -o /gsoap-2.8/stdsoap2.o g+ -g -Wall -I. -I./src -I./inc -DWITH_NONAMESPACES -I/gsoap-2.8 -c src/gsoapSampleServer.cpp -o src/gsoapSampleServer.o g+ -g -Wall -I. -I./src -I./inc -DWITH_NONAMESPACES -I/gsoap-2.8 -c src/serviceIMPL.cpp -o src/serviceIMPL.o g+ -g -Wall -I. -I./src -I./inc -DWITH_NONAMESPACES -I/gsoap-2.8 -c src/gsoapAutoGenCode/autoGen_C.cpp -o src/gsoapAutoGenCode/autoGen_C.o g+ -g -Wall -I. -I./src -I./inc -DWITH_NONAMESPACES -I/gsoap-2.8 -c src/gsoapAutoGenCode/autoGen_zyccbIbsService.cpp -o src/gsoapAutoGenCode/autoGen_zyccbIbsService.o -e Linking gsoapSampleServer.debug g+ /gsoap-2.8/stdsoap2.o src/gsoapSampleServer.o src/serviceIMPL.o src/gsoapAutoGenCode/autoGen_C.o src/gsoapAutoGenCode/autoGen_zyccbIbsService.o -L/lib -lpthread -ldl -o /bin/gsoapSampleServer.debug root gsoapSampleServer#cd /bin root bin#./gsoapSampleServer.debug./gsoapSampleServer.debug 创建 SOAP 服务对象 . 设置 SOAP 属性: 通讯字符串使用 UTF-8 编码. 设置 SOAP 属性: 防止客户端半途断开时使用服务进程退出 绑定服务于端口 5299, 请使用 SoapUI 访问: http:/127.0.0.1:5299/zyccbIbs 2.4. 测试服务接口测试服务接口 WebService 客户端测试工具:http:/
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号