gSOAP calc服务端与客户端示例
1. Web服务定义描述头文件
- typedef double xsd__double;
- int ns__add(xsd__double a, xsd__double b, xsd__double &result);
- int ns__sub(xsd__double a, xsd__double b, xsd__double &result);
- int ns__sqrt(xsd__double a, xsd__double &result);
2. 生成服务端与客户端代码
soapcpp2 calc.h
3. 服务端工程 / 客户端工程对比
4. 服务端main.cpp
- #include "soapH.h"
- #include <math.h>
- int http_get(struct soap *soap)
- {
- FILE *fd = NULL;
- fd = fopen("ns.wsdl", "rb");
- if (!fd)
- {
- return ;
- }
- soap->http_content = "text/xml";
- soap_response(soap, SOAP_FILE);
- while(true)
- {
- size_t r = fread(soap->tmpbuf, , sizeof(soap->tmpbuf), fd);
- if (!r) break;
- if (soap_send_raw(soap, soap->tmpbuf, r)) break;
- }
- fclose(fd);
- soap_end_send(soap);
- return SOAP_OK;
- }
- int http_get1(struct soap *soap)
- {
- std::string fileName="ns.wsdl";
- FILE *fd = NULL;
- fd = fopen(fileName.c_str(), "rb");//openWSDLfiletocopy
- if(!fd)
- {
- return ; //return HTTP not found error
- }
- soap->http_content="text/xml"; //HTTP header with text/xml content
- soap_response(soap,SOAP_FILE);
- while (true)
- {
- size_t r=fread(soap->tmpbuf,,sizeof(soap->tmpbuf),fd);
- if(!r) break;
- if(soap_send_raw(soap,soap->tmpbuf,r)) break; //cannot send, but little we can do about that
- }
- fclose(fd);
- soap_end_send(soap);
- return SOAP_OK;
- }
- int main()
- {
- struct soap soap;
- int m, s;
- soap_init(&soap);
- soap.fget = http_get;
- m = soap_bind(&soap, NULL, , );
- if (m < )
- {
- soap_print_fault(&soap, stderr);
- exit(-);
- }
- fprintf(stderr, "Socket connection successful: master socket = %d\n", m);
- for (int i=; ; i++)
- {
- s = soap_accept(&soap); //接受请求
- if (s < )
- {
- soap_print_fault(&soap, stderr);
- break;
- }
- fprintf(stderr, "%d: accepted connection from IP=%d.%d.%d.%d socket=%d",
- i, (soap.ip >> )&0xFF, (soap.ip >> )&0xFF, (soap.ip >> )&0xFF, soap.ip&&0xFF, s); //打印出接受请求的详细信息
- if (soap_serve(&soap) != SOAP_OK) //处理请求
- soap_print_fault(&soap, stderr);
- fprintf(stderr, "request served\n");
- soap_destroy(&soap); //清理soap类实例
- soap_end(&soap); //清理soap相关的所有资源并关闭连接
- }
- soap_done(&soap);
- return soap_serve(soap_new());
- }
- int ns__add(struct soap *soap, double a, double b, double &result)
- {
- result = a + b;
- return SOAP_OK;
- }
- int ns__sub(struct soap *soap, double a, double b, double &result)
- {
- result = a - b;
- return SOAP_OK;
- }
- int ns__sqrt(struct soap *soap, double a, double &result)
- {
- if (a >= )
- {
- result = sqrt(a);
- return SOAP_OK;
- }
- else
- return soap_receiver_fault(soap, "Square root of negative number", "I can't only take the square root of a non-negative number");
- }
- SOAP_NMAC struct Namespace namespaces[] =
- {
- {"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/*/soap-envelope", NULL},
- {"SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", "http://www.w3.org/*/soap-encoding", NULL},
- {"xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", NULL},
- {"xsd", "http://www.w3.org/2001/XMLSchema", "http://www.w3.org/*/XMLSchema", NULL},
- {"ns", "http://tempuri.org/ns.xsd", NULL, NULL},
- {NULL, NULL, NULL, NULL}
- };
5. 客户端main.cpp
- #include "soapH.h"
- int main()
- {
- struct soap calc_soap;
- soap_init(&calc_soap);
- double result = -;
- /*
- soap_call_ns__add(
- struct soap *soap,
- const char *soap_endpoint,
- const char *soap_action,
- double a,
- double b,
- double &result)
- */
- //调用成功返回标准0
- int flag = soap_call_ns__add(&calc_soap, "http://localhost:9001", "", 1.0, 6.9, result);
- std::cout<<"result="<<result<<", flag="<<flag<<std::endl;
- flag = soap_call_ns__sqrt(&calc_soap, "http://localhost:9001", "", , result);
- std::cout<<"result="<<result<<", flag="<<flag<<std::endl;
- return ;
- };
- SOAP_NMAC struct Namespace namespaces[] =
- {
- {"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/*/soap-envelope", NULL},
- {"SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", "http://www.w3.org/*/soap-encoding", NULL},
- {"xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", NULL},
- {"xsd", "http://www.w3.org/2001/XMLSchema", "http://www.w3.org/*/XMLSchema", NULL},
- {"ns", "http://tempuri.org/ns.xsd", NULL, NULL},
- {NULL, NULL, NULL, NULL}
- };
6 服务端与客户端调试
gSOAP calc服务端与客户端示例的更多相关文章
- 【GoLang】golang HTTP GET/POST JSON的服务端、客户端示例,包含序列化、反序列化
服务端代码示例: package main import ( "encoding/json" "fmt" "io/ioutil" " ...
- Hessian服务端和客户端示例
一.服务端 1.创建web项目,建立客户端调用的hessian接口和实现类. 接口: package com.ymx.hessian.service; import com.ymx.hessian.s ...
- 简单的UDP服务端和客户端示例
UDP的理论不再多说,我这里直接给出一个关于UDP的HelloWorld程序,代码明了,希望对刚入门的学生有所帮助! 当然,实际上,在这块我也刚入门! 首先写服务端代码,服务端邦定本地的IP和端口来监 ...
- 基于Select模型的Windows TCP服务端和客户端程序示例
最近跟着刘远东老师的<C++百万并发网络通信引擎架构与实现(服务端.客户端.跨平台)>,Bilibili视频地址为C++百万并发网络通信引擎架构与实现(服务端.客户端.跨平台),重新复习下 ...
- 使用flask_socketio实现服务端向客户端定时推送
websocket连接是客户端与服务器之间永久的双向通信通道,直到某方断开连接. 双向通道意味着在连接时,服务端随时可以发送消息给客户端,反之亦然,这在一些需要即时通讯的场景比如多人聊天室非常重要. ...
- C# 编写WCF简单的服务端与客户端
http://www.wxzzz.com/1860.html Windows Communication Foundation(WCF)是由微软开发的一系列支持数据通信的应用程序框架,可以翻译为Win ...
- QUdpSocket-Qt使用Udp通讯实现服务端和客户端
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:QUdpSocket-Qt使用Udp通讯实现服务端和客户端 本文地址:https:// ...
- 采用MQTT协议实现android消息推送(2)MQTT服务端与客户端软件对比、android客户端示列表
1.服务端软件对比 https://github.com/mqtt/mqtt.github.io/wiki/servers 名称(点名进官网) 特性 简介 收费 支持的客户端语言 IBM MQ 完整的 ...
- 常量,字段,构造方法 调试 ms 源代码 一个C#二维码图片识别的Demo 近期ASP.NET问题汇总及对应的解决办法 c# chart控件柱状图,改变柱子宽度 使用C#创建Windows服务 C#服务端判断客户端socket是否已断开的方法 线程 线程池 Task .NET 单元测试的利剑——模拟框架Moq
常量,字段,构造方法 常量 1.什么是常量 常量是值从不变化的符号,在编译之前值就必须确定.编译后,常量值会保存到程序集元数据中.所以,常量必须是编译器识别的基元类型的常量,如:Boolean ...
随机推荐
- 精密MRAM芯片制造系统
MRAM是一种非常复杂的薄膜多层堆叠,由10多种不同材料和超过30层以上的薄膜与堆叠组成,部分薄膜层的厚度仅达数埃,比人类的发丝还要薄500000倍,相近于一颗原子的大小,如何控制这些薄膜层的厚度.沉 ...
- LintCode_175 翻转二叉树
题目 翻转一棵二叉树 您在真实的面试中是否遇到过这个题? Yes 样例 1 1 / \ / \ 2 3 => 3 2 / \ 4 4 和前序遍历代码很相似从叶子节点依次翻转递归到根节点C++代码 ...
- js关闭或者刷新页面后执行事件
onbeforeunload 使用方法 window.onbeforeunload=function(){ return ''; } 有返回值才能弹出显示,或者有需要执行的事件也行.
- 【机器学习PAI实战】—— 玩转人工智能之你最喜欢哪个男生?
摘要: 分类问题是生活中最常遇到的问题之一.普通人在做出选择之前,可能会犹豫不决,但对机器而言,则是唯一必选的问题.我们可以通过算法生成模型去帮助我们快速的做出选择,而且保证误差最小.充足的样本,合适 ...
- 【Leetcode 堆、快速选择、Top-K问题 BFPRT】数组中的第K个最大元素(215)
这道题很强大,引出了很多知识点 题目 在未排序的数组中找到第 k 个最大的元素.请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素. 示例 1: 输入: [3,2,1,5 ...
- SQLServer数据库(二)
数据库设计:就是将数据库中的数据库实体及这些数据库实体之间的关系,进行规划和结构化的过程. 项目开发过程: 需求分析 概要设计 详细设计 代码编写 运行测试 打包发行 数据库的系统分析基本步骤:收集信 ...
- 使用 Windows 10 WSL 搭建 ESP8266 编译环境并使用 VSCODE 编程(一)(2019-08-23)
目录 使用 Windows 10 WSL 搭建 ESP8266 编译环境并使用 VSCODE 编程 安装前准备 安装 ESP8266 工具链 下载 ESP8266 SDK 编译 花絮 使用 Windo ...
- Vagrant-安装教程及常见问题
http://ju.outofmemory.cn/entry/346215 前言: Vagrant是一个基于Ruby的工具,用于创建和部署虚拟化开发环境. 它的主要意义是让所有开发人员都使用和线上服务 ...
- Go语言开发教程
Go语言简述 兴起:2009年Gogle发布的第二款开源编程语言 特征: 语法简单:语法标准比较严格,适合开发人员短时间高效的服务端开发. 并发模型:Goroutine是Go最显著的特征,使用类协程的 ...
- Java8 日期、时间操作
一.简介 在Java8之前,日期时间API一直被开发者诟病,包括:java.util.Date是可变类型,SimpleDateFormat非线程安全等问题.故此,Java8引入了一套全新的日期时间处理 ...