gsoap ANSI C - 正确使用 gsoap 定义的 ANSI C 客户端调用存根

发布于 2024-10-25 20:11:11 字数 3929 浏览 1 评论 0原文

我是使用 gsoap 的新手。我仅使用 C++ 取得了 4 个小成功,但是受我当前项目的限制,无法设置源代码生成选项来创建纯 ANSI C(不是 C++)。我似乎无法成功调用该服务,错误返回为 0xC0000005,并给出以下代码片段,任何人都可以建议我应该采取哪些不同的做法:

代码片段包括
1.客户端函数定义,
2. ns7结构def,
3.简单的调用应用:
谢谢,

这是客户端调用:

#include "soapH.h"  
#include "addressByAccount_ExtWS_BPELSOAP.nsmap"

SOAP_FMAC5 int SOAP_FMAC6 soap_call___ns1__accountsBPEL(struct soap *soap, const char *soap_endpoint, const char *soap_action, struct _ns7__accounts *ns7__accounts, struct     _ns9__accountsResponse *ns9__accountsResponse)  
{         
        struct __ns1__accountsBPEL soap_tmp___ns1__accountsBPEL;  
        if (!soap_endpoint)    
            soap_endpoint = "http://cctest3-v.physio-control.com:8080/ccx/addressByAccount-ExtWS-BPEL";    
        if (!soap_action)  
        soap_action = "http://www.physio-control.com/addressByAccount-ExtWS-BPEL/1.0/accounts";  
    soap->encodingStyle = NULL;  
    soap_tmp___ns1__accountsBPEL.ns7__accounts = ns7__accounts;  
    soap_begin(soap);  
    soap_serializeheader(soap);
    soap_serialize___ns1__accountsBPEL(soap, &soap_tmp___ns1__accountsBPEL);
    if (soap_begin_count(soap))
            return soap->error;
    if (soap->mode & SOAP_IO_LENGTH)
    {   if (soap_envelope_begin_out(soap)
         || soap_putheader(soap)
         || soap_body_begin_out(soap)
         || soap_put___ns1__accountsBPEL(soap, &soap_tmp___ns1__accountsBPEL, "-ns1:accountsBPEL", NULL)
         || soap_body_end_out(soap)
         || soap_envelope_end_out(soap))
             return soap->error;
    }
    if (soap_end_count(soap))
        return soap->error;
    if (soap_connect(soap, soap_endpoint, soap_action)
     || soap_envelope_begin_out(soap)
     || soap_putheader(soap)
     || soap_body_begin_out(soap)
     || soap_put___ns1__accountsBPEL(soap, &soap_tmp___ns1__accountsBPEL, "-ns1:accountsBPEL", NULL)
     || soap_body_end_out(soap)
     || soap_envelope_end_out(soap)
     || soap_end_send(soap))
        return soap_closesock(soap);
    if (!ns9__accountsResponse)
        return soap_closesock(soap);
    soap_default__ns9__accountsResponse(soap, ns9__accountsResponse);
    if (soap_begin_recv(soap)
     || soap_envelope_begin_in(soap)
     || soap_recv_header(soap)
     || soap_body_begin_in(soap))
        return soap_closesock(soap);
    soap_get__ns9__accountsResponse(soap, ns9__accountsResponse, "ns9:accountsResponse", "");
    if (soap->error)
        return soap_recv_fault(soap, 0);
    if (soap_body_end_in(soap)
     || soap_envelope_end_in(soap)
     || soap_end_recv(soap))
        return soap_closesock(soap);
    return soap_closesock(soap);
}

这是 ns7 结构:

struct _ns7__accounts
{
    int __sizeaccountNumber;    /* sequence of elements <accountNumber> */
    char **accountNumber;   /* required element of type xsd:string */
    char *requestIDTrackingForESB;  /* optional attribute of type xsd:string */
};

这是一个使用客户端调用的简单应用程序调用服务:

struct _ns7__accounts in, *pIn;
struct _ns9__accountsResponse out, *pOut;
int main(void)
{
    struct soap *soap = soap_new();

    //used to populate char ** in pIn
    char *pNumber=malloc(sizeof("00000201"));
    strcpy(pNumber, "00000201");

    pOut = &out;
    pIn = &in;

    pIn->__sizeaccountNumber = sizeof("00000201");
    pIn->accountNumber = &pNumber;
    pIn->requestIDTrackingForESB = malloc(sizeof(""));
    strcpy(pIn->requestIDTrackingForESB,"");

    if (soap_call___ns1__accountsBPEL(soap, "", "", pIn, pOut)== SOAP_OK)
    {
        printf("Soap OK...");
    }
    else  
    {
        printf(pIn->requestIDTrackingForESB);
        soap_print_fault(soap, stderr);
    }
    soap_end(soap);
    soap_free(soap);

   return 0;
} 

I am new to using gsoap. I have 4 small successes using c++ only, however am constrained by my current project to set source code generation options to create pure ANSI C (not c++). I cannot seem to successfully call the service, the error return is 0xC0000005 and given the following code snippets, can anyone make a suggestion as to what I should do differently:

Snippets include
1. client-side function definition,
2. ns7 structure def,
3. simple calling application:
Thank you,

Here is the client side call:

#include "soapH.h"  
#include "addressByAccount_ExtWS_BPELSOAP.nsmap"

