void MakePayment([IN] int qty, [OUT]int& errorCode, [OUT]string& message)
//gsoap ns service name: paymentssl //gsoap ns service style: rpc //gsoap ns service encoding: encoded //gsoap ns service namespace: urn:paymentssl //gsoap ns service location: http://localhost:9999 //gsoap ns service method-action: MakePayment urn:MakePayment typedef int xsd__int; typedef char* xsd__string; enum t__status // remote status: { STATE_OK, // ok STATE_FAIL // fail to process }; class t__result { public: enum t__status errCode; xsd__string message; }; int ns__MakePayment(xsd__int qty, t__result* result);
soapcpp2.exe -2 -i -e paymentservice.h
soap
structure. This structure is part of the gSOAP core kernel (gSOAP is based on C, on top of which, as usual, you can make a C ++ wrapper);paymentssl.wsdl
- WSDL service description;t.xsd
- types declared by us (in our case, our enum will go there);paymentssl.MakePayment.req.xml
and paymentssl.MakePayment.res.xml
are examples of SOAP messages (the Request and Reply parts) that the service should accept / issue;soappaymentsslProxy.cpp
and soappaymentsslProxy.h
- client proxy code;soappaymentsslService.cpp
and soappaymentsslService.h
- server-side code;paymentssl.nsmap
- constants used by the server and client when forming the SOAP header;soapC.cpp
and soapH.h
- code for parsing C messages;soapStub.h
is a header describing the classes used by the server and client.stdsoap2.cpp
and stdsoap2.h
.PaymentServiceImpl
class in which I plan to implement the service. paymentsslService::MakePayment(int qty, t__result *result)
PaymentServiceImpl
inherited from paymentsslService
and will overload this operation, so you have to declare it somewhere as a stub somewhere like this: // //implementation for generated code always return FAIL. //This method will be override in PaymentServiceImpl class // int paymentsslService::MakePayment(int qty, t__result *result) { return SOAP_ERR; }
SOAP_ERR
defined in stdsoap2.h
among others.MakePayment
function in the PaymentServiceImpl
class. // PaymentServiceImpl.h #pragma once #include "Autogenerated/soappaymentsslService.h" class PaymentServiceImpl : public paymentsslService { public: virtual int MakePayment(int qty, t__result *result); }; // PaymentServiceImpl.cpp #include "PaymentServiceImpl.h" #include "Autogenerated/paymentssl.nsmap" /*virtual*/ int PaymentServiceImpl::MakePayment(int qty, t__result *result) { this->mode = this->mode | SOAP_C_UTFSTRING; if(qty<0) { this->soap_senderfault("error!", "<error xmlns=\"http://tempuri.org/\">The input parameter must be positive</error>"); return SOAP_CLI_FAULT; } if(qty>100){ result->errCode = STATE_FAIL; char err[] = "error (2)!"; int len=strlen(err); result->message = reinterpret_cast<char*>(soap_malloc(this, len+1)); strcpy_s(result->message, len+1, err); result->message[len] = '\0'; } return SOAP_OK; }
#include "PaymentServiceImpl.h" int _tmain(int argc, _TCHAR* argv[]) { const int SERVICE_PORT = 9999; std::auto_ptr<PaymentServiceImpl> srv (new PaymentServiceImpl()); if (srv->run(SERVICE_PORT)) { srv->soap_stream_fault(std::cerr); exit(-1); } return 0; }
paymentssl.wsdl
. var proxy = new PaymentService.paymentsslPortTypeClient(); string msg; var errCode = proxy.MakePayment(out msg, 10);
<configuration> <system.serviceModel> <bindings> <customBinding> <binding name="paymentssl"> <textMessageEncoding messageVersion="Soap12" /> <httpTransport/> </binding> </customBinding> </bindings> <client> <endpoint address="http://localhost:9999" binding="customBinding" bindingConfiguration="paymentssl" contract="PaymentService.paymentsslPortType" name="paymentssl"/> </client> </system.serviceModel> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> </startup> </configuration>
Source: https://habr.com/ru/post/121853/
All Articles