gSOAP digital certificate for remote invocation

Source: Internet
Author: User
Tags soap wsdl

Sometimes gSOAP calls others to provide the interface, need authentication to go in.

1. First, the user name and password are required, which can be specified as follows:

struct SOAP Info_soap;
Soap_init (&INFO_SOAP);
Info_soap.userid = "Superadmin";
INFO_SOAP.PASSWD = "123456";


2. Need to download the corresponding certificate, you can download the digital certificate with Firefox, modify the name placed under the corresponding development directory for the call, and then in the program to indicate the name of the certificate, as follows:

Soap_ssl_client_context (&info_soap, 0, NULL, NULL, "/opt/create_user/sipxcert.pem", "/opt/create_user/", null);


Note: If you want to download the specified WSDL file, to copy the corresponding download link to the specified description document, replace the IP address of the corresponding server: Https://yourdomain:8443/sipxconfig/services/*service
When you open this URL, you will be prompted to issue the certificate, and then download the certificate on it.

Under Linux you can directly enter the command to download this wsdl:wget--no-check-certificate URL--http-user=superadmin--http-password=123456


Refer to the complete code below:
#include <iostream>
#include <string>

#include "Userservicesoapbinding.nsmap"
#include "SoapH.h"

int Sendwebserviceitem (
Const char* URL,
Const char* Superadminpin,
Const char* UserName
)
{
int res =-1;

struct SOAP Info_soap;
Soap_init (&AMP;INFO_SOAP);
Info_soap.userid = "Superadmin";
INFO_SOAP.PASSWD = "123456";
Info_soap.proxy_userid = "Superadmin";
INFO_SOAP.PROXY_PASSWD = "123456";
Info_soap.send_timeout = 3;
Info_soap.recv_timeout = 3;
Soap_set_mode (&info_soap, soap_c_utfstring);
#ifdef DEBUG
Soap_set_test_logfile (&info_soap, "TEST.log");
Soap_set_test_logfile (&info_soap, "RECV.log");
Soap_set_test_logfile (&info_soap, "SEND.log");
#endif

#ifdef _PROXY_IP
_soap.proxy_host = _proxy_ip;
#endif

#ifdef _proxy_port
_soap.proxy_port = _proxy_port;
#endif

Ns1__adduser Preq;
struct __ns1__adduserresponse pres;
Preq.pin = Superadminpin;
Preq.user = new Ns1__user;
if (Preq.user = NULL)
{
Std::cout << "Preq.user new memory Failed" << Std::endl;
Soap_print_fault (&info_soap, stderr);
#ifdef DEBUG
Soap_close_logfiles (&AMP;INFO_SOAP);
#endif
Soap_cleanup (&AMP;INFO_SOAP);
Soap_destroy (&AMP;INFO_SOAP);
Soap_end (&AMP;INFO_SOAP);
Soap_done (&AMP;INFO_SOAP);
return-1;
}
std::string strUserName = userName;
Preq.user->username = strUserName;

Soap_ssl_client_context (&info_soap, 0, NULL, NULL, "/opt/create_user/sipxcert.pem", "/opt/create_user/", null);
Info_soap.authrealm = Soap_authentication_digest;
res = Soap_call___ns1__adduser (&info_soap, URL, "", &preq, Pres);
if (res!= 0)
{
Std::cout << "Soap_call___ns1__adduser error:" << res << "Soap.error:" << info_soap.error &LT;&L T Std::endl;
#ifdef DEBUG
Soap_close_logfiles (&AMP;INFO_SOAP);
#endif
Delete Preq.user;
Preq.user = NULL;
Soap_cleanup (&AMP;INFO_SOAP);
Soap_destroy (&AMP;INFO_SOAP);
Soap_end (&AMP;INFO_SOAP);
Soap_done (&AMP;INFO_SOAP);
return-1;
}

#ifdef DEBUG
Soap_close_logfiles (&INFO_SOAP);
#endif
Delete Preq.user;
Preq.user = NULL;
Soap_cleanup (&INFO_SOAP);
Soap_destroy (&INFO_SOAP);
Soap_end (&INFO_SOAP);
Soap_done (&INFO_SOAP);

return 0;
}

int main (int argc, char* argv[])
{
if (argc!= 4)
{
Std::cout << "arg error" << Std::endl;
return-1;
}
int result = Sendwebserviceitem (argv[1], argv[2], argv[3]);
If (Result!= 0)
return-1;

return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.