gsoap开发webservice
gSOAP编译工具提供了一个SOAP/XML 关于C/C++ 语言的实现,从而让C/C++语言开发web服务或客户端程序的工作变得轻松了很多。绝大多数的C++web服务工具包提供一组API函数类库来处理特定的SOAP数据结构,这样就使得用户必须改变程序结构来适应相关的类库。与之相反,gSOAP利用编译器技术提供了一组透明化的SOAP API,并将与开发无关的SOAP实现细节相关的内容对用户隐藏起来。
gSOAP的编译器能够自动的将用户定义的本地化的C或C++数据类型转变为符合XML语法的数据结构,反之亦然。这样,只用一组简单的API就将用户从SOAP细节实现工作中解脱了出来,可以专注与应用程序逻辑的实现工作了。gSOAP编译器可以集成C/C++和Fortran代码(通过一个Fortran到C的接口),嵌入式系统,其他SOAP程序提供的实时软件的资源和信息;可以跨越多个操作系统,语言环境以及在防火墙后的不同组织。
gSOAP使编写web服务的工作最小化了。gSOAP编译器生成SOAP的代码来序列化或反序列化C/C++的数据结构。gSOAP包含一个WSDL生成器,用它
来为你的web服务生成web服务的解释。gSOAP的解释器及导入器可以使用户不需要分析web服务的细节就可以实现一个客户端或服务端程序。
下面是gSOAP的一些特点:
gSOAP编译器可以根据用户定义的C和C++数据结构自动生成符合SOAP的实例化代码。
如果用生成纯C的代码,需要加编译选项-c
wsdl2h -c -o outfile.h(为自己任意起的头文件) infile.wsdl(提供的wsdl文件)
如果用生成纯C的代码,需要加编译选项-c
soapcpp2 -c outfile.h生成构架代码
soapC.cpp soapC.h soapServer.cpp soapStub.h stdsoap2.cpp stdsoap2.h stlvector.h WcmpServiceSOAP11Binding.nsmap(这个文件名根据outfile文件是不同的)
作为客户端,需要的代码为:
soapC.cpp soapC.h soapClient.cpp soapStub.h stdsoap2.cpp stdsoap2.h stlvector.h WcmpServiceSOAP11Binding.nsmap(这个文件名根据outfile文件是不同的)

#include "stdafx.h"#include "soapH.h"#include <stdio.h>#include "calc.nsmap"using namespace std;int main(int argc, char **argv){ SOAP_SOCKET m, s; /* master and slave sockets */ struct soap soap; soap_init(&soap); if (argc < 2) soap_serve(&soap); /* serve as CGI application */ else { m = soap_bind(&soap, NULL, atoi(argv[1]), 100); if (!soap_valid_socket(m)) { soap_print_fault(&soap, stderr); exit(-1); } fprintf(stderr, "Socket connection successful: master socket = %d\n", m); for ( ; ; ) { s = soap_accept(&soap); fprintf(stderr, "Socket connection successful: slave socket = %d\n", s); if (!soap_valid_socket(s)) { soap_print_fault(&soap, stderr); exit(-1); } soap_serve(&soap); soap_end(&soap); } } return 0;} int __cdecl ns2__add(struct soap *soap,double a,double b,double &result){ result = a + b; cout<<"the result is ---"<<result<<endl; return SOAP_OK;}int __cdecl ns2__sub(struct soap *soap, double a, double b, double &result){ result = a - b; return SOAP_OK;}int __cdecl ns2__mul(struct soap *soap, double a, double b, double &result){ result = a * b; return SOAP_OK;}int __cdecl ns2__div(struct soap *soap, double a, double b, double &result){ if (b) result = a / b; else { char *s = (char*)soap_malloc(soap, 1024); sprintf(s, "<error xmlns=\"http://tempuri.org/\">Can't divide %f by %f</error>", a, b); return soap_sender_fault(soap, "Division by zero", s); } return SOAP_OK;}int __cdecl ns2__pow(struct soap *soap, double a, double b, double &result){ result = pow(a, b); if (soap_errno == EDOM) /* soap_errno is like errno, but compatible with Win32 */ { char *s = (char*)soap_malloc(soap, 1024); sprintf(s, "Can't take the power of %f to %f", a, b); sprintf(s, "<error xmlns=\"http://tempuri.org/\">Can't take power of %f to %f</error>", a, b); return soap_sender_fault(soap, "Power function domain error", s); } return SOAP_OK;} |
#include "stdafx.h"#include "soapH.h"#include "calc.nsmap"//const char server[] = "http://websrv.cs.fsu.edu/~engelen/calcserver.cgi";const char server[] = "http://localhost:8000";int main(int argc, char* argv[]){ struct soap soap; double a, b, result; if (argc < 4) { fprintf(stderr, "Usage: [add|sub|mul|div|pow] num num\n"); exit(0); } soap_init1(&soap, SOAP_XML_INDENT); a = strtod(argv[2], NULL); b = strtod(argv[3], NULL); switch (*argv[1]) { case 'a': soap_call_ns2__add(&soap, server, "", a, b, result); break; case 's': soap_call_ns2__sub(&soap, server, "", a, b, result); break; case 'm': soap_call_ns2__mul(&soap, server, "", a, b, result); break; case 'd': soap_call_ns2__div(&soap, server, "", a, b, result); break; case 'p': soap_call_ns2__pow(&soap, server, "", a, b, result); break; default: fprintf(stderr, "Unknown command\n"); exit(0); } if (soap.error) { soap_print_fault(&soap, stderr); exit(1); } else printf("result = %g\n", result); soap_destroy(&soap); soap_end(&soap); soap_done(&soap); return 0;} |


