gsoap ANSI C - Using gsoap defined ANSI C Client-side call stub correctly
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)
开发者_如何学Python || 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;
}
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";
精彩评论