当前位置:网站首页>Win10 build webservice
Win10 build webservice
2022-06-24 07:37:00 【Hard working Lao Zhou】
Preface
Because the project needs to use WebService, It's my first time to use WebService, Belong to completely inexperienced . Thanks to the universal Ethernet . The following is about the first construction WebService The server side writes a simple summary .
Development environment construction
System environment
Win10 + gSoap 2.8.119
The server-side program currently uses VS2019.
gSoap install
download gSoap
gSoap Just download directly from the network , No local compilation is required , The download is a little slow . Download at :
https://sourceforge.net/projects/gsoap2/files/.
I chose the latest version , That is to say gSoap 2.8.119.
decompression
After downloading is a zip file , It can be extracted directly . I unzipped it in d:/gsoap Under the table of contents . The executables we need to use are 
Add a path
take D:\gsoap-2.8\gsoap\bin\win64 Add to system environment variables . Here's the picture .
such ,gSoap Just install it .
gSoap Introduction to important tools
wsdl2h
The main function of the tool is , adopt wsdl File generation C/C++ .h The header file .
socapcpp2
This tool is used to create files from scratch , Generate SOAP Server and client code , It also includes WSDL、 Test use XML data .
first Web Service Server side
When I first read the Internet materials , Need to build a wsdl file , Also download from the network , See yourself completely at a loss . Fortunately, you can find a data and set up a complete server by yourself .
Create a server folder
I am here d:\gsoap-2.8\gsoap. Here's the picture . Created a gServer Catalog .
This directory is anywhere .
Create a header file to provide services
We use one of the most common calculator functions to implement Web Service Server side , Provide some basic operations .
#ifndef __GSERVICE_H__
#define __GSERVICE_H__
//gsoap ns service name: gservice
//gsoap ns service style: rpc
int ns__add(double num1, double num2, double& result );
int ns__sub(double num1, double num2, double& result );
int ns__mult(double num1, double num2, double& result);
int ns__divid(double num1, double num2, double& result);
#endif
The current folder is as follows .
Generate wsdl file
Use the following command line ,
soapcpp2.exe -S gservice.h
To generate wsdl Wait for the documents . The complete recording process is as follows .
D:\gsoap-2.8\gsoap\gServer>soapcpp2.exe -S gservice.h
** The gSOAP code generator for C and C++, soapcpp2 release 2.8.119
** Copyright (C) 2000-2021, Robert van Engelen, Genivia Inc.
** All Rights Reserved. This product is provided "as is", without any warranty.
** The soapcpp2 tool and its generated software are released under the GPL.
** ----------------------------------------------------------------------------
** A commercial use license is available from Genivia Inc., [email protected]
** ----------------------------------------------------------------------------
Saving soapStub.h annotated copy of the source interface header file
Saving soapH.h serialization functions to #include in projects
Using ns service name: gservice
Using ns service style: rpc
Using ns service encoding: literal
Using ns schema namespace: http://tempuri.org/ns.xsd
Saving gservice.wsdl Web Service description
Saving gservice.add.req.xml sample SOAP/XML request
Saving gservice.add.res.xml sample SOAP/XML response
Saving gservice.sub.req.xml sample SOAP/XML request
Saving gservice.sub.res.xml sample SOAP/XML response
Saving gservice.mult.req.xml sample SOAP/XML request
Saving gservice.mult.res.xml sample SOAP/XML response
Saving gservice.divid.req.xml sample SOAP/XML request
Saving gservice.divid.res.xml sample SOAP/XML response
Saving gservice.nsmap namespace mapping table
Saving ns.xsd XML schema
Saving soapServer.cpp server request dispatcher
Saving soapServerLib.cpp server request dispatcher with serializers (use only for libs)
Saving soapC.cpp serialization functions
Compilation successful
such , We have generated what we need gservice.wsdl,gservice.nsmap. As shown in the figure below .
Use vs2019 Set up the service end project
I use the vs2019, stay D:\gsoap-2.8\gsoap\gServer A console application is generated under the directory .

And I'm gonna go ahead and create . The generated blank project is shown in the following figure .