gsoap开发webservice的更多相关文章
- 使用GSoap开发WebService客户端与服务端
Gsoap 编译工具提供了一个SOAP/XML 关于C/C++ 语言的实现, 从而让C/C++语言开发web服务或客户端程序的工作变得轻松了很多. 用gsoap开发web service的大致思路 我 ...
- windows下vs2012用gsoap开发webservice实例
零:说明 1.本文是根据网上前人经验结合自己动手操作写成,开发工具用的vs2012,gsoap用的是gsoap-2.8: 2.gsoap提供的工具简单介绍 1)wsdl2h.exe:根据WSDL文件生 ...
- VS2010使用c++、gSOAP创建WebService 图文教程
VS2010使用c++.gSOAP创建的WebService 图文教程 环境 操作系统:Windows 7gsoap版本:2.8.32C++编译器/开发环境:Visual Studio 2010 gS ...
- 使用JDK开发WebService
一.WebService的开发手段 使用Java开发WebService时可以使用以下两种开发手段 1. 使用JDK开发(1.6及以上版本) 2.使用CXF框架开发(工作中) 二.使用JDK开发Web ...
- Java开发Webservice的组件
参考:http://bbs.csdn.net/topics/390900831 转自:http://blog.csdn.net/dragoo1/article/details/50759222 htt ...
- 2.使用JDK开发webService
使用jdk开发webService需要注意:jdk版本必须1.6以及1.6以上! 以下webService的组成部分: server端和client端,通过服务器端(server)webService ...
- 利用NuSoap开发WebService(PHP)
利用NuSoap开发WebService(PHP) 分类: php 2010-09-08 12:00 5005人阅读 评论(1) 收藏 举报 webservicephpsoapstringencodi ...
- JAVA6开发WebService (四)——SAAJ调用WebService
转载自http://wuhongyu.iteye.com/blog/810571 前面写了个JAX-WS的小例子,看到用JAVA6开发WebService确实很简单,也很方便,不过前面也说了,JAVA ...
- Apache axis2 + Eclipse 开发 WebService
yd小结注意:1.axis2的2个插件的版本必须与引入的jar包匹配,如果不同则可能报以下错误 “没有实现序列化方法”或 “org.apache.axis2.databinding.utils.wri ...
随机推荐
- SPFA 求带负权的单源最短路
int spfa_bfs(int s) { ///s表示起点. queue <int> q; memset(d,0x3f,sizeof(d)); ///d数组中存下的就是最短路径(存在的话 ...
- hql 多对多查询
这种查询,hibernate 建议用 From Dealer s inner join fetch s.carSerieses cs 实现,注意这种实现只支持b.c,不支持b.cs. 如果要用b.c ...
- ios You app information could not be saved. Try again. If the problem persists, contact us
ios You app information could not be saved. Try again. If the problem persists, contact us 大概意思:你的a ...
- 赵雅智_Android案例_刮刮乐
实现效果 主要代码 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...
- MyEclipse 设置智能提示
choice 1: -->window→Preferences→Java→Editor→Content Assist, --->将Auto activation delay 的数值改为一个 ...
- vue-router篇
目录结构: -lib-vue.js -lib-vue-router.js -js-main.js -index.html 1.安装和基本配置 2.传参以及获取传参 3.子路由 4.手动访问和传参 5. ...
- 备忘:js正则表达式中的元字符
Predefined term Matches \t Horizontal tab \b Backspace \v Vertical tab \f Form feed \r Carriage retu ...
- 目标检测之harr---点角检测harr
Haar特征与积分图 1. Adaboost方法的引入 1.1 Boosting方法的提出和发展 在了解Adaboost方法之前,先了解一下Boosting方法. 回答一个是与否的问题,随机猜测可以获 ...
- Mysql 存储过程使用游标
-- 完整例子 CREATE PROCEDURE test BEGIN -- 定义参数 DECLARE _id INT; -- 定义游标 DECLARE no_more_products ...
- unity3d从零開始(五):了解摄像机
1.简单介绍 Unity的摄像机是用来将游戏世界呈现给玩家的,游戏场景中至少有一台摄像机.也能够有多台. 2.类型 Unity中支持两种类型的摄像机,各自是Perspe ...