In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
16:42:58 on June 11, 2017
In the past few days, we have made a power selling interface (under the windows platform), including webservice service (C #), webservice dynamic library, client dll (C++), and client gsoap proxy. The software structure is as follows:
ClientDLL (client machine)-> gsoapProxy (client machine)-> webservice (server)-- > webserviceDLL (server)-> HSM (encryption machine)
[emphasize the premise that the webservice service is a web project created with vs2010, while client is written by Cmax Candle +. Here we mainly introduce how to use gsoap to proxy client requests]
Because the client and server are not on the same machine, it is no longer possible to use direct dynamic calls to dll. In order to connect the server through the network and transfer the function parameters to the corresponding function interface of webservice, it is necessary to use some tool to convert the function parameters to the network format and transfer them to server,gsoap. Gsoap can proxy not only the client request, but also the server side (this time it is only used as the client proxy). Although it has been as simple and easy to use as possible, I have searched a lot of articles on the Internet, all of which are taught until the files are generated, but how to use the generated files is not very clear. So I will record the whole process of use for reference in the future.
(1) download the gsoap software, search it on the Internet, go to the official directory, and then decompress it. Be sure to see whether the decompression is complete. There are three files stdsoap2.h, stdsoap2.cpp and stdsoap2.c in the root directory, which will be used later. (my computer seemed to crash during the decompression, but I didn't notice it, and then I didn't decompress it, so I searched for the stdsoap2 file for a long time.)
(2) generate intermediate files
Find two wsdl2h.exe soapcpp2.exe files in the unzipped directory.
2.1 first generate the intermediate header file, the function is to generate the interface exposed by your server in the form of a function in network format. Open a command line window and go to the gsoap directory: [the C++ method I use]
Wsdl2h-s-o test.h http://xxxxx:xxxx/xxx.wsdl
Common options for wsdl2h
-o file name, specify the output header file
The-n name space prefix replaces the default ns
-c produces pure C code, otherwise it is C++ code
-s do not use STL code
-t file name, specify typemap file, default is typemap.dat
-e prohibit namespace prefixes for enum members
The following * * .wsdl is the description of the server interface. How do you find it? As far as my project is concerned, it goes like this:
My webservice is written in c #, directly use the web project created by vs2010, [run the project], you will start a web service, pop up a browser to open a page, click "* .asmx", you will see all the web interfaces, and then there is a link with the word "View description" on the page. Click on it to enter the "*. Wsdl", yes, that's it.
2.2 produce other files based on header files
Soapcpp2-j test.h
Common options for soapcpp2
-C generates only client code
-S generates only server-side code
-L do not generate soapClientLib.c and soapServerLib.c files
-c produces pure C code, otherwise it is C++ code (related to header files)
-I specify the import path (see above)
-x do not generate XML sample files
-I generate C++ wrapper with xxxxProxy.h (.cpp) on the client and xxxxService.h (.cpp) on the server.
-j is similar to-I, except that the generated proxy class does not inherit from soap struct, but contains a pointer to soap. Proxy classes generated in this way are easy to communicate with each other.
The following files will be generated
The stub file of soapStub.h// soap, which defines the corresponding remote call model in test.h.
SoapC.csoapH.h / / soap sequence and anti-sequence code, which already contains soapStub.h, both server-side and client-side should include it
SoapClient.csoapClientLib.c / C client code, and the soapClientLib.c file simply contains soapClient.c and soapC.c
SoapServer.csoapServerLib.c / C server-side code, soapServerLib.c file simply contains soapServer.c and soapC.c
ServiceSoap.nsmapServiceSoap12.nsmap / / namespace definition, which should be included on both the server side and the client side
Simple wrapper for C++ of soapServiceSoapProxy.hsoapServiceSoap12Proxy.h / / client (if the header file is pure C code, these two files will not be generated)
To sum up
If you write server-side C mode, the files you need are: soapStub.h, soapC.cpp soapH.h soapServer.c soapServerLib.c ServiceSoap.nsmap ServiceSoap12.nsmap soapServiceSoapProxy.h soapServiceSoap12Proxy.h
If you write C++ on the client side, the file you need is: soapStub.h soapC.cpp soapH.h soapXXXXSoapProxy.cpp soapXXXXSoapProxy.h soapXXXXSoapService.cpp soapXXXXSoapService.h XXXXSoap.nsmap
Of course, you should also add the stdsoap2.cpp file in the gsoap library (if you are writing C code, add stdsoap2.c) [in the gsoap root directory, different versions of gsoap correspond to different files and cannot be mixed]
Test.h is useless here.
If you see the soapcpp2 prompt: "Criticalerror: # import: Cannot open file" stlvector.h "forreading.", it is because our header file uses STL (wsdl2h does not use the-s option), then use the-I option to specify the import file path of gSOAP, which is "$gsoap\ gsoap\ import":
Soapcpp2-j test.h-I D:\ gsoap-2.7\ gsoap\ import
(3) create an agent, convert input and output parameters, and receive the return value
Gsoap will convert the name of your server interface and divide it into request and response class (I use C++, which feels easier to use).
For example, the server interface is int EncryptPurse (char* cardNum, char* fileMoney, char* dataOut)
Gsoap converts the interface to:
_ ns1__EncryptPurse [request class, pass input parameters]
_ ns1__EncryptPurseResponse [response class, get output parameters and return values]
Create soap structures and gsoap proxies:
Struct soap soap
HSM_USCOREEPSaleSoapProxy soapProxy; / / type names will be different
Define the data transfer format for soap:
Soap_init (& soap); / / Initializes a runtime context
Soap_set_mode (& soap, SOAP_C_MBSTRING); / / sets the data mode
SoapProxy.HSM_USCOREEPSaleSoapProxy_init (SOAP_C_MBSTRING, SOAP_C_MBSTRING); / / initialize the data transfer mode
Then convert the parameters, and note that the input and output parameters are in two classes respectively:
_ ns1__EncryptPurse reqEncryptPurse; / / create a request class object
_ ns1__EncryptPurseResponse respEncryptPurse; / / create a response class object
ReqEncryptPurse.cardNum = IncardNo; / / IncardNo is the actual passed parameter
ReqEncryptPurse.fileMoney = InfileMoney; / / InfileMoney is the actual passed parameter
RespEncyptPurse.dataOut = Outdata;// Outdata is the parameter for receiving the output parameter
Next, call the API:
Int ret = soap.EncryptPurse ("http://localhost:1132/EPSaleWebService.asmx", NULL, & reqEncryptPurse, respEncryptPurse)
Receive return values and output parameters
Ret = respResponse.EncryptPurseResult; / / receive the return value of EncryptPurse
Strcpy (dataOut, respEncryptPurse.dataOut); / / receives the value of the output parameter
Close soap and clean the memory:
Soap_close & soap)
Soap_end & soap)
Soap_done & soap)
At this point, the request for a function interface and the corresponding is completed.
Problems encountered:
1. At the beginning of writing vc6 for gsoap projects, there was an error in the compilation Times: undefined types of sockaddr_storage
Due to the inconsistent version of winsock, there is no problem with changing it to vs2010 and then compiling it. If you have to compile in vc6, please continue Baidu, there should be other solutions.
2. Error LNK2001: unparsed external symbol _ namespaces
Project-Properties-configuration Properties-CumberCandlesMuir-pre-processor, add WITH_NONAMESPACES
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.