How to pass header information to the soap header SOAP_ENV__Header, in c++ using gsoap

时间秒杀一切 提交于 2019-12-14 02:19:08

问题


I am working on calling the webservices using the gsoap packages in c++ and get the responses. I have to pass some header information as well, which I am not sure how to do that, as my header is like this - /* SOAP Header: */

struct SOAP_ENV__Header

{

public:

void *dummy;    /* transient */

};

Is there something I missed, or it is supposed to be like this only and we have to make changes here? I have read here some info, but my header is just dummy.

Secondly, for further debugging, I wanted to enable DEBUGS and for that, as per the user-guide, I have uncommented the DEBUG macros in the stdsoap2.h and built with the DEBUG flag again but, I couldn't get the .log files getting created. Any idea?

Deepak


回答1:


You can do something like

soap_init(&mysoap);
mysoap.header = (SOAP_ENV__Header *)soap_malloc(&mysoap, sizeof(SOAP_ENV__Header));
mysoap.header->ns3__MyHeader = (ns3__Header*)malloc(sizeof(ns3__Header));
mysoap.header->ns3__MyHeader->Value = (char*)malloc(10 * sizeof(char));
strcpy(mysoap.header->ns3__MyHeader->Value, str);



回答2:


For rest calls this works -

#include "json.h"
#include <string.h>
#include "jsonStub.h"

struct Namespace namespaces[] = { {NULL, NULL} };
int main()
{
   struct soap *ctx = soap_new1(SOAP_XML_NOTYPE);
   soap_init(ctx);
   struct value *request = new_value(ctx);
   struct value response;

   ctx->sendfd = 1;   
   ctx->http_extra_header = "userName:abcd\r\npassword:xyz";
   *string_of(value_at(value_at(request, "add"), "i")) = "10";
   *string_of(value_at(value_at(request, "add"), "j")) = "20";

   json_write(ctx, request);
   printf("\n");
   if (json_call(ctx, "endpoint",request, &response))
   {
         printf( "json call failed " );
         soap_print_fault(ctx, stderr);
         printf("\n%d", ctx->error);
         printf("\n1: SOAP faultcode = %s\n", *soap_faultcode(ctx));
         printf("2: SOAP faultstring = %s\n", *soap_faultstring(ctx));
         printf("3: SOAP faultdetail = %s\n\n", *soap_faultdetail(ctx));
         soap_print_fault_location(ctx, stderr);

   }

   else
   {
         printf("Success !!!");
         json_write(ctx, &response);
   }

   soap_destroy(ctx);
   soap_end(ctx);
   soap_free(ctx);
   return 0;

}



来源:https://stackoverflow.com/questions/7569324/how-to-pass-header-information-to-the-soap-header-soap-env-header-in-c-using

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!