最近有一个需求要在C++ 里面调用Java 的Web Service。具体的环境是 VS2008, XP sp3.
这两个东东一组合就悲催了。 本来基于微软自己的技术有两个可以选。
1 ATL Server, 悲催的微软啊, 从VS 2008 将ATL Server 从Visual Studio 中拿到了去所谓的开源了。从此在VS2008 里面选用 add web reference 也会出错的, sproxy.exe 也被拿掉了。 去下载了个 ATL Server 的源代码 也没有办法成功编译sproxy。 想想反正这个sproxy 生成的代码也会是一坨一坨的 template 代码。 咱不专业啊, 找其它的呗。
2,微软还有个Windows Web Services API 不过这个更搞, 只有在windows 7, window 2008 下用。 如果XP 下用还得发email 给微软问它讨, 这个你还得是啥大客户啥的, 一年至少几万美刀级别的。
幸好有啥, 开源。开源好啊, 找到个gSoap。 这个现在差不多也成了一个在c++下使用Web Service的事实标准了。 鉴于这个gSoap 的使用方法还得整理出来放到项目的wiki。 俺们就干脆用英语整理了,省的来两遍。
1, gSoap is an open source Web Service /XML binding for C/C++. It supports Windows and GCC operating system.
go to the official web site
http://sourceforge.net/projects/gsoap2
or goto download the http://sourceforge.net/projects/gsoap2/files/latest/download
Currently the stable version is 2.8.8
Of couse we can build the tools from scratch. There is VisualStudio2005 folder, under which the Readme is very importance.
2, We can just use the tools under gSoap to build the stub and proxy source code for us:
there are two tools under gSoap, ther are wsdl2h and soapcpp2.
1, wsdl2h -o service.h -n namespacename URL or file name
the generatd service.h file will be used in the next step.
2, soapcpp2 service.h -C -i -x -I F:\study_code\mfc\gsoap_2.8.8\gsoap-2.8\gsoap\import
-I sepecify the import folder under gSoap.
soapcpp2 will generate the proxy, soaph.h, soapc.c files.
3, how to use the generated files.
Normally, we just use the web service client.If we compile the client code, we need files
soaph.h
soapRSOWebserviceServiceSoapBindingProxy.h
soapStub.h
soapc.cpp
soapRSOWebserviceServiceSoapBindingProxy.cpp
and other two files : stdsoap2.h, stdsoap2.cpp ( they are under the gSoap folder)
The example code can be like:
#include "RSOWebserviceServiceSoapBinding.nsmap"
#include "soapRSOWebserviceServiceSoapBindingProxy.h"
const char endpoint[] = "http://localhost:8080/rso-ws-1.0.5/service";
int main(int argc, char **argv)
{
RSOWebserviceServiceSoapBindingProxy proxy(SOAP_XML_INDENT);
std::string landingPath = "c"; /* optional element of type xsd:string */
int customerId = 2; /* optional element of type xsd:int */
int clientId = 3; /* optional element of type xsd:int */
std::string groupExternalId = "groupExternalId"; /* optional element of type xsd:string */
std::string memberId = "memberId"; /* optional element of type xsd:string */
wstest1__getRSOToken wstest1__getRSOToken_;
wstest1__getRSOToken_.clientId = &clientId;
wstest1__getRSOToken_.customerId = &customerId;
wstest1__getRSOToken_.groupExternalId = &groupExternalId;
wstest1__getRSOToken_.landingPath = &landingPath;
wstest1__getRSOToken_.memberId = &memberId;
wstest1__getRSOTokenResponse wstest1__getRSOTokenResponse_;
proxy.getRSOToken(endpoint, NULL, &wstest1__getRSOToken_, &wstest1__getRSOTokenResponse_);
std::cout << *(wstest1__getRSOTokenResponse_.rsoToken) << std::endl;
std::cout << "successful" << std::endl;
}
分享到:
相关推荐
c++通过gsoap调用webservices实例
在VS2008中使用gsoap调用Web Service
本文档主要介绍C++如何使用gSoap调用java的webservice接口. 是一篇自己工作中使用写下的使用说明。 非常详细步骤,带有简单示例的详细说明文档。
C++使用gsoap调用webservice接口,无需积分,仅供参考,内置说明文档,欢迎下载。
C++做客户端,通过gSoap调用java发布的webservice,所调用的java方法返回的是自定义实体类,如果返回int,String等基本数据类型,这很容易实现;但这里函数返回的是List,Course,List甚至是Object,应该很有价值! ...
vc++ 开发环境调用 web service 的接口的转换工具
C++做客户端,通过gSoap调用webservice,所调用的webservice方法返回的是自定义实体类,如果返回int,String等基本数据类型,这很容易实现;但这里函数返回的是List,Course,List甚至是Object,应该很有价值!
在VS2010下,使用C/C++通过gsoap调用webservice接口。 包含使用文档,C和C++调用实例。
gSOAP 开发 Web Service 程序
系统地演示了Qt的大量特性,包括资源处理、多线程、调试支持、中文支持、参数传递、工具栏、状态栏、菜单、自定义信号和槽、居中窗口、操作友好性支持等,还集成了gSOAP,成功实现了同Java实现的CXF的Web Service的...
VC++使用gsoap调用webservice文件,包含使用说明和事例程序。
C++环境下使用gsoap开发WebService接口
C++Gsoap调用天气的一个代码,网上一大堆,但有些用不了
在linux下_利用gSoap开发Web_Service_CC++客户端-good.
VS2010使用c++、gSOAP调用WebService 图文教程 参考:http://blog.csdn.net/testcs_dn/article/details/51526051
Linux下用gSOAP开发Web Service服务端和客户端程序
C++ 通过gsoap生成WebServer 和WebClient 内附gsoap包和测试源码,内部附有gsoap包、简单的使用说明以及测试代码
gsoap 使用http get post调用web api接口
C++通过gSOAP开发WebService客户端
代码在Linux5.6 64下编译通过,代码中调用http://www.cs.fsu.edu/~engelen/calc.wsdl提供的WebService接口。文件中相应的文件由gSOAP工具生成,详细操作说明请看我的博客。