gSOAP 在windows下的安装与使用(mingw32)
gSOAP是一个绑定SOAP/XML到C/C++语言的工具,使用它可以简单快速地开发出SOAP/XML的服务器端和客户端。由于 gSOAP具 有相当不错的兼容性,通过gSOAP,我们就可以调用由Java, .Net, Delhpi, PHP等语言开发的SOAP服务,或者向它们提供SOAP服务。
(一)安装
gSOAP的主页是:
http://sourceforge.net/projects/gsoap2
下载解压后,可以在gsoap\bin\win32里 找到wsdl2h.exe和soapcpp2.exe(另外 mac版本)。
根据实践证明,windows下可以不用像https://www.genivia.com/downloads.html#releases文中所说如下图编译安装,直接使用。
当然想重新编译安装也是可以的。具体步骤如下:
首先根据说明“Tip: when autoconf, automake, flex, bison, openssl-devel, and zlib-devel are installed you can run configure to build the gSOAP tools and libraries as follows:”
需要安装以上几个库和工具,否则后面的编译会出错。
具体可以使用mingw-get.exe安装
完成以上安装后,接着可以进行gsoap编译安装
1、打开mingw32->msys目录下的终端“msys.bat 美化mintty”,记得用美化mintty版,这样可以使用右键copy。进入gsoap解压后的目录
2、执行./configure
3、执行make
4、安装,执行make install
完成以后会将soapcpp2、wsdl2h工具及库等安装部署到以下目录
根据实践证明,生成的wsdl2h运行无法正常使用
所以不建议编译安装,如果实在要使用可以将gsoap源文件夹win32下的该程序拷贝过来替换。
最后是要在windows环境变量中加入以上安装目录中的bin、lib、include等目录,记得实在不同的环境变量中哦。
如果不编译安装,而是直接使用gsoap源文件夹win32则环境变量中加入该目录即可。
当然不加入以上lib、include亦可,只需在编程工具的工程项目中增加即可,netbeans、qt等工具都可以添加。
(二)使用demo
这个参考https://blog.csdn.net/qianqiuwanzi/article/details/24120455
(以经典的calc为例)
使用gsoap\bin\win32目录中的两个应用:soapcpp2.exe和wsdl2h.exe,生成客户端和服务器端框架。
使用gSOAP生成客户端和服务器端代码框架。我们有两种做法:
- 编写WSDL,使用wsdl2h生成头文件,再通过soapcpp2生成框架代码;
- 编写头文件,使用soapcpp2生成框架代码;
经常使用的一些指令如下:
-o filename.h 将wsdl转化为filename.h头文件。
-s 不生成STL代码
-c 生成纯C风格的头文件,这将去除C++的一些特性
-n name 使用name代替默认前缀ns
-t filename.dat 使用filename.dat代替默认的typemap.dat文件
-zX 兼容之前的X版本
calc.h部分代码如下
1 /******************************************************************************\ 2 * * 3 * Services * 4 * * 5 \******************************************************************************/ 6 7 8 //gsoap ns2 service name: calc 9 //gsoap ns2 service type: calcPortType 10 //gsoap ns2 service port: http://websrv.cs.fsu.edu/~engelen/calcserver.cgi 11 //gsoap ns2 service namespace: urn:calc 12 //gsoap ns2 service transport: http://schemas.xmlsoap.org/soap/http 13 14 /** @mainpage calc Definitions 15 16 @section calc_bindings Service Bindings 17 18 - @ref calc 19 20 @section calc_more More Information 21 22 - @ref page_notes "Notes" 23 24 - @ref page_XMLDataBinding "XML Data Binding" 25 26 - @ref SOAP_ENV__Header "SOAP Header Content" (when applicable) 27 28 - @ref SOAP_ENV__Detail "SOAP Fault Detail Content" (when applicable) 29 30 31 */ 32 33 /** 34 35 @page calc Binding "calc" 36 37 @section calc_service Service Documentation "calc" 38 gSOAP 2.7.9k generated service definition 39 40 @section calc_operations Operations of Binding "calc" 41 42 - @ref ns2__add 43 44 - @ref ns2__sub 45 46 - @ref ns2__mul 47 48 - @ref ns2__div 49 50 - @ref ns2__pow 51 52 @section calc_ports Default endpoints of Binding "calc" 53 54 - http://websrv.cs.fsu.edu/~engelen/calcserver.cgi 55 56 @note Use wsdl2h option -Nname to change the service binding prefix name 57 58 59 */ 60 //gsoap ns2 service method-protocol: add SOAP 61 //gsoap ns2 service method-style: add rpc 62 //gsoap ns2 service method-encoding: add http://schemas.xmlsoap.org/soap/encoding/ 63 //gsoap ns2 service method-action: add "" 64 //gsoap ns2 service method-output-action: add Response 65 int ns2__add( 66 double :a, ///< Input parameter, : unqualified name as per RPC encoding 67 double :b, ///< Input parameter, : unqualified name as per RPC encoding 68 double &:result ///< Output parameter, : unqualified name as per RPC encoding 69 ); 70 71 //gsoap ns2 service method-protocol: sub SOAP 72 //gsoap ns2 service method-style: sub rpc 73 //gsoap ns2 service method-encoding: sub http://schemas.xmlsoap.org/soap/encoding/ 74 //gsoap ns2 service method-action: sub "" 75 //gsoap ns2 service method-output-action: sub Response 76 int ns2__sub( 77 double :a, ///< Input parameter, : unqualified name as per RPC encoding 78 double :b, ///< Input parameter, : unqualified name as per RPC encoding 79 double &:result ///< Output parameter, : unqualified name as per RPC encoding 80 ); 81 82 //gsoap ns2 service method-protocol: mul SOAP 83 //gsoap ns2 service method-style: mul rpc 84 //gsoap ns2 service method-encoding: mul http://schemas.xmlsoap.org/soap/encoding/ 85 //gsoap ns2 service method-action: mul "" 86 //gsoap ns2 service method-output-action: mul Response 87 int ns2__mul( 88 double :a, ///< Input parameter, : unqualified name as per RPC encoding 89 double :b, ///< Input parameter, : unqualified name as per RPC encoding 90 double &:result ///< Output parameter, : unqualified name as per RPC encoding 91 ); 92 93 //gsoap ns2 service method-protocol: div SOAP 94 //gsoap ns2 service method-style: div rpc 95 //gsoap ns2 service method-encoding: div http://schemas.xmlsoap.org/soap/encoding/ 96 //gsoap ns2 service method-action: div "" 97 //gsoap ns2 service method-output-action: div Response 98 int ns2__div( 99 double :a, ///< Input parameter, : unqualified name as per RPC encoding 100 double :b, ///< Input parameter, : unqualified name as per RPC encoding 101 double &:result ///< Output parameter, : unqualified name as per RPC encoding 102 ); 103 104 //gsoap ns2 service method-protocol: pow SOAP 105 //gsoap ns2 service method-style: pow rpc 106 //gsoap ns2 service method-encoding: pow http://schemas.xmlsoap.org/soap/encoding/ 107 //gsoap ns2 service method-action: pow "" 108 //gsoap ns2 service method-output-action: pow Response 109 int ns2__pow( 110 double :a, ///< Input parameter, : unqualified name as per RPC encoding 111 double :b, ///< Input parameter, : unqualified name as per RPC encoding 112 double &:result ///< Output parameter, : unqualified name as per RPC encoding 113 );
接着生成源文件:
soapcpp2 头文件 常用选项 -C 仅生成客户端代码 -S 仅生成服务器端代码 -L 不要产生soapClientLib.c和soapServerLib.c文件 -c 产生纯C代码,否则是C++代码(与头文件有关) -I 指定import路径(见上文) -x 不要产生XML示例文件 -i 生成C++包装,客户端为xxxxProxy.h(.cpp),服务器端为xxxxService.h(.cpp)。--wsj本人建议加上
在cmd命令行下进入工程目录,执行:
soapcpp2 -L -w -x -i -I D:\tools\gsoap-2.8\gsoap\import calc.h
通过netbeans创建工程项目soap_calc(client)
并将生成的soapC.cpp、soapH.h、soapStub.h、soapcalcProxy.h、soapcalcProxy.cpp、calc.nsmap、stdsoap2.h和stdsoap2.cpp文件加入到工程,其中stdsoap2.h和stdsoap2.cpp为gsoap文件夹中的文件拷贝过来即可,如果是c语言则stdsoap2.cpp替换为stdsoap2.c。
客户端代码如下
1 #include <cstdlib> 2 #include "calc.nsmap"//一定要加,不要忘记 3 #include "soapcalcProxy.h" 4 5 using namespace std; 6 7 /* 8 * 9 */ 10 int main(int argc, char** argv) { 11 calcProxy calc_clnt; 12 double add; 13 int ret=calc_clnt.add(1,2,add); 14 if(ret==SOAP_OK) { 15 printf("add=%lf", add); 16 }else 17 { 18 printf("err_code=%d", ret); 19 } 20 return 0; 21 }
运行结果
编译工程时特别要注意加上其它编译项和库
netbeans中在
中设置即可。
qtcreator只需在pro文件里添加即可
注意事项(关键):---wsj
当直接使用 soapcpp2 头文件 生成文件时,如果头文件的命名是
int downloadCAGCtrl(std::string strXMLParams,std::string *strXMLResult);时
使用soapcpp2 I2Server.h命令只能生成以下文件,无法生成wsdl、xml类型文件,这个wsdl文件在此头文件生成webservice服务端的时候很关键,在webservice调用的时候要使用。
这时候,就要将头文件内容修改下:
int ns__downloadCAGCtrl(std::string strXMLParams,std::string *strXMLResult);
对了就是在函数名前面加了命名空间名字,通常用默认的ns__
同样的命令:soapcpp2 I2Server.h 结果如下
服务端的话,建议采用命令soapcpp2 -L -S -i I2Server.h
结果:
gSOAP 在windows下的安装与使用(mingw32)相关推荐
- Windows下RabbitMQ安装及注意事项
Windows下RabbitMQ安装及注意事项 简介 背景 1. RabbitMQ是一个由erlang开发的AMQP(Advanved Message Queue)的开源实现. Rabbit ...
- flume 1.7在windows下的安装与运行
flume 1.7在windows下的安装与运行 一.安装 安装java,配置环境变量. 安装flume,flume的官网http://flume.apache.org/,下载地址,下载后直接解压即可 ...
- Windows下MongoDB安装及创建用户名和密码
Windows下MongoDB安装及创建用户名和密码 下载MongoDB的安装文件https://www.mongodb.com/download-center#community,选择合适的版本(注 ...
- Windows下Wireshark安装版本选择方式
Windows下Wireshark安装版本选择方式 Wireshark版本分为1.X系列和2.X系列.1.X系列是早期版本,不提供中文版本.2.X系列是新版本,安装后,同时提供中文版和英文版.根据系统 ...
- python怎么安装pandas模块-windows下如何安装Python、pandas
windows下如何安装Python.pandas 本篇主要涵盖以下三部分内容: Python.Pycharm的安装 使用Pycharm创建.运行Python程序 安装pandas 1.Python. ...
- 【转帖】Windows下PostgreSQL安装图解
Windows下PostgreSQL安装图解 这篇文章主要为大家介绍了如果在Windows下安装PostgreSQL数据库的方法,需要的朋友可以参考下 现在谈起免费数据库,大多数人首先想到的可能是My ...
- memcache的windows下的安装和简单使用
原文:memcache的windows下的安装和简单使用 memcache是为了解决网站访问量大,数据库压力倍增的解决方案之一,由于其简单实用,很多站点现在都在使用memcache,但是memcach ...
- TensorFlow在windows 下的安装
前言:从2015年谷歌将tensorflow开源后,这位用于深度学习的强大神器便把Caffe,Keras,Torch7等这一票人全部干掉,github上的star和fork是一路飙升,几乎是它们的总和 ...
- 学习笔记:Windows 下Keras安装和配置指南
目录: 目录: Windows下Keras安装和配置指南 Keras 框架搭建 安装 本系列参考官方文档官方文档 这就是keras可以参考前篇:这就是keras 学习笔记 Keras:一些基本概念 一 ...
最新文章
- 视频质量评估的新方式:VMAF百分位数
- wince6.0中文内核定制
- python socket server accpet 时间_Python socket.accept非阻塞?
- H264 profile and level
- TypeScript:基本类型和接口
- jq ajax购物车,jquery制作的移动端购物车效果完整示例
- 基于Javaweb实现小区物业管理系统
- 物联网开发平台快速实现ModbusRTU连接
- 6,JESD204B接口简介
- 前端JS 调用 Google地图 以及拖拽地图事件触发
- RestTemplate 下载文件
- aardio - 旋转图片
- 入手评测华为nova10和vivoS15pro选哪个
- STP生成树协议切割网络环路
- 猿创征文|当我在追光 我与光同航--我与Java的技术成长之路
- JS之class的前世今生
- 用C语言实现贪吃蛇笔记1-------.wav格式音乐的添加及播放(方法一:嵌入到可执行文件里面)
- 常见加密算法的Python实现
- 互联网创业还有前途吗
- 如何规避“Flash中国特供版”
热门文章
- x86终端登录horizon view设置
- Kendo UI常用示例汇总(九)
- ***CI中的数据库操作(insert_id新增后返回记录ID)
- [转]苹果iOS 5限制应用本地存储问题
- Red Hat Enterprise Linux 5安装图解
- 软件测试2019:第三次作业
- POJ2342-Anniversary party-树形DP入门
- .net实现md5加密 sha1加密 sha256加密 sha384加密 sha512加密 des加密解密
- WeX5 -- xcode7+iphone免费帐号打包详解
- 移动H5前端性能优化指南[转]