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
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);
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;
}
精彩评论