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.c(服务器)

#include "soapH.h"
#include "calc.nsmap" /* 与add.h的第一行命名空间(ns)有关 */
#include <stdio.h>
#include <stdlib.h>
int
main (int argc, char *argv[])
{
int m, s;
struct soap add_soap;
soap_init (&add_soap);
if (argc < )
{
printf ("usage: %s <server_port> \n", argv[]);
exit ();
}
else
{
m = soap_bind (&add_soap, NULL, atoi (argv[]), );
if (m < )
{
soap_print_fault (&add_soap, stderr);
exit (-);
}
fprintf (stderr, "Socket connection successful: master socket = %d\n",m);
for (;;)
{
s = soap_accept (&add_soap);
if (s < )
{
soap_print_fault (&add_soap, stderr);
exit (-);
}
fprintf (stderr,
"Socket connection successful: slave socket = %d\n", s);
soap_serve (&add_soap); //该句说明该server的服务
soap_end (&add_soap);
}
}
return ;
} int
ns__add (struct soap *add_soap, int num1, int num2, int *sum)
{
*sum = num1 + num2;
return ;
}

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

#include "soapH.h"
#include "calc.nsmap" /* 与add.h的第一行命名空间(ns)有关 */
#include <stdio.h>
#include <stdlib.h> int add (const char *server, int num1, int num2, int *sum); int
main (int argc, char **argv)
{
int result = -;
char *server = "http://localhost:4567"; /* 定义server */
int num1 = ;
int num2 = ;
int sum = ;
if (argc < ) /* 判断传入参数 */
{
printf ("usage: %s num1 num2 \n", argv[]);
exit ();
}
num1 = atoi (argv[]);
num2 = atoi (argv[]);
result = add (server, num1, num2, &sum); /* 执行add() */
if (result != ) /* 输出result */
{
printf ("soap err,errcode = %d\n", result);
}
else
{
printf ("%d+%d=%d\n", num1, num2, sum);
}
return ;
} int
add (const char *server, int num1, int num2, int *sum)
{
struct soap add_soap; /* 创建add_soap()结构体 */
int result = ;
soap_init (&add_soap); /* soap_init()*/
soap_call_ns__add (&add_soap, server, "", num1, num2, sum); /* 调用soap_call_ns_add() */
if (add_soap.error)
{
printf ("soap error:%d,%s,%s\n", add_soap.error,
*soap_faultcode (&add_soap), *soap_faultstring (&add_soap));
result = add_soap.error;
}
soap_end (&add_soap); /* 释放内存空间 */
soap_done (&add_soap);
return result;
}

  4) 编写Makefile文件

# this is a Makefile to build client and server
# please setting the GSOAP_ROOT first.
# build procedure:
# step1: make soap
# step2: make all 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-gcc
#GCC := arm-linux-gcc OBJ_SERVER := soapC.o stdsoap2.o soapServer.o $(OBJ_NAME)server.o
OBJ_CLIENT := soapC.o stdsoap2.o soapClient.o $(OBJ_NAME)client.o all: server client server: $(OBJ_SERVER)
$(CC) $(INCLUDE) $^ -o $@
client: $(OBJ_CLIENT)
$(CC) $(INCLUDE) $^ -o $@ .PHONY:soap
soap:
@cp -v $(GSOAP_ROOT)/stdsoap2.* .
@$(GSOAP_ROOT)/bin/linux386/soapcpp2 -c $(OBJ_NAME).h
# -c 表示生成c文件 .PHONY:clean
clean:
rm -f server client *.o
distclean:
rm -f server client *.o ns* soap* *.xml *.nsmap *.wsdl stdsoap2.*

  5) 编译及验证

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

参考文章:

  1.http://blog.csdn.net/wesleyluo/article/details/5532633

