webservice gsoap 小记
参考 http://www.cs.fsu.edu/~engelen/soap.html
1. web service client application
> wsdl2h -s -o MyHead.h http://www.genivia.com/calc.wsdl
-s 不用 STL
> soapcpp2 -i -C MyHead.h
Option -i (and alternatively option -j) indicates that we want C++ proxy and server objects that include the client (and server) code, -C indicates client-side only
soapcpp2 generates both client and server stubs and skeletons by default
这两步过程中可能会出错,要把必要的文件加上: soap12.h stdsoap2.h stdsoap2.cpp
然后,We use the generated soapcalcProxy class and calc.nsmap XML namespace mapping table to access the Web service. The soapcalcProxy class is a proxy to invoke the service:
#include "soapWebService1SoapProxy.h" // 自动生成的头文件 注:不用MyHead.h
#include "WebService1Soap.nsmap" int main()
{
WebService1SoapProxy service;
_tempuri__GetSum a;
_tempuri__GetSumResponse result;
//a.soap = soap_new();
a.a = ;
a.b = ;
//result.soap = soap_new(); if (service.GetSum(&a, &result) == SOAP_OK)
std::cout << "the num of 1 and 5 is " << result.GetSumResult << std::endl;
else
service.soap_stream_fault(std::cerr);
service.destroy(); getchar();
return ;
}
编译
如果遇到 stdsoap2.obj : error LNK2001: 无法解析的外部符号_namespaces
参考 http://blog.163.com/lyz_sea/blog/static/115586707201182432412677
在 stdsoap2.h,添加
#ifndef WITH_NONAMESPACES
#define WITH_NONAMESPACES
#endif
2. Develop a Web Service (Stand-Alone Server)
// File: currentTime.h
//gsoap ns service name: currentTime
//gsoap ns service namespace: urn:currentTime
//gsoap ns service location: http://www.yourdomain.com/currentTime.cgi
int ns__currentTime(time_t& response);
> soapcpp2 -i -S currentTime.h
// File: currentTime.cpp
#include "soapcurrentTimeService.h" // include the proxy declarations
#include "currentTime.nsmap" // include the XML namespace mappings
int main()
{
// create server and serve on CGI-based request:
currentTimeService server;
/*server.serve();
server.destroy();
*/ while (server.run() != SOAP_TCP_ERROR)
{
server.soap_stream_fault(std::cerr);
} return ;
} int currentTimeService::currentTime(time_t& response)
{
response = time();
return SOAP_OK;
}
Compile with currentTime.cpp soapC.cpp soapcurrentTimeService.cpp stdsoap2.cpp
run
然后可以由 wsdl 文件生成客户端头文件,and ...
3. C# 调用 gsoap 的 service
参考 http://blog.sina.com.cn/s/blog_4e7d38260100ade4.html
用 VS 自带的 wsdl.exe (在 C 盘的某个角落)
> wsdl.exe currentTime.wsdl
生成 currentTime.cs
将 currentTime.cs 放到 C# 的工程中,研究下代码结构,找到 currentTime 的初始化函数:
public picture() {
this.Url = "http://localhost:65432/picture.cgi"; // 改成你的地址
}
OK,可以用了。
4. 如果要发送 二进制数据,可先将其进行编码(暂时采用 base64 编码,实际场景中应采用更合适的编码算法),以 string 形式发送。接收端再进行相应解码。
C++ gsoap service 端,读取图片:
int pictureService::picture(struct picdata &picture)
{
char *pic = NULL;
unsigned int length = ; std::ifstream is("chicken.jpg", std::ios::binary);
if (is)
{
is.seekg(, is.beg);
is.seekg(, is.end);
length = is.tellg();
is.seekg(, is.beg); pic = new char[length]; if (pic == NULL)
return SOAP_ERR; is.read(pic, length);
is.close();
} picture.data = base64_encode((unsigned char*)pic, length); if (pic != NULL)
{
delete pic;
pic = NULL;
} return SOAP_OK;
}
C# 端,调用 webservice,获取一张图片,并保存:
picture pic = new picture();
picture1 pic1 = new picture1();
pictureResponse res = pic.Callpicture(pic1); string strData = res.picture.data;
byte[] bytes = Convert.FromBase64String(strData); FileStream fs = new FileStream("D:\\picture.jpg", FileMode.OpenOrCreate);
fs.Write(bytes, , bytes.Length);
fs.Close();
以上代码,有待优化。
webservice gsoap 小记的更多相关文章
- C++访问WebService gSoap方式
一. gSOAP访问WebService 1. 下载gSOAP gSOAP 2.7.17 版下载地址http://sourceforge.net/projects/g ...
- 转--webservice、socket、http 小记(一)
webservice.socket.http 小记(一) http://blog.csdn.net/m_123hj_520/article/details/9370723 2013-07-18 17: ...
- 使用GSoap开发WebService客户端与服务端
Gsoap 编译工具提供了一个SOAP/XML 关于C/C++ 语言的实现, 从而让C/C++语言开发web服务或客户端程序的工作变得轻松了很多. 用gsoap开发web service的大致思路 我 ...
- GSoap的使用(调用webservice接口)
由于本人写项目时使用到C++要调用C#写得后台服务器发布的webservice,因此抽出来了一点时间整理相关的知识如下 gSOAP是一个绑定SOAP/XML到C/C++语言的工具,使用它可以简单快速地 ...
- Linux下gsoap实现webservice功能
蓝字为关键字,等号=后面为关键字值. 一.介绍 我们用的webservice是根据gsoap编译工具来实现,gSOAP的编译器能够自动的将用户定义的本地化的C或C++数据类型转变为符合XML语法的数据 ...
- Qt+gsoap调用WebService
1. 前言 Qt本身给我们提供了调用WebService的解决方案qsoap,看了一下他的介绍,感觉实在是太弱了,而且又是个新出的东西,所以还是决定不用他.既然使用Qt,那当然是跨平台的解 ...
- gsoap创建webservice服务简单教程
版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] WebServicesoapgsoap 使用gsoap创建webservice服务 下载gsop 准备待导出的服务接口定义文件比 ...
- C++客户端通过gSOAP调用WebService
webService三要素: SOAP(Simple Object Access Protocol).WSDL(WebServicesDescriptionLanguage).UDDI(Univers ...
- 使用webService时,gsoap数据类型注意事项
今天在使用gsoap生成webservice客户端文件时,发现我的参数类型全被改了,比如string型变成了char*,原来有STL的地方也变没了,经过研究发现,原来和我生成的头文件时使用的参数有关, ...
随机推荐
- 【转】MEF程序设计指南二:Silverlight中使用CompositionInitializer宿主MEF
MEF可以在传统应用程序中使用(包括桌面的Winform.控制台程序和Web的ASP.NET),也可以在RIA的Silverlight中使用.在Silverlight中只是宿主的方式有所不同,实际上在 ...
- [freeCodeCamp] solution to JUGGLING ASYNC
Here's the official solution in case you want to compare notes: var http = require('http') var bl = ...
- [SoapUI] 设置最大等待时间,不断重复的去发送一个request,每次从response中获取一个status,直到这个status从一种状态变成另外一种状态
import com.eviware.soapui.support.GroovyUtils def groovyUtils = new GroovyUtils( context ) def holde ...
- 【附案例】UI交互设计不会做?设计大神带你开启动效灵感之路
随着网络技术的创新发展,如今UI交互设计应用越来越广泛,显然已经成为设计的主流及流行的必然趋势.UI界面交互设计中的动效包括移动,滑块,悬停效果,GIF动画等.UI界面交互设计为何越来越受到青睐?它有 ...
- pthread_once 和 pthread_key
http://blog.csdn.net/rickyguo/article/details/6259410 一次性初始化 有时候我们需要对一些posix变量只进行一次初始化,如线程键(我下面会讲到). ...
- 2018.10.15 loj#6010. 「网络流 24 题」数字梯形(费用流)
传送门 费用流经典题. 按照题目要求建边. 为了方便我将所有格子拆点,三种情况下容量分别为111,infinfinf,infinfinf,费用都为validi,jval_{id_{i,j}}valid ...
- 2018.08.06 bzoj1503: [NOI2004]郁闷的出纳员(非旋treap)
传送门 平衡树简单题. 直接用fhgtreap实现分裂和合并就没了. 代码: #include<bits/stdc++.h> #define N 100005 using namespac ...
- modelsim仿真中Altera库的用法
添加altera 库 实例: 把建立lpm_mux IP时生成的.v文件lpm_mux_ip.v和编写的测试脚本文件放在一起,在modelsim中建立工程,把下面两个文件添加到工程中 直接compil ...
- mysql中要根据某个逗号分割的字符串关联查询另一张表的数据
首先观察下面的查询 select * from company where f_id in ('210','205','208') select * from company where f_id i ...
- Go语言的传参和传引用[转]
目录[-] 传参和传引用的问题 传slice不是传引用! 什么叫传引用? 为什么传slice不是传引用? 为什么很多人误以为slice是传引用呢? 传指针和传引用是等价的吗? 所有类型的函数参数都是传 ...