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

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

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

在前面两篇博文中,我们建立了jee和vc++的webservice服务端程序。现在,我们开始通过gsoap完成webservice客户端vc++项目。

前两篇:

gsoap CXF2.7.5 ssh vc++ webservice应用实例(一)》;

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

创建一个win32控制台应用程序,项目名称为HelloWorldClient,在项目目录中建立一个文件夹hello。

还是使用在(二)中使用gsoap生成的文件,不同的是,这次我们使用soapHelloWorldSoapBindingProxy.cpp和soapHelloWorldSoapBindingProxy.h

而不使用soapHelloWorldSoapBindingService.cpp和soapHelloWorldSoapBindingService.h

把9个文件复制到hello文件夹中,如图

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

设置3个.cpp文件的属性为不使用预编译头。

HelloWorldClient.cpp代码如下


#include "stdafx.h"

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

int _tmain(int argc, _TCHAR* argv[])
{
	cout << "test client:" << endl;
	HelloWorldSoapBindingProxy *helloService = new HelloWorldSoapBindingProxy();
	helloService->soap_endpoint = "http://localhost:8080/CXFServerDemo/webServices/HelloWorld";
	ns1__sayHello request;
	ns1__sayHelloResponse response;
	request.name = "biboheart";
	if(helloService->sayHello(&request, &response) != SOAP_OK)
	{
		cout << "请求失败" << endl;
	}
	else
	{
		string message = response.return_;
		cout << "response:" << message << endl;
	}
	getchar();
	return 0;
}

注意:

“helloService->soap_endpoint = "http://localhost:8080/CXFServerDemo/webServices/HelloWorld";”

这行是设置服务端地址的,这里测试cxf建立的webservice服务端,服务端是发布在tomcat中。默认为8080端口。如果是请求(二)中用gsoap创建的服务,这里的端口就相应修改,因为2中我们设置的9001端口监听。像下面这样设置。

“helloService->soap_endpoint = "http://localhost:9001/CXFServerDemo/webServices/HelloWorld";”

如果服务端搭建在网络中的计算机中,那么“localhost”就换成相应的ip地址

编译项目。

因为这里设置的是请求8080,我们启动tomcat的CXFServerDemo项目服务。

运行客户端程序,结果如下图。

运行(二)中生编译的程序,把端口改成9001,运行客户端。运行结果相同。

还剩一个CXF客户端项目。就可以完成互相调用了。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值