标签:vs2008 gsoap webservice win32
gSOAP下载地址http://sourceforge.net/projects/gsoap2/
我下载的版本是gsoap-2.8
3.1 通过wsdl生成访问接口3.2 解析WebService.h,生成存根程序
- 在目录D:\private\code\gsoap-2.8\gsoap\bin\win32下新建一个空的头文件WebService.h;
- 建立一个字符转换规则文件wsmap.dat,文件内容为xsd__string = | std::wstring | wchar_t*,那么SOAP/XML中的string将转换成std::wstrin或wchar_t*,这样能更好地支持中文;
- 启动cmd,进入到D:\private\code\gsoap-2.8\gsoap\bin\win32目录,调用wsdl2h.exe生成头文件接口定义,命令为:
wsdl2h -o WebService.h -N WS -n WS -R -t wsmap.dat http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?WSDL;
仍然是目录D:\private\code\gsoap-2.8\gsoap\bin\win32下,在命令行输入soapcpp2 -C WebService.h -I soapcpp2 -C WebService.h -i -I D:\private\code\gsoap-2.8\gsoap\import
成功后目录D:\private\code\gsoap-2.8\gsoap\bin\win32文件列表如下:
4. 建立win32工程
- 建立一个空的win32工程gsoapWeather;
- 将生成的soapC.cpp、soapClient.cpp、soapH.h、soapStub.h、soapWeatherWSSoapProxy.h、WeatherWSSoap.nsmap、stdsoap2.h和stdsoap2.cpp文件加入到工程;
- 添加一个cpp文件gsoapWeather.cpp,代码如下:
#include <iostream> #include <string> #include <xstring> // 名称空间映射表 #include "WeatherWSSoap.nsmap" #include "soapWeatherWSSoapProxy.h" using namespace std; int main(void) { WeatherWSSoapProxy weatherwebservice; // 获取近5天天气情况及城市信息 _WS__getWeather cityName; _WS__getWeatherResponse weatherResponse; wstring strAddress=L"广州"; cityName.theCityCode = const_cast<wchar_t*>(strAddress.c_str()); int result = weatherwebservice.getWeather(&cityName, weatherResponse); if(SOAP_OK == result) { vector<wstring> weatherString = weatherResponse.getWeatherResult->string; vector<wstring>::iterator itr; vector<wstring>::iterator itr_end; cout<<"近5天天气情况及城市信息:"<<endl; wcout.imbue(locale("chs")); cout<<weatherString.size()<<endl; for(itr = weatherString.begin(),itr_end = weatherString.end(); itr!=itr_end; ++itr) { wcout<<*itr<<endl; } cout<<endl; } system("pause"); return 0; }执行结果如下
标签:vs2008 gsoap webservice win32
原文地址:http://blog.csdn.net/jq_develop/article/details/41982337