1. gsoap的好处就不用说了:百度百科

2. gsoap的下载地址:项目地址,目前我使用的是2.8.15版本

3. 开发环境:Ubuntu13.10

4. 具体操作步骤(以简单相加为例):

  1)编写add.h(头文件)

//gsoap ns service name: calc
//gsoap ns service protocol: SOAP
//gsoap ns service style: rpc
//gsoap ns service encoding: encoded
//gsoap ns service namespace: http://localhost:8888
//gsoap ns service location: http://localhost:8888
//gsoap ns service port: http://localhost:8888 int ns__add( int num1, int num2, int* sum );

  2)编写addserver.cpp(服务器)

#include "soapcalcService.h"                    /* 与add.h中第一行ns有关 */
#include "calc.nsmap" /* 与add.h中第一行ns有关 */ int main(int argc, char **argv)
{ calcService calc; /* 创建calc对象 */
if (argc < )
calc.serve(); /* serve as CGI application */
else
{ int port = atoi(argv[]);
if (!port)
{ fprintf(stderr, "Usage: server <port>\n");
exit();
}
/* run iterative server on port until fatal error */
if (calc.run(port)) /* 运行在port端口上 */
{ calc.soap_stream_fault(std::cerr);
exit(-);
}
}
return ;
} int calcService::add(int a, int b, int *result) /* 在此处实现add() */
{ *result = a + b;
return SOAP_OK;
}

  3)编写addclient.cpp(客户端)

#include "soapcalcProxy.h"                      /* 与add.h第一行的ns有关 */
#include "calc.nsmap" /* 与add.h第一行的ns有关 */
#include <stdio.h>
#include <stdlib.h>
const char server[] = "127.0.0.1:4567"; int main(int argc, char **argv)
{ if (argc < )
{ fprintf(stderr, "Usage: client num1 num2\n");
exit();
}
int a, b, result;
a = (int)(strtod(argv[], NULL)); /* str转double再转int */
b = (int)(strtod(argv[], NULL));
calcProxy calc; /* 创建calc对象 */
calc.soap_endpoint = server; /* 设定server */
calc.add(a, b, &result); /* 执行add() */
if (calc.error)
calc.soap_stream_fault(std::cerr);
else
printf("result = %d\n", result); /* 打印消息 */
return ;
}

  4)编写Makefile文件

# this is a Makefile to build client and server
# please setting the GSOAP_ROOT first.
# build procedure(EXAMPLE): server run on pc, then client run on arm
# step1: setting GSOAP_ROOT
# step2: setting OBJ_NS   # the first line in add.h
# step3: setting OBJ_NAME  # the basename of filename of add.h
# step4: setting CC and CXX
# step4: make OBJ_NS := calc
OBJ_NAME := add
GSOAP_ROOT := /home/scue/work/gsoap_2.8.15/gsoap
INCLUDE := -I$(GSOAP_ROOT) CC := clang++
GCC := clang++
#CC := arm-linux-g++
#CXX := arm-linux-g++ CFLAGS += -w
CXXFLAGS += -w OBJ_SERVER := soapC.o stdsoap2.o soap$(OBJ_NS)Service.o $(OBJ_NAME)server.o
OBJ_CLIENT := soapC.o stdsoap2.o soap$(OBJ_NS)Proxy.o $(OBJ_NAME)client.o all:
@make soap
@make server
@make client server: $(OBJ_SERVER)
$(CXX) $(CXXFLAGS) $(INCLUDE) $^ -o $@
client: $(OBJ_CLIENT)
$(CXX) $(CXXFLAGS) $(INCLUDE) $^ -o $@ .PHONY:soap
soap:
@cp -v $(GSOAP_ROOT)/stdsoap2.* .
@$(GSOAP_ROOT)/bin/linux386/soapcpp2 -i $(OBJ_NAME).h soapqt:
@mkdir -p $(OBJ_NS)qtclient
@cp -v soapH.h soapStub.h stdsoap2.h soap$(OBJ_NS)Proxy.h \
soapC.cpp stdsoap2.cpp soap$(OBJ_NS)Proxy.cpp $(OBJ_NS).nsmap \
$(OBJ_NS)qtclient/ # -c 生成C的文件
# -i 生成C++的文件 .PHONY:clean
clean:
rm -f server client *.o
distclean:
rm -f server client *.o ns* soap* *.xml *.nsmap *.wsdl stdsoap2.*

  5)编译及试验

make
./server
./client #将会返回5,也可以直接在浏览器中输入http://localhost:4567进行验证

总结:使用C++编写将会轻松很多。

最新文章

  1. python 杂七杂八 :
  2. linux常用命令-文件搜索命令-locate,which,whereis,grep
  3. [IOS] 利用@IBInspectable
  4. Python中的range函数用法
  5. 查看mysql语句运行时间
  6. Linux内核补丁升级
  7. ListView Web 服务器控件概述(MSDN)
  8. js调用本地 exe
  9. 【网络流#3】hdu 1532 - Dinic模板题
  10. prepareCall()运行存储过程
  11. GUI &amp; Event例子
  12. 网站静态化处理—web前端优化—下【终篇】(13)
  13. Asp.Net Core轻量级Aop解决方案:AspectCore
  14. python 将文件夹内的图片转换成PDF
  15. react 入坑笔记(一)
  16. 强大的图片展示插件,JQuery图片预览展示插件
  17. django之环境变量配置
  18. linux命令新建文件
  19. Winform文件夹图片批量压缩整理修改
  20. goaccess nginx日志分析工具简单使用

热门文章

  1. Iptables 指南 1.1.19
  2. cocos2d0基础篇笔记一
  3. 系统字体的Regular、Light等几种名称的区别
  4. mybatis配置文件,注意标签配置顺序。否则报错The content of element type &quot;configuration&quot; must match &quot;(properties?,settings?,...怎么解决
  5. python接口自动化6-重定向(Location)
  6. 在JSP中应用JavaBean
  7. Objective-C:异常的处理
  8. iOS开发-多线程简介
  9. 【Dagger2】 案例大全
  10. 检测设备平台,操作系统,方向 Javascript 库:Device.js