小白一步一个脚印,手把手,教你安装使用gsoap

安装

去官网拿到gsoap安装包。作者使用的gsoap_2.8.10.zip。

unzip gsoap_2.8.10.zip --解压安装包。

./configure --检查安装环境。 如果失败(出现error的),根据错误提示,安装相关的包。如果安装了openssl,还提示找不到-lssl,用root安装yum install openssl-devel(如遇其它,参考这篇博客http://blog.csdn.net/learnhard/article/details/5154262

make --编译。

make install --安装。

记得多看看README NOTE INSTALL这些文件,别因为懒就不看。

安装成功后会出现打印如下提示

+--------------------------------------------------------+
| You now have successfully built and installed gsoap. |
| |
| You can link your programs with -lgsoap++ for |
| C++ projects created with soapcpp2 and you can link |
| with -lgsoap for C projects generated with soapcpp2 -c |
| |
| There are also corresponding libraries for SSL and |
| zlib compression support (-lgsoapssl and lgsoapssl++) |
| which require linking -lssl -lcrypto -lz |
| |
| Thanks for using gsoap. |
| |
| http://sourceforge.net/projects/gsoap2 |
+--------------------------------------------------------+

使用

mkdir soap --新建一个目录soap。

wget http://www.genivia.com/calc.wsdl --拿到测试用的wsdl文档,当然如果你有自己的文档更好,一样的。

/usr/local/bin/wsdl2h -c -o calc.h calc.wsdl --用wsdl2h工具将wsdl文档编译成calc.h头文件。

/usr/local/bin/soapcpp2 -Lc calc.h --将calc.h文件编译成为编程需要的多个文件,比如实现文件,xml样板等。

编写main.c

#include "soapH.h" 
#include "calc.nsmap" 
main() 
{ 
   struct soap *soap = soap_new(); 
   double result; 
   if (soap_call_ns__add(soap, 1.0, 2.0, &result) == SOAP_OK) 
      printf("The sum of 1.0 and 2.0 is %lg\n", result); 
   else
      soap_print_fault(soap, stderr); 
   soap_end(soap); 
   soap_free(soap); 
}

gcc main.c soapC.c soapClient.c $(安装包路径)/gsoap-2.8/gsoap/stdsoap2.c

主要就是这个stdsoap2.c文件,如果编译的时候不包含它,那么会有很多函数找不到实现。

posted on 2012-09-17 19:12  jogger  阅读(723)  评论(0编辑  收藏  举报

导航