当前位置:网站首页>GSOAP example - calc
GSOAP example - calc
2022-06-29 09:59:00 【Water like ice】
One 、readme
Simple calculator service implements:
- add(a,b)
- sub(a,b)
- mul(a,b)
- div(a,b)
- pow(a,b)
Compilation in C (see samples/calc):
soapcpp2 -c calc.h
cc -o calcclient calcclient.c stdsoap2.c soapC.c soapClient.c
cc -o calcserver calcserver.c stdsoap2.c soapC.c soapServer.c
Two 、calc.h
int ns__add(double a, double b, double *result);
//gsoap ns service method: sub Subtracts two values
int ns__sub(double a, double b, double *result);
//gsoap ns service method: mul Multiplies two values
int ns__mul(double a, double b, double *result);
//gsoap ns service method: div Divides two values
int ns__div(double a, double b, double *result);
//gsoap ns service method: pow Raises a to b
int ns__pow(double a, double b, double *result);
3、 ... and 、calcclient.c and calcserver.c
1.calcclient.c
/*
calcclient.c
Example calculator service client in C
Compilation in C (see samples/calc/calc.h):
$ soapcpp2 -c calc.h
$ cc -o calcclient calcclient.c stdsoap2.c soapC.c soapClient.c
where stdsoap2.c is in the 'gsoap' directory, or use libgsoap:
$ cc -o calcclient calcclient.c soapC.c soapClient.c -lgsoap
--------------------------------------------------------------------------------
gSOAP XML Web services tools
Copyright (C) 2001-2008, Robert van Engelen, Genivia, Inc. All Rights Reserved.
This software is released under one of the following two licenses:
Genivia's license for commercial use.
--------------------------------------------------------------------------------
Product and source code licensed by Genivia, Inc., [email protected]
--------------------------------------------------------------------------------
*/
#include "soapH.h"
#include "calc.nsmap"
const char server[] = "http://websrv.cs.fsu.edu/~engelen/calcserver.cgi";
/* = "http://localhost:8080"; to test against samples/webserver */
int main(int argc, char **argv)
{ struct soap soap;
double a, b, result;
if (argc < 4)
{ fprintf(stderr, "Usage: [add|sub|mul|div|pow] num num\n");
exit(0);
}
soap_init1(&soap, SOAP_XML_INDENT);
a = strtod(argv[2], NULL);
b = strtod(argv[3], NULL);
switch (*argv[1])
{ case 'a':
soap_call_ns__add(&soap, server, "", a, b, &result);
break;
case 's':
soap_call_ns__sub(&soap, server, "", a, b, &result);
break;
case 'm':
soap_call_ns__mul(&soap, server, "", a, b, &result);
break;
case 'd':
soap_call_ns__div(&soap, server, "", a, b, &result);
break;
case 'p':
soap_call_ns__pow(&soap, server, "", a, b, &result);
break;
default:
fprintf(stderr, "Unknown command\n");
exit(0);
}
if (soap.error)
soap_print_fault(&soap, stderr);
else
printf("result = %g\n", result);
soap_destroy(&soap);
soap_end(&soap);
soap_done(&soap);
return 0;
}
2.calcserver.c
/*
calcserver.c
......
*/
#include "soapH.h"
#include "calc.nsmap"
int main(int argc, char **argv)
{ SOAP_SOCKET m, s; /* sockets */
struct soap soap;
soap_init(&soap);
if (argc < 2)
soap_serve(&soap); /* serve as CGI application */
else
{ m = soap_bind(&soap, NULL, atoi(argv[1]), 100);
if (!soap_valid_socket(m))
{ soap_print_fault(&soap, stderr);
exit(1);
}
fprintf(stderr, "Socket connection successful: master socket = %d\n", m);
for ( ; ; )
{ s = soap_accept(&soap);
fprintf(stderr, "Socket connection successful: slave socket = %d\n", s);
if (!soap_valid_socket(s))
{ soap_print_fault(&soap, stderr);
exit(1);
}
soap_serve(&soap);
soap_end(&soap);
}
}
return 0;
}
int ns__add(struct soap *soap, double a, double b, double *result)
{ (void)soap;
*result = a + b;
return SOAP_OK;
}
int ns__sub(struct soap *soap, double a, double b, double *result)
{ (void)soap;
*result = a - b;
return SOAP_OK;
}
int ns__mul(struct soap *soap, double a, double b, double *result)
{ (void)soap;
*result = a * b;
return SOAP_OK;
}
int ns__div(struct soap *soap, double a, double b, double *result)
{ if (b)
*result = a / b;
else
{ char *s = (char*)soap_malloc(soap, 1024);
(SOAP_SNPRINTF(s, 1024, 100),
"<error xmlns=\"http://tempuri.org/\">Can't divide %f by %f</error>",
a, b);
return soap_sender_fault(soap, "Division by zero", s);
}
return SOAP_OK;
}
int ns__pow(struct soap *soap, double a, double b, double *result)
{ *result = pow(a, b);
if (soap_errno == EDOM) /* soap_errno is like errno, but compatible with Win32 */
{ char *s = (char*)soap_malloc(soap, 1024);
(SOAP_SNPRINTF(s, 1024, 100),
"<error xmlns=\"http://tempuri.org/\">Can't raise %f to %f</error>",
a, b);
return soap_sender_fault(soap, "Power function domain error", s);
}
return SOAP_OK;
}
Four 、 Use and summarize
4.1、 step
1、 Run on the server first :
./calcserver
2、 Run on client
./calcclient add 1 2
3、 Results output :
result = 3
4.2、 summary
- client The first few parameters can be passed in by the end program server End
- client End program wants to bring from server The parameters must be placed in the last one Parameters ,gsoap Stipulated
- server The end program is implemented according to its own requirements , But remember to add the first parameter
fun(struct soap *soap,x,y)
边栏推荐
- mysql修改自动递增初始值
- IPC(进程间通信)之管道详解
- 1424. diagonal traversal II
- KiCad学习笔记--快捷键
- Gross Tumor Volume Segmentation for Head and Neck Cancer Radiotherapy using Deep Dense Multi-modalit
- Slider validation code
- 自定义mvc框架实现
- Introduction to Chang'an chain data storage and construction of MySQL storage environment
- CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION
- es报错NoNodeAvailableException[None of the configured nodes are available:[.127.0.0.1}{127.0.0.1:9300]
猜你喜欢

Fully Automated Gross Tumor Volume Delineation From PET in Head and Neck Cancer Using Deep Learning

力扣85题最大矩形

Chang'an chain go language smart contract writing and compilation

Gross Tumor Volume Segmentation for Head and Neck Cancer Radiotherapy using Deep Dense Multi-modalit

自定义mvc框架实现

C语言实现一种创建易管理易维护线程的方法

Fully Automated Gross Tumor Volume Delineation From PET in Head and Neck Cancer Using Deep Learning

1424. 对角线遍历 II

Making of simple addition calculator based on pyqt5 and QT Designer

阿里云防火墙配置,多种设置方式(iptables和fireward)
随机推荐
阿里云服务器安装配置redis,无法远程访问
你必须知道的23个最有用的Elasticseaerch检索技巧
动态规划总结
Application of decorator mode, packaging ServletRequest and adding addparameter method
es报错NoNodeAvailableException[None of the configured nodes are available:[.127.0.0.1}{127.0.0.1:9300]
Wechat applet realizes store function
Zabbix4.4 configure the indicators of the monitoring server and solve the garbled graphics pages
2020-09-23左右值 右值引用 std::move()
How to set Google Chrome as the default browser
GCC and makefile
券商经理给的开户二维码办理股票开户安全吗?我想开个户
JS获取手机型号和系统版本
leetcode MYSQL数据库题目180
Chang'an chain go language smart contract writing and compilation
2020-09-25 boost库的noncopyable,用于单例模式
監控數據源連接池使用情况
2020-9-14 广告系统入门
转载 :判断对象是否具有属性的5种方法
C # judge whether the array contains any items of another array
c语言printf大家族系列