2016-02-13 67 views
0

我使用gSOAP的用下面的Web服务进行通信: http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?wsdl段错误上运行的应用程序gSOAP的

我已经运行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"); 
} 

当我运行此代码时,我收到段错误,任何提示?

回答

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"); 
} 
相关问题