源码下载地址: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客户端项目。