0

I have problem to pass request variable in my gsoap client app. The error is Segmentation Fault (core dump).

This is my header file:

class _ns1__NewTransactionDataRequest;
class _ns1__NewTransactionDataResponse;
class _ns1__GetTransactionResultRequest;
class _ns1__GetTransactionResultResponse;

class _ns1__NewTransactionDataRequest
{ 

public:

char* UserID 1; 
char* UserPwd 1;    
char* TransID 1;    
char* TransDate 1;  
char* A_NO 1;   
char* B_NO 1;   
char* Denom  1; 
char* TransType 1;  
struct soap *soap ;
};



class _ns1__NewTransactionDataResponse
{ public:
char* TransID 1;    
char* ResultCode 1; 
char* ResultDesc 1; 
struct soap *soap ;
};

class _ns1__GetTransactionResultRequest
{ 

public:

char* UserID 1; 
char* UserPwd 1;    
char* TransID 1;    
char* TransDate 1;  
char* A_NO 1;   
char* B_NO 1;   
char* Status 1; 
char* Remark 1; 
struct soap *soap                          ;
};

class _ns1__GetTransactionResultResponse
{ 

public:

char*  TransID 1;   
char*  ResultCode 1;    
char*  ResultDesc 1;    
struct soap *soap ;
};

int __ns1__NewTransactionData(_ns1__NewTransactionDataRequest*       ns1__NewTransactionDataRequest,    _ns1__NewTransactionDataResponse* ns1__NewTransactionDataResponse   
);

int __ns1__GetTransactionResult(_ns1__GetTransactionResultRequest*ns1__GetTransactionResultRequest,_ns1__GetTransactionResultResponse* ns1__GetTransactionResultResponse    
);

This is the client app that I try to compile:

int main(int argc, char **argv) 

{ 

struct soap soap;
_ns1__GetTransactionResultRequest  *ns1__GetTransactionResultRequest;
_ns1__GetTransactionResultResponse *ns1__GetTransactionResultResponse;
_ns1__NewTransactionDataRequest *ns1__NewTransactionDataRequest;
_ns1__NewTransactionDataResponse *ns1__NewTransactionDataResponse;


(*ns1__GetTransactionResultRequest).UserID = "myuserid"; //<--fail at this line
(*ns1__GetTransactionResultRequest).UserPwd = "userpwd";
(*ns1__GetTransactionResultRequest).TransID = "amwani";
(*ns1__GetTransactionResultRequest).TransDate = "2013-09-09 01:01:01";
(*ns1__GetTransactionResultRequest).A_NO = "mynumber";
(*ns1__GetTransactionResultRequest).B_NO = "yournumber";
(*ns1__GetTransactionResultRequest).Status = "success";
(*ns1__GetTransactionResultRequest).Remark = "done";


printf("Content-type: text/html\r\n\r\n<html><h1>Magic Square of Rank</h1><pre>\n");
if (soap_call___ns1__GetTransactionResult(&soap, server, NULL, ns1__GetTransactionResultRequest, ns1__GetTransactionResultResponse))
{   
    soap_print_fault(&soap, stderr);
    soap_print_fault_location(&soap, stderr);
}
else
{ 
        printf("%s", (*ns1__GetTransactionResultRequest).TransID);
}
printf("</pre></html>\n");
soap_destroy(&soap);
soap_end(&soap);
soap_done(&soap);
}

I did not get any error during compilaton, but few warnings:

xpulsaclient.cpp: In function ‘int main(int, char**)’:
xpulsaclient.cpp:46: warning: deprecated conversion from string constant to ‘char*’
xpulsaclient.cpp:47: warning: deprecated conversion from string constant to ‘char*’
xpulsaclient.cpp:48: warning: deprecated conversion from string constant to ‘char*’
xpulsaclient.cpp:49: warning: deprecated conversion from string constant to ‘char*’
xpulsaclient.cpp:50: warning: deprecated conversion from string constant to ‘char*’
xpulsaclient.cpp:51: warning: deprecated conversion from string constant to ‘char*’
xpulsaclient.cpp:52: warning: deprecated conversion from string constant to ‘char*’
xpulsaclient.cpp:53: warning: deprecated conversion from string constant to ‘char*’
xpulsaclient.cpp:42: warning: unused variable ‘ns1__NewTransactionDataRequest’
xpulsaclient.cpp:43: warning: unused variable ‘ns1__NewTransactionDataResponse’
xpulsaclient.cpp:46: warning: ‘ns1__GetTransactionResultRequest’ is used uninitialized in this function
xpulsaclient.cpp:57: warning: ‘ns1__GetTransactionResultResponse’ may be used uninitialized in this function

Maybe the way I initialize variable in class ns1_GetTransactionResultRequest is not correct that caused the segmentation fault?. Can anyone help me? I have been stuck at this point for 2 days....Thanks!

aizaz
  • 3,056
  • 9
  • 25
  • 57

1 Answers1

0

You're right - you're not initializing ns1__GetTransactionResultRequest (or any of the other pointers). The variables you've declared are pointers, but they're never assigned to a new object. You can either instantiate objects, or declare the variables on the stack instead.

I've posted a simple gSOAP client app in another response. It includes assignment to a gSOAP request object property, which should help you out.

Example: making a web services query using gSoap with query arguments

Community
  • 1
  • 1
Thaddeus
  • 91
  • 4