Copy necessary files
take stdsoap2.h,stdsoap2.c,stdsoap2.cpp copy to gServer Under the table of contents , These three documents are gSoap Provided , stay D:\gsoap-2.8\gsoap Under the table of contents .
Add the necessary header file
And will stdsoap2.h、soapStub.h、soapH.h、gservice.nsmap and stdsoap2.cpp、soapC.cpp、soapServer.cpp File import to gServer in , The project directory structure is as follows .
modify gServer.cpp
increase soap Related codes
stay main() add soap service , Port, etc .
// gServer.cpp : This file contains "main" function . Program execution will start and end here .
//
#include <iostream>
#include "stdio.h"
#include "../soapH.h"
#include "../gservice.nsmap"
int main(int argc, char** argv)
{
int nPort = 8080;
struct soap fun_soap;
soap_init(&fun_soap);
int nMaster = (int)soap_bind(&fun_soap, NULL, nPort, 100);
if (nMaster < 0)
{
soap_print_fault(&fun_soap, stderr);
exit(-1);
}
fprintf(stderr, "Socket connection successful : master socket = %d\n", nMaster);
while (true)
{
int nSlave = (int)soap_accept(&fun_soap);
if (nSlave < 0)
{
soap_print_fault(&fun_soap, stderr);
exit(-1);
}
fprintf(stderr, "Socket connection successful : slave socket = %d\n", nSlave);
soap_serve(&fun_soap);
soap_end(&fun_soap);
}
return 0;
}
Interface related code
take gservice.h Defined function implementation .
/* The concrete realization of addition */
int ns__add(struct soap* soap, double num1, double num2, double& result)
{
result = num1 + num2;
printf("[add] num1 = %lf, num2 = %lf, result = %lf\n", num1, num2, result);
return SOAP_OK;
}
/* The concrete implementation of subtraction */
int ns__sub(struct soap* soap, double num1, double num2, double& result)
{
result = num1 - num2;
printf("[sub] num1 = %lf, num2 = %lf, result = %lf\n", num1, num2, result);
return SOAP_OK;
}
/* The concrete realization of multiplication */
int ns__mult(struct soap* soap, double num1, double num2, double& result)
{
result = num1 * num2;
printf("[mul] num1 = %lf, num2 = %lf, result = %lf\n", num1, num2, result);
return SOAP_OK;
}
/* The concrete implementation of division */
int ns__divid(struct soap* soap, double num1, double num2, double& result)
{
result = num1 / num2;
printf("[div] num1 = %lf, num2 = %lf, result = %lf\n", num1, num2, result);
return SOAP_OK;
return SOAP_OK;
}
Compile operation
The following interface will appear , Click on “ allow access to ” that will do .
such , Our first one Web Service The server program has been running .
Access test
We can open the browser , Input localhost:8080 To make sure Web Service Whether it starts normally . We will see the following display .
In this way, our server has been completed .
At the same time, we can also see the connection information .
first Web Service client
The client can send application query to the server .
Build directory
We use gClient Catalog .
Build project
Or use VS 2019 Build a console application . This time our name is gClient.

Copy service files
take gservice.h Copy to the corresponding directory .
Generate wsdl file
Note that you need to use parameters here C, Indicates that it is a client .
soapcpp2.exe -C gservice.h
D:\gsoap-2.8\gsoap\gClient>soapcpp2.exe -C gservice.h
** The gSOAP code generator for C and C++, soapcpp2 release 2.8.119
** Copyright (C) 2000-2021, Robert van Engelen, Genivia Inc.
** All Rights Reserved. This product is provided "as is", without any warranty.
** The soapcpp2 tool and its generated software are released under the GPL.
** ----------------------------------------------------------------------------
** A commercial use license is available from Genivia Inc., [email protected]
** ----------------------------------------------------------------------------
Saving soapStub.h annotated copy of the source interface header file
Saving soapH.h serialization functions to #include in projects
Using ns service name: gservice
Using ns service style: rpc
Using ns service encoding: literal
Using ns schema namespace: http://tempuri.org/ns.xsd
Saving gservice.wsdl Web Service description
Saving gservice.add.req.xml sample SOAP/XML request
Saving gservice.add.res.xml sample SOAP/XML response
Saving gservice.sub.req.xml sample SOAP/XML request
Saving gservice.sub.res.xml sample SOAP/XML response
Saving gservice.mult.req.xml sample SOAP/XML request
Saving gservice.mult.res.xml sample SOAP/XML response
Saving gservice.divid.req.xml sample SOAP/XML request
Saving gservice.divid.res.xml sample SOAP/XML response
Saving gservice.nsmap namespace mapping table
Saving ns.xsd XML schema
Saving soapClient.cpp client call stub functions
Saving soapClientLib.cpp client stubs with serializers (use only for libs)
Saving soapC.cpp serialization functions
Compilation successful
Add necessary files to the project
take stdsoap2.h、soapStub.h、soapH.h、gservice.nsmap and stdsoap2.cpp、soapC.cpp、soapClient.cpp File import to gClient in , The project directory structure is as follows

