gsoap クライアント アプリでリクエスト変数を渡すのに問題があります。エラーは、Segmentation Fault (コア ダンプ) です。
これは私のヘッダーファイルです:
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
);
これは、コンパイルしようとするクライアント アプリです。
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);
}
コンパイル中にエラーは発生しませんでしたが、警告はほとんどありません。
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
クラスns1 _GetTransactionResultRequest で変数を初期化する方法が正しくないため、セグメンテーション違反が発生したのではないでしょうか? 誰でも私を助けることができますか?私はこの時点で 2 日間立ち往生しています....ありがとう!