我使用gsoap与以下网络服务进行通信: http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?wsdl
我运行soapcpp2来生成头文件,这里是我的soapClient.c: http://pastebin.com/Bjev3dP7
的getQuote:
struct _ns1__GetQuote
{
/// Element "StockSymbol" of XSD type xs:string.
char* StockSymbol 0; ///< Optional element.
/// Element "LicenseKey" of XSD type xs:string.
char* LicenseKey 0; ///< Optional element.
};
struct _ns1__GetQuoteResponse
{
/// Element "GetQuoteResult" of XSD type "http://ws.cdyne.com/":QuoteData.
struct ns1__QuoteData* GetQuoteResult 1; ///< Required element.
};
到目前为止,这是我的代码:
#include "soapH.h"
#include "DelayedStockQuoteSoap.nsmap"
#include "soapClient.c"
struct _ns1__GetQuote *ns1__GetQuote;
struct _ns1__GetQuoteResponse *response;
main() {
struct soap *soap ;
ns1__GetQuote->StockSymbol = "goog";
ns1__GetQuote->LicenseKey = "0";
if (soap_call___ns1__GetQuote(soap, NULL, NULL, ns1__GetQuote, &response) == SOAP_OK)
printf("yay\n");
}
我在运行此代码时会收到一个段错误,是否有任何提示?
答案 0 :(得分:1)
在您的代码中有许多错误,没有分配任何内容。
首先,你需要使用:
分配struct soap
struct soap *soap = soap_new();
需要分配GetQuote
方法的下一个输入和输出参数,这可以很容易地在堆栈中存储:
struct _ns1__GetQuote ns1__GetQuote;
struct _ns1__GetQuoteResponse response;
将所有内容放在一起可能会产生类似的结果:
#include "soapH.h"
#include "DelayedStockQuoteSoap.nsmap"
#include "soapClient.c"
main() {
struct soap *soap = soap_new();
struct _ns1__GetQuote ns1__GetQuote;
struct _ns1__GetQuoteResponse response;
ns1__GetQuote.StockSymbol = "goog";
ns1__GetQuote.LicenseKey = "0";
if (soap_call___ns1__GetQuote(soap, NULL, NULL, &ns1__GetQuote, &response) == SOAP_OK)
printf("yay\n");
}