gpt4 book ai didi

c - gsoap ANSI C - 正确使用 gsoap 定义的 ANSI C 客户端调用 stub

转载 作者:太空宇宙 更新时间:2023-11-04 04:06:28 26 4
gpt4 key购买 nike

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

片段包括
1. 客户端函数定义,
2. ns7结构定义,
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;
}

最佳答案

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

关于c - gsoap ANSI C - 正确使用 gsoap 定义的 ANSI C 客户端调用 stub ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5394829/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com