There's some misleading info in gSOAP's official documents in SOAP Header Processing Part.
This article leads you to the right way and can make your program work. The use case is:
Client needs to pass user name and password to Server Side to get authenticated.
The username and password info shocould be embeded in SOAP Header. Steps:
1. Edit struct SOAP_ENV _ Header in soapStub. h file which is generated by gSOAP's soapcpp2 compiler
Add the neccesary info to this struct
For example: The original one is:
Struct SOAP_ENV _ Header
{
Public:
Void * dummy;/* transient */
};
This shoshould be changed:
Struct SOAP_ENV _ Header
{
Public:
Void * dummy;/* transient */
Char * username;
Char * password;
}; 2. Edit function soap_out_SOAP_ENV _ Header in soapC. cpp file which is also generated by gSOAP
Add statements to serialize those info into SOAP Header.
For example: The original one is:
SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV _ Header (struct soap * soap, const char * tag, int id, construst SOAP_ENV _ Header * a, const char * type)
{
Soap_element_begin_out (soap, tag, soap_embedded_id (soap, id, a, SOAP_TYPE_SOAP_ENV _ Header), type );
/* Transient dummy skipped */
Soap_element_end_out (soap, tag );
Return SOAP_ OK;
} This coshould be changed to: SOAP_FMAC3 int SOAP_FMAC4 soap_out_SOAP_ENV _ Header (struct soap * soap, const char * tag, int id, const struct SOAP_ENV _ Header *, const char * type)
{
Soap_element_begin_out (soap, tag, soap_embedded_id (soap, id, a, SOAP_TYPE_SOAP_ENV _ Header), type );
} 3. Add the namespace mapping to namespaces array in. nsmap file.
{"HeaderNS", "http://customeheader.test.com ",
NULL, NULL}, 4. Set the header before invoking Web Service Method. This part you can also refer to the gSOAP's official implements enthttp: // www.cs.fsu.edu /~ Engelen/soapdoc2.html # tth_sEc12. struct soap;
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.