如何将标头信息传递到soap标头SOAP_ENV__Header,在c++使用 gsoap

发布于 2024-12-07 07:56:26 字数 513 浏览 0 评论 0原文

我正在使用 c++ 中的 gsoap 包调用 Web 服务并获取响应。 我还必须传递一些标头信息,我不知道该怎么做,因为我的标头是这样的 - /* SOAP 标头: */

struct SOAP_ENV__Header

{

public:

void *dummy;    /* transient */

};

是否有什么我错过了,或者应该只是这样,我们必须在这里做出改变? 我已阅读此处一些信息,但我的标题只是假的。

其次,为了进一步调试,我想启用 DEBUGS,为此,根据用户指南,我取消了 stdsoap2.h 中 DEBUG 宏的注释,并再次使用 DEBUG 标志构建,但是,我无法获取 .log文件正在创建。有什么想法吗?

迪帕克

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

高跟鞋的旋律 2024-12-14 07:56:26

你可以做类似的事情

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);

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);
似最初 2024-12-14 07:56:26

对于休息呼叫,这有效 -

#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;

}

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;

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文