我是使用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 = ∈
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;
}
答案 0 :(得分:1)
pIn->__sizeaccountNumber = sizeof("00000201");
__sizeaccountNumber
应设置为数组(1)的大小,而不是数组中第一个成员的大小。由于字符串以空值终止,因此无需指定字符串的大小。
正如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";