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 ...
随机推荐
- ccs 中的定位
一.相对定位 position:relative; 作用: 相对定位 一般加给定位元素父级 特点: (1)不脱离文档流: (2)不改变元素类型: (3)参照物是元素本身: 二.绝对定位 posi ...
- css3 - 动态伪类
动态伪类分为以下几种: 1. hover(经过) 2. active(点击后) 3. focus(聚焦) - input专用 4. visited(访问后) 使用:
- Food hub
Work center List Tillage 耕作 Hand harvest 手工采收 Planting 种植 Cultivating 培养 Mulching 覆盖 Dig harvest 挖地采 ...
- Convert Sorted List to Binary Search Tree——将链表转换为平衡二叉搜索树 &&convert-sorted-array-to-binary-search-tree——将数列转换为bst
Convert Sorted List to Binary Search Tree Given a singly linked list where elements are sorted in as ...
- String.split()分割字符串方法
split方法的主要用处就是:分割字符串 split方法返回的是数组类型 主要由以下几种用法: 1.比如有一个字符串var str = "bcadeab";对str使用split方 ...
- FPGA机器学习之机器学习的n中算法总结1
机器学习是AI领域的重要一门学科.前面我描写叙述过.我计划从事的方向是视觉相关的机器学习分类识别,所以可能在每一个算法的分析中,仅仅增加在视频.视觉领域的作用. 我毛华望QQ849886241.技术博 ...
- angular 指令封装弹出框效果
就直接用bs的警告框啦~,Duang~ 功能 可以设置message和type,type就是bs内置的几种颜色 默认提示3秒框自动关闭,或者点击x号关闭 代码 模板 <div class=&qu ...
- Android Studio 工程的 .gitignore
新建一个 Android Studio 工程时会默认建立两个 .gitignore 文件 .gitignore *.iml .gradle /local.properties /.idea/works ...
- Struts2实例详解(转载)
Struts2(上) 一. 经典的MVC模式 二. Struts1.x对MVC的实现 三. Struts1.x的主要组件和作用 组件 作用 ActionSer ...
- File syncing and sharing software with file encryption and group sharing, emphasis on reliability and high performance.
http://seafile.com/ showdoc haiwen/seafile: File syncing and sharing software with file encryption a ...