modify gClient.cpp
increase soap Code
#include <stdio.h>
#include "../soapH.h"
#include "../gservice.nsmap"
int main(int argc, char* argv[])
{
printf("The Client is runing...\n");
double num1 = 110;
double num2 = 11;
double result = 0;
struct soap* CalculateSoap = soap_new();
//soap_init(CalculateSoap);
char server_addr[] = "http://localhost:8080";
int iRet = soap_call_ns__add(CalculateSoap, server_addr, "", num1, num2, result);
if (iRet == SOAP_ERR)
{
printf("Error while calling the soap_call_ns__add");
}
else
{
printf("Calling the soap_call_ns__add success.\n");
printf("%lf + %lf = %lf\n", num1, num2, result);
}
iRet = soap_call_ns__sub(CalculateSoap, server_addr, "", num1, num2, result);
if (iRet == SOAP_ERR)
{
printf("Error while calling the soap_call_ns__sub");
}
else
{
printf("Calling the soap_call_ns__sub success.\n");
printf("%lf - %lf = %lf\n", num1, num2, result);
}
iRet = soap_call_ns__mult(CalculateSoap, server_addr, "", num1, num2, result);
if (iRet == SOAP_ERR)
{
printf("Error while calling the soap_call_ns__mult");
}
else
{
printf("Calling the soap_call_ns__mult success.\n");
printf("%lf * %lf = %lf\n", num1, num2, result);
}
iRet = soap_call_ns__divid(CalculateSoap, server_addr, "", num1, num2, result);
if (iRet == SOAP_ERR)
{
printf("Error while calling the soap_call_ns__divid");
}
else
{
printf("Calling the soap_call_ns__divid success.\n");
printf("%lf / %lf = %lf\n", num1, num2, result);
}
soap_end(CalculateSoap);
soap_done(CalculateSoap);
free(CalculateSoap);
return 0;
}
Compile operation

Pictured above , We passed through Web Service The related calculation is realized .
边栏推荐
- get_ started_ 3dsctf_ two thousand and sixteen
- [image fusion] image fusion based on directional discrete cosine transform and principal component analysis with matlab code
- MySQL case: analysis of full-text indexing
- A penetration test of c/s Architecture - Request encryption, decryption and test
- Leetcode probability interview shock series 11~15
- Group policy disables command prompt bypass
- 伦敦金的资金管理比其他都重要
- L2tp/ipsec one click installation script
- [equalizer] bit error rate performance comparison simulation of LS equalizer, def equalizer and LMMSE equalizer
- Win11 points how to divide disks? How to divide disks in win11 system?
猜你喜欢
![[vulhub shooting range]] ZABBIX SQL injection (cve-2016-10134) vulnerability recurrence](/img/c5/f548223666d7379a7d4aaed2953587.png)
[vulhub shooting range]] ZABBIX SQL injection (cve-2016-10134) vulnerability recurrence

【信号识别】基于深度学习CNN实现信号调制分类附matlab代码

两个链表的第一个公共节点_链表中环的入口(剑指offer)

Description of module data serial number positioning area code positioning refers to GBK code

阿里云全链路数据治理

【图像分割】基于形态学实现视网膜血管分割附matlab代码

The first common node of two linked lists_ The entry of the link in the linked list (Sword finger offer)
![[GUET-CTF2019]zips](/img/79/22ff5d4a3cdc3fa9e0957ccc9bad4b.png)
[GUET-CTF2019]zips

20 not to be missed ES6 tips

Win11分磁盘怎么分?Win11系统怎么分磁盘?
随机推荐
L2tp/ipsec one click installation script
PCL 点云按比率随机采样
[cnpm] tutorial
阿里云全链路数据治理
[WordPress website] 6 Article content copy prevention
Huawei experimental topology set, learning methods are attached at the end of the article!
[WUSTCTF2020]alison_likes_jojo
[understanding of opportunity -29]: Guiguzi - internal dialogue - five levels of communication with superiors
How to select a third-party software testing company? 2022 ranking of domestic software testing institutions
[GUET-CTF2019]zips
How can genetic testing help patients fight disease?
[Proteus] Arduino uno + ds1307+lcd1602 time display
Win11 points how to divide disks? How to divide disks in win11 system?
Only two lines are displayed, and the excess part is displayed with Ellipsis
Spark stage and shuffle for daily data processing
Buuctf misc grab from the doll
Description of module data serial number positioning area code positioning refers to GBK code
Unexpected token u in JSON at position 0
Dichotomous special training
湖北专升本-湖师计科