mfc 请求java_在C++下使用gSoap 调用Java开发的Web Service

最近有一个需求要在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

or goto download thehttp://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 isVisualStudio2005 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 arewsdl2h 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;

}

分享到:

2012-04-19 10:52

浏览 5108

评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值