我尝试使用gsoap设置SOAP标题时遇到困难。我在这里阅读常见问题解答:http://www.genivia.com/Help/FAQlist.html#g17在C中使用SOAP_ENV__Header设置肥皂标题
这个答案没有任何任何帮助:How to pass header information to the soap header SOAP_ENV__Header, in c++ using gsoap
它假定一些神奇的种姓已经发生SOAP_ENV__Header种姓虚设的元素所需的数据类型。
这里是我的代码:
#include <stdio.h>
#include <time.h>
struct SOAP_ENV__Header {
char *authwsns__token;
char *authwsns__ip;
};
#define SOAP_TYPE_SOAP_ENV__Header struct SOAP_ENV__Header
#include "authservicesH.h"
#include "AuthServicesBinding.nsmap"
int
main(int argc, char **argv) {
struct soap *soap;
struct authwsns__GetTokenRequest *request;
struct authwsns__GetTokenResult *result;
soap = soap_new();
soap->header = (struct SOAP_ENV__Header *)soap_malloc(soap, sizeof(struct SOAP_ENV__Header));
soap->header->authwsns__token = "jc09bdd";
soap->header->authwsns__ip = "10.10.10.10";
request = (struct authwsns__GetTokenRequest *)malloc(sizeof(struct authwsns__GetTokenRequest));
result = (struct authwsns__GetTokenResult *)malloc(sizeof(struct authwsns__GetTokenResult));
request->tokenBase = id;
soap_call___authwsns__getToken(soap, "http://", NULL, request, result);
if (result->tdsns__errorReport) {
printf("Web services error\n");
printf("Level: %s\n",result->tdsns__errorReport->level);
printf("Message: %s\n",result->tdsns__errorReport->message);
} else {
printf("Token is %s\n",result->token);
}
soap_end(soap);
soap_free(soap);
free(request);
free(result);
}
当我通过一个调试器中运行了一个程序,显示SOAP_ENV__Header,它仍然显示其为具有虚设的元素,所以我不知道什么是正确的方式来覆盖默认定义是。常见问题中的解释对此的细节非常模糊。
当我用我的SOAP_ENV__Header定义对Stub.h文件进行破解并在其中设置值时,正确的字段在我通过调试器运行时显示出来,但它们不会显示在输出XML中。
我在这里错过了什么? 谢谢, 约翰