gSOAP 使用
1. wsdl2h 生成服务定义头文件
wsdl2h -o calc.h http://www.genivia.com/calc.wsdl
2. 从服务定义头文件calc.h生成客户端代码
soapcpp2 -C -IC:\Users\Administrator\Desktop\gsoap-2.8\gsoap\import calc.h
3. vc6.0项目结构
调用代码main.cpp:
1 #include "soapH.h" 2 #include "calc.nsmap" 3 4 5 int main() 6 { 7 struct soap soap; 8 double result = 0.0; 9 ns2__add nsadd; 10 11 soap_init(&soap); 12 13 const char *server_location = "http://websrv.cs.fsu.edu/~engelen/calcserver.cgi"; 14 nsadd.a = 1.0; 15 nsadd.b = 9.0; 16 17 if (soap_call_ns2__add(&soap, server_location, "", nsadd.a, nsadd.b, result) == SOAP_OK) 18 std::cout<<"Sum = " <<result << std::endl; 19 else 20 soap_print_fault(&soap, stderr); 21 22 soap_destroy(&soap); 23 soap_end(&soap); 24 soap_done(&soap); 25 26 return 0; 27 }
#################################
### 客户端调用使用代理类的方式
soapcpp2 -C -IC:\Users\Administrator\Desktop\gsoap-2.8\gsoap\import -i calc.h
calcProxy项目文件夹结构(头文件、源代码分开存放)
在Project ->Project Settings -> C/C++ ->Project Options 下添加 /I ".\\" /I ".\\include", 即把项目根目录和项目根目录下的include目录添加到编译器的搜索路径中了
vc++6.0项目结构:
调用文件main.cpp:
1 #include "soapcalcProxy.h" 2 #include "calc.nsmap" 3 4 int main() 5 { 6 calcProxy service; 7 8 double result; 9 10 if (service.add(1.0, 2.0, result) == SOAP_OK) 11 std::cout<<"Sum = "<<result<<std::endl; 12 else 13 service.soap_stream_fault(std::cerr); 14 15 service.destroy(); 16 17 return 0; 18 }