〖Linux〗使用gsoap搭建web server(C)的更多相关文章

  1. 〖Linux〗使用gsoap搭建web server(C++)

    1. gsoap的好处就不用说了:百度百科 2. gsoap的下载地址:项目地址,目前我使用的是2.8.15版本 3. 开发环境:Ubuntu13.10 4. 具体操作步骤(以简单相加为例): 1)编 ...

  2. express快速搭建web server

    安装express4.x npm install -g express npm install -g express-generator //express命令行工具在4.x分离出来了 express ...

  3. 从零开始的ESP8266探索(1)-使用Server功能搭建Web Server

    https://blog.csdn.net/Naisu_kun/article/details/80398667 文件系统 https://blog.csdn.net/solar_Lan/articl ...

  4. python搭建web server

    假设你急需一个简单的Web Server,但你又不想去下载并安装那些复杂的HTTP服务程序,比方:Apache,ISS等.那么, Python 可能帮助你.使用Python能够完毕一个简单的内建 HT ...

  5. Linux服务器上搭建web项目环境

    一.下载并安装jdk 去官网下载linux系统上jdk的安装包jdk-8u181-linux-x64.tar.gz,在Linux的/usr目录下新建文件夹java,可以使用命令:cd /usr    ...

  6. virtualbox搭建ubuntu server nginx+mysql+tomcat web服务器1 (未完待续)

    virtualbox搭建ubuntu server nginx+mysql+tomcat web服务器1 (未完待续) 第一次接触到 linux,不知道linux的确很强大,然后用virtualbox ...

  7. linux系统下搭建自己的web服务器

    之前在windows 2008 server上搭建了一个用于测试的web服务器,但是在打开网站的时候特别的慢,尤其是图片的加载都会失败,当时以为是路径的问题,但是在服务器上自己打开都特别慢,自己实在找 ...

  8. (总结)CentOS Linux搭建SVN Server配置详解

         PS:虽然在公司linux服务器上搭建过几次svn,但是时间长了,有些配置操作会忘掉,上网搜索的结果都不大满意,有幸在前几天看到一篇算是最满意的svn搭建文章,转载一下以备以后使用,原文地址 ...

  9. jexus asp.net Linux Web Server

    Jexus简介 Jexus web server for linux 是运行在Linux上的Web服务器.其安装和部署及其简单,直接支持Asp.net . 下载Jexus wget http://li ...

随机推荐

  1. blkblock 2工具

    http://blog.yufeng.info/archives/tag/blktrace

  2. shell中的括号(小括号,中括号,大括号)及单引号、 双引号,反引号(``)

    一.小括号,园括号() 1.单小括号 () ①命令组.括号中的命令将会新开一个子shell顺序执行,所以括号中的变量不能够被脚本余下的部分使用.括号中多个命令之间用分号隔开,最后一个命令可以没有分号, ...

  3. SSH深度历险(四) Maven初步学�

    这几天接触这个词,非常多遍了,仅仅是浅显的体会到它在GXPT中的优点,功能之强大,又通过网络查询了资料进一步的认识学习了,和大家分享. Maven是基于项目对象模型(POM),能够通过一小段描写叙述信 ...

  4. MVC如何避免控制器方法接收到的值不能被转换为参数类型

    假设控制器方法参数类型是int: public ActionResult GetSth(int id) { return Content(id.ToString()); } 而视图传递过来的是字符串: ...

  5. MVC实现文件下载

    □ 思路 点击一个链接,把该文件的Id传递给控制器方法,遍历文件夹所有文件,根据ID找到对应文件,并返回FileResult类型. 与文件相关的Model: namespace MvcApplicat ...

  6. A secure connection is requiered(such as ssl). More information at http://service.mail.qq.com/cgi-bin/help?id=28

    上面回答有问题,找到qq官方的文档了 http://service.exmail.qq.com/cgi-bin/help?id=28&no=1000585&subtype=1 如果您的 ...

  7. mybatis映射文件遇到的小问题

    mybatis的映射文件插入操作时: 如果对应的属性是String类型的,那么一定要做空串的判断. 比如注册的时候,如果需要向数据库中插入一条记录时,对应的字段没有给他赋值,这个String类型的值传 ...

  8. 支持5G-WiFi的安卓设备搜索不到5G信号解决方法

    安卓设备必须获得root权限,然后修改 /system/etc/wifi/nvram_net.txt 文件, 将ccode = CN 改为 ccode = ALL.保存并重启即可. 三星EK-GC11 ...

  9. retrofit okhttp RxJava bk Gson Lambda 综合示例【配置】

    项目地址:https://github.com/baiqiantao/retrofit2_okhttp3_RxJava_butterknife.git <uses-permission andr ...

  10. 基于jQuery的Cookie操作插件--简单而又没有兼容性问题!

    在网页客户端,我们经常会遇到读取或者设置cookie的情况,如果用纯生的js我们可能会遇到一些兼容性带来的麻烦,这里给大家介绍一个比较实用jquery操作cookie的插件,插件的源代码如下: 1 2 ...