Linux下C++ gsoap服务器的搭建

参照这篇文章 http://www.cnblogs.com/cy163/archive/2013/03/29/2989757.html进行修改

1.创建自己的文件夹:mkdir airServer

2.创建自己的.cpp和.h文件:airServer.cpp,airServer.h

3.编写自己的airServer.h

//gsoap ns service name: airServer  
//gsoap ns service style: rpc  
//gsoap ns service namespace: http://服务器ip地址:端口/airServer.wsdl  
//gsoap ns service location: http://服务器ip:端口  
//gsoap ns service encoding: encoded
//gsoap ns schema namespace: urn:airServer
//下面是自己要定义的接口。可根据自己的项目编写

4.在airServer文件夹新建soap文件夹,cd soap 

根据自己编写的airServer.h生成必要的文件:/usr/local/gSoap/bin/soapcpp2 -i ../airServer/airServer.h -I /usr/local/gSoap/include/

将编译好的gSoap中的stdsoap2.h和stdsoap2.cpp拷贝到当前airServer工程目录的下的soap目录中


5.编写自己的服务器代码:airServer.cpp,

#include "soap/soapcalcService.h"改为
#include "soap/soapairServerService.h"

6.修改makefile、sources.mk、subdir.mk、soap/subdir.mk、objects.mk

根据自己的工程,将代码中的相关项改成自己的,在编译目标时加入
-DWITH_NONAMESPACES
否则会出现undefined reference to namespaces
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个基于gsoap2.8实现IPv6设备搜索的C++代码示例: 服务端代码: ```c++ #include "soapH.h" #include "DeviceService.nsmap" #include <stdio.h> int main(int argc, char **argv) { struct soap soap; soap_init(&soap); if (soap_bind(&soap, "::1", 8080, 100) < 0) // 在IPv6下绑定地址 { soap_print_fault(&soap, stderr); exit(-1); } printf("DeviceService ready at %s\n", soap.wsdd); while (true) { if (soap_serve(&soap) != SOAP_OK) { soap_print_fault(&soap, stderr); exit(-1); } soap_destroy(&soap); soap_end(&soap); } soap_done(&soap); return 0; } int DeviceService__GetDeviceInfo(struct soap *soap, char *deviceID, char *deviceInfo) { sprintf(deviceInfo, "Device ID: %s", deviceID); return SOAP_OK; } ``` 客户端代码: ```c++ #include "soapH.h" #include "DeviceService.nsmap" #include <stdio.h> int main(int argc, char **argv) { struct soap soap; soap_init(&soap); soap_set_namespaces(&soap, namespaces); // 初始化命名空间 soap_set_mode(&soap, SOAP_C_UTFSTRING); // 设置通信方式为UTF-8字符串 DeviceServiceBindingProxy proxy; proxy.soap_endpoint = "http://[::1]:8080"; // 创建设备搜索请求消息 _tds__GetDeviceInformation request; _tds__GetDeviceInformationResponse response; if (proxy.GetDeviceInformation(&request, &response) == SOAP_OK) // 发送设备搜索请求 { printf("Device information: %s\n", response.DeviceInformation); } else { soap_print_fault(&soap, stderr); } soap_destroy(&soap); soap_end(&soap); soap_done(&soap); return 0; } ``` 需要注意的是,服务端代码需要实现`DeviceService__GetDeviceInfo`函数,该函数用于返回设备信息。客户端代码中的请求消息和响应消息需要根据实际情况进行修改。此外,客户端代码中的SOAP_ENDPOINT需要修改为服务端的IPv6地址和端口号。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值