SOAP_FMAC5 int SOAP_FMAC6 soap_call___ns1__accountsBPEL(struct soap *soap, const char *soap_endpoint, const char *soap_action, struct _ns7__accounts *ns7__accounts, struct     _ns9__accountsResponse *ns9__accountsResponse)  
{         
        struct __ns1__accountsBPEL soap_tmp___ns1__accountsBPEL;  
        if (!soap_endpoint)    
            soap_endpoint = "http://cctest3-v.physio-control.com:8080/ccx/addressByAccount-ExtWS-BPEL";    
        if (!soap_action)  
        soap_action = "http://www.physio-control.com/addressByAccount-ExtWS-BPEL/1.0/accounts";  
    soap->encodingStyle = NULL;  
    soap_tmp___ns1__accountsBPEL.ns7__accounts = ns7__accounts;  
    soap_begin(soap);  
    soap_serializeheader(soap);
    soap_serialize___ns1__accountsBPEL(soap, &soap_tmp___ns1__accountsBPEL);
    if (soap_begin_count(soap))
            return soap->error;
    if (soap->mode & SOAP_IO_LENGTH)
    {   if (soap_envelope_begin_out(soap)
         || soap_putheader(soap)
         || soap_body_begin_out(soap)
         || soap_put___ns1__accountsBPEL(soap, &soap_tmp___ns1__accountsBPEL, "-ns1:accountsBPEL", NULL)
         || soap_body_end_out(soap)
         || soap_envelope_end_out(soap))
             return soap->error;
    }
    if (soap_end_count(soap))
        return soap->error;
    if (soap_connect(soap, soap_endpoint, soap_action)
     || soap_envelope_begin_out(soap)
     || soap_putheader(soap)
     || soap_body_begin_out(soap)
     || soap_put___ns1__accountsBPEL(soap, &soap_tmp___ns1__accountsBPEL, "-ns1:accountsBPEL", NULL)
     || soap_body_end_out(soap)
     || soap_envelope_end_out(soap)
     || soap_end_send(soap))
        return soap_closesock(soap);
    if (!ns9__accountsResponse)
        return soap_closesock(soap);
    soap_default__ns9__accountsResponse(soap, ns9__accountsResponse);
    if (soap_begin_recv(soap)
     || soap_envelope_begin_in(soap)
     || soap_recv_header(soap)
     || soap_body_begin_in(soap))
        return soap_closesock(soap);
    soap_get__ns9__accountsResponse(soap, ns9__accountsResponse, "ns9:accountsResponse", "");
    if (soap->error)
        return soap_recv_fault(soap, 0);
    if (soap_body_end_in(soap)
     || soap_envelope_end_in(soap)
     || soap_end_recv(soap))
        return soap_closesock(soap);
    return soap_closesock(soap);
}

Here is the ns7 structure:

struct _ns7__accounts
{
    int __sizeaccountNumber;    /* sequence of elements <accountNumber> */
    char **accountNumber;   /* required element of type xsd:string */
    char *requestIDTrackingForESB;  /* optional attribute of type xsd:string */
};

Here is a simple application calling service using client-side call:

struct _ns7__accounts in, *pIn;
struct _ns9__accountsResponse out, *pOut;
int main(void)
{
    struct soap *soap = soap_new();

    //used to populate char ** in pIn
    char *pNumber=malloc(sizeof("00000201"));
    strcpy(pNumber, "00000201");

    pOut = &out;
    pIn = ∈

    pIn->__sizeaccountNumber = sizeof("00000201");
    pIn->accountNumber = &pNumber;
    pIn->requestIDTrackingForESB = malloc(sizeof(""));
    strcpy(pIn->requestIDTrackingForESB,"");

    if (soap_call___ns1__accountsBPEL(soap, "", "", pIn, pOut)== SOAP_OK)
    {
        printf("Soap OK...");
    }
    else  
    {
        printf(pIn->requestIDTrackingForESB);
        soap_print_fault(soap, stderr);
    }
    soap_end(soap);
    soap_free(soap);

   return 0;
} 

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

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

发布评论

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

评论(1

你穿错了嫁妆 2024-11-01 20:11:11
pIn->__sizeaccountNumber = sizeof("00000201");

__sizeaccountNumber 应设置为数组的大小 (1),而不是数组中第一个成员的大小。由于字符串以 null 结尾,因此无需指定字符串的大小。

正如 pmg 已经评论的那样,不要为soap_endpoint 和soap_action 传递""。您可以在函数中看到它定义了这些参数的默认值,但前提是您传递 0 (或 NULL)。

if (!soap_endpoint)    
  soap_endpoint = "http://cctest3-v.physio-control.com:8080/ccx/addressByAccount-ExtWS-BPEL";    
if (!soap_action)  
  soap_action = "http://www.physio-control.com/addressByAccount-ExtWS-BPEL/1.0/accounts";  
pIn->__sizeaccountNumber = sizeof("00000201");

__sizeaccountNumber should be set to the size of the array (1), not to the size of the first member in the array. Because a string is null terminated, there is no need to specify the size of a string.

And as already commented by pmg, don't pass "" for soap_endpoint and soap_action. You can see in the function it defines defaults for those parameters, but only if you pass 0 (or NULL).

if (!soap_endpoint)    
  soap_endpoint = "http://cctest3-v.physio-control.com:8080/ccx/addressByAccount-ExtWS-BPEL";    
if (!soap_action)  
  soap_action = "http://www.physio-control.com/addressByAccount-ExtWS-BPEL/1.0/accounts";  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文