gsoap CXF2.7.5 ssh vc++ webservice应用实例(二)

5 篇文章 0 订阅
5 篇文章 0 订阅

源码下载地址:http://download.csdn.net/detail/biboheart/6314985

接上一篇《gsoap CXF2.7.5 ssh vc++ webservice应用实例(一)

在上篇中已经获得了HelloWorld.wsdl文件

现在开始用gsoap,vc++做webservice服务端。

我用的是gsoap2.8.16。

gsoap将wsdl文件生成服务端C++代码就不啰嗦了。网上很多。

生成后文件:

stdsoap2.cpp和stdsoap2.h是在gsoap压缩包中获得的。

我用的是vs2008。

建立一个win32控制台应用程序,项目名称:HelloWorldServer。

在项目中HelloWorldServer目录中建立一个hello文件夹;

在上面gsoap生成的文件中,soapHelloWorldSoapBindingProxy.cpp和soapHelloWorldSoapBindingProxy.h两个文件是做客户端的时候用的。现在暂时不使用,把其它的文件都复制到hello文件夹下。

把stdsoap2.h;stdsoap2.cpp;soapHelloWorldSoapBindinService.cpp;soapC.cpp;四个文件添加到项目中。

修改3个cpp文件属性,为不使用预编译头。如下图

HelloWorldServer.cpp文件


#include "stdafx.h"

#include "hello\soapHelloWorldSoapBindingService.h"
#include "hello\HelloWorldSoapBinding.nsmap"

int _tmain(int argc, _TCHAR* argv[])
{
	cout << "test server:" << endl;
	HelloWorldSoapBindingService* server = new HelloWorldSoapBindingService();
	while(server->run(9001) != SOAP_TCP_ERROR);
	getchar();
	return 0;
}

int HelloWorldSoapBindingService::sayHello(ns1__sayHello *ns1__sayHello_, ns1__sayHelloResponse *ns1__sayHelloResponse_)
{
	char* responseMessage = new char[50];
	memset(responseMessage, 0, 50);
	strcpy_s(responseMessage, 6, "hello ");
	strcat_s(responseMessage, strlen(ns1__sayHello_->name) + 7, ns1__sayHello_->name);
	ns1__sayHelloResponse_->return_ = responseMessage;
	return SOAP_OK;
}

通过编译后,启动程序,在浏览器中访问http://localhost:9001

显示以上信息,表示webservice服务启动正常。

通过以上两篇博文,已经完成了jee和vc++的webservice服务。

接下去还有两个项目,是jee和vc++的webservice客户端项目。


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值