Hello people,

I am trying to set up a simple soap client to this web service with gsoap.

Code generated with soapcpp compiles and works fine but I cannot seem to successfully get data from service.

This service uses soap_header to check user login and password.

std::string login = "somelogin";
    std::string password = "somecode";

    std::string from = "AMD";
    std::string to = "USD";

    CurrencyRatesSoapProxy rateProxy(SOAP_XML_INDENT);

    ns2__LicenseInfo* licenseinfo = new ns2__LicenseInfo;

    ns2__RegisteredUser reguser;
    reguser.UserID = &login;
    reguser.Password = &password;

    ns2__SubscriptionInfo subs;

    licenseinfo->RegisteredUser = ®user;
    licenseinfo->UnregisteredUser = NULL;

    rateProxy.soap_header(licenseinfo, NULL);

    _ns1__GetLatestRate getrate;
    getrate.SingleCurrencyFrom = &to;
    getrate.SingleCurrencyTo = &from;

    _ns1__GetLatestRateResponse responserate;


    if (rateProxy.GetLatestRate(&getrate, &responserate) == SOAP_OK)
        std::cout << "Works!";
    else
        rateProxy.soap_stream_fault(std::cerr);

    std::cout << "Doesnt work!";
    return "";

^^ that is the code written by me that should work. The following codes are codes generated by soapcpp2:

class SOAP_CMAC CurrencyRatesSoapProxy : public soap
{ public:
    /// Endpoint URL of service 'CurrencyRatesSoapProxy' (change as needed)
    const char *soap_endpoint;
    /// Constructor
    CurrencyRatesSoapProxy();
    /// Construct from another engine state
    CurrencyRatesSoapProxy(const struct soap&);
    /// Constructor with endpoint URL
    CurrencyRatesSoapProxy(const char *url);
    /// Constructor with engine input+output mode control
    CurrencyRatesSoapProxy(soap_mode iomode);
    /// Constructor with URL and input+output mode control
    CurrencyRatesSoapProxy(const char *url, soap_mode iomode);
    /// Constructor with engine input and output mode control
    CurrencyRatesSoapProxy(soap_mode imode, soap_mode omode);
    /// Destructor frees deserialized data
    virtual ~CurrencyRatesSoapProxy();
    /// Initializer used by constructors
    virtual void CurrencyRatesSoapProxy_init(soap_mode imode, soap_mode omode);
    /// Delete all deserialized data (with soap_destroy and soap_end)
    virtual void destroy();
    /// Delete all deserialized data and reset to default
    virtual void reset();
    /// Disables and removes SOAP Header from message
    virtual void soap_noheader();
    /// Put SOAP Header in message
    virtual void soap_header(ns2__LicenseInfo *ns2__LicenseInfo_, ns2__SubscriptionInfo *ns2__SubscriptionInfo_);
    /// Get SOAP Header structure (NULL when absent)
    virtual const SOAP_ENV__Header *soap_header();
    /// Get SOAP Fault structure (NULL when absent)
    virtual const SOAP_ENV__Fault *soap_fault();
    /// Get SOAP Fault string (NULL when absent)
    virtual const char *soap_fault_string();
    /// Get SOAP Fault detail as string (NULL when absent)
    virtual const char *soap_fault_detail();
    /// Close connection (normally automatic, except for send_X ops)
    virtual int soap_close_socket();
    /// Force close connection (can kill a thread blocked on IO)
    virtual int soap_force_close_socket();
    /// Print fault
    virtual void soap_print_fault(FILE*);
#ifndef WITH_LEAN
    /// Print fault to stream
#ifndef WITH_COMPAT
    virtual void soap_stream_fault(std::ostream&);
#endif

    /// Put fault into buffer
    virtual char *soap_sprint_fault(char *buf, size_t len);
#endif

    /// Web service operation 'GetLatestRate' (returns error code or SOAP_OK)
    virtual int GetLatestRate(_ns1__GetLatestRate *ns1__GetLatestRate, _ns1__GetLatestRateResponse *ns1__GetLatestRateResponse) { return this->GetLatestRate(NULL, NULL, ns1__GetLatestRate, ns1__GetLatestRateResponse); }
    virtual int GetLatestRate(const char *endpoint, const char *soap_action, _ns1__GetLatestRate *ns1__GetLatestRate, _ns1__GetLatestRateResponse *ns1__GetLatestRateResponse);

    /// Web service operation 'GetLatestRates' (returns error code or SOAP_OK)
    virtual int GetLatestRates(_ns1__GetLatestRates *ns1__GetLatestRates, _ns1__GetLatestRatesResponse *ns1__GetLatestRatesResponse) { return this->GetLatestRates(NULL, NULL, ns1__GetLatestRates, ns1__GetLatestRatesResponse); }
    virtual int GetLatestRates(const char *endpoint, const char *soap_action, _ns1__GetLatestRates *ns1__GetLatestRates, _ns1__GetLatestRatesResponse *ns1__GetLatestRatesResponse);

    /// Web service operation 'CurrencyRateForAmount' (returns error code or SOAP_OK)
    virtual int CurrencyRateForAmount(_ns1__CurrencyRateForAmount *ns1__CurrencyRateForAmount, _ns1__CurrencyRateForAmountResponse *ns1__CurrencyRateForAmountResponse) { return this->CurrencyRateForAmount(NULL, NULL, ns1__CurrencyRateForAmount, ns1__CurrencyRateForAmountResponse); }
    virtual int CurrencyRateForAmount(const char *endpoint, const char *soap_action, _ns1__CurrencyRateForAmount *ns1__CurrencyRateForAmount, _ns1__CurrencyRateForAmountResponse *ns1__CurrencyRateForAmountResponse);

    /// Web service operation 'GetHistoricalRates' (returns error code or SOAP_OK)
    virtual int GetHistoricalRates(_ns1__GetHistoricalRates *ns1__GetHistoricalRates, _ns1__GetHistoricalRatesResponse *ns1__GetHistoricalRatesResponse) { return this->GetHistoricalRates(NULL, NULL, ns1__GetHistoricalRates, ns1__GetHistoricalRatesResponse); }
    virtual int GetHistoricalRates(const char *endpoint, const char *soap_action, _ns1__GetHistoricalRates *ns1__GetHistoricalRates, _ns1__GetHistoricalRatesResponse *ns1__GetHistoricalRatesResponse);

    /// Web service operation 'GetHistoricalRate' (returns error code or SOAP_OK)
    virtual int GetHistoricalRate(_ns1__GetHistoricalRate *ns1__GetHistoricalRate, _ns1__GetHistoricalRateResponse *ns1__GetHistoricalRateResponse) { return this->GetHistoricalRate(NULL, NULL, ns1__GetHistoricalRate, ns1__GetHistoricalRateResponse); }
    virtual int GetHistoricalRate(const char *endpoint, const char *soap_action, _ns1__GetHistoricalRate *ns1__GetHistoricalRate, _ns1__GetHistoricalRateResponse *ns1__GetHistoricalRateResponse);

    /// Web service operation 'GetAllLatestRatesToUSD' (returns error code or SOAP_OK)
    virtual int GetAllLatestRatesToUSD(_ns1__GetAllLatestRatesToUSD *ns1__GetAllLatestRatesToUSD, _ns1__GetAllLatestRatesToUSDResponse *ns1__GetAllLatestRatesToUSDResponse) { return this->GetAllLatestRatesToUSD(NULL, NULL, ns1__GetAllLatestRatesToUSD, ns1__GetAllLatestRatesToUSDResponse); }
    virtual int GetAllLatestRatesToUSD(const char *endpoint, const char *soap_action, _ns1__GetAllLatestRatesToUSD *ns1__GetAllLatestRatesToUSD, _ns1__GetAllLatestRatesToUSDResponse *ns1__GetAllLatestRatesToUSDResponse);

    /// Web service operation 'GetAllLatestUSDToCurrencies' (returns error code or SOAP_OK)
    virtual int GetAllLatestUSDToCurrencies(_ns1__GetAllLatestUSDToCurrencies *ns1__GetAllLatestUSDToCurrencies, _ns1__GetAllLatestUSDToCurrenciesResponse *ns1__GetAllLatestUSDToCurrenciesResponse) { return this->GetAllLatestUSDToCurrencies(NULL, NULL, ns1__GetAllLatestUSDToCurrencies, ns1__GetAllLatestUSDToCurrenciesResponse); }
    virtual int GetAllLatestUSDToCurrencies(const char *endpoint, const char *soap_action, _ns1__GetAllLatestUSDToCurrencies *ns1__GetAllLatestUSDToCurrencies, _ns1__GetAllLatestUSDToCurrenciesResponse *ns1__GetAllLatestUSDToCurrenciesResponse);

    /// Web service operation 'GetSupportedCurrencies' (returns error code or SOAP_OK)
    virtual int GetSupportedCurrencies(_ns1__GetSupportedCurrencies *ns1__GetSupportedCurrencies, _ns1__GetSupportedCurrenciesResponse *ns1__GetSupportedCurrenciesResponse) { return this->GetSupportedCurrencies(NULL, NULL, ns1__GetSupportedCurrencies, ns1__GetSupportedCurrenciesResponse); }
    virtual int GetSupportedCurrencies(const char *endpoint, const char *soap_action, _ns1__GetSupportedCurrencies *ns1__GetSupportedCurrencies, _ns1__GetSupportedCurrenciesResponse *ns1__GetSupportedCurrenciesResponse);

    /// Web service operation 'GetStatusCodesForMethod' (returns error code or SOAP_OK)
    virtual int GetStatusCodesForMethod(_ns1__GetStatusCodesForMethod *ns1__GetStatusCodesForMethod, _ns1__GetStatusCodesForMethodResponse *ns1__GetStatusCodesForMethodResponse) { return this->GetStatusCodesForMethod(NULL, NULL, ns1__GetStatusCodesForMethod, ns1__GetStatusCodesForMethodResponse); }
    virtual int GetStatusCodesForMethod(const char *endpoint, const char *soap_action, _ns1__GetStatusCodesForMethod *ns1__GetStatusCodesForMethod, _ns1__GetStatusCodesForMethodResponse *ns1__GetStatusCodesForMethodResponse);

    /// Web service operation 'GetStatusCodes' (returns error code or SOAP_OK)
    virtual int GetStatusCodes(_ns1__GetStatusCodes *ns1__GetStatusCodes, _ns1__GetStatusCodesResponse *ns1__GetStatusCodesResponse) { return this->GetStatusCodes(NULL, NULL, ns1__GetStatusCodes, ns1__GetStatusCodesResponse); }
    virtual int GetStatusCodes(const char *endpoint, const char *soap_action, _ns1__GetStatusCodes *ns1__GetStatusCodes, _ns1__GetStatusCodesResponse *ns1__GetStatusCodesResponse);

    /// Web service operation 'GetServiceInfo' (returns error code or SOAP_OK)
    virtual int GetServiceInfo(_ns1__GetServiceInfo *ns1__GetServiceInfo, _ns1__GetServiceInfoResponse *ns1__GetServiceInfoResponse) { return this->GetServiceInfo(NULL, NULL, ns1__GetServiceInfo, ns1__GetServiceInfoResponse); }
    virtual int GetServiceInfo(const char *endpoint, const char *soap_action, _ns1__GetServiceInfo *ns1__GetServiceInfo, _ns1__GetServiceInfoResponse *ns1__GetServiceInfoResponse);

    /// Web service operation 'GetRemainingHits' (returns error code or SOAP_OK)
    virtual int GetRemainingHits(_ns2__GetRemainingHits *ns2__GetRemainingHits, _ns2__GetRemainingHitsResponse *ns2__GetRemainingHitsResponse) { return this->GetRemainingHits(NULL, NULL, ns2__GetRemainingHits, ns2__GetRemainingHitsResponse); }
    virtual int GetRemainingHits(const char *endpoint, const char *soap_action, _ns2__GetRemainingHits *ns2__GetRemainingHits, _ns2__GetRemainingHitsResponse *ns2__GetRemainingHitsResponse);
};

Class ns2__registeredUser used at first code:

class SOAP_CMAC ns2__RegisteredUser
{
public:
    std::string *UserID;    /* optional element of type xsd:string */
    std::string *Password;  /* optional element of type xsd:string */
    struct soap *soap;  /* transient */
public:
    virtual int soap_type() const { return 57; } /* = unique id SOAP_TYPE_ns2__RegisteredUser */
    virtual void soap_default(struct soap*);
    virtual void soap_serialize(struct soap*) const;
    virtual int soap_put(struct soap*, const char*, const char*) const;
    virtual int soap_out(struct soap*, const char*, int, const char*) const;
    virtual void *soap_get(struct soap*, const char*, const char*);
    virtual void *soap_in(struct soap*, const char*, const char*);
             ns2__RegisteredUser() { ns2__RegisteredUser::soap_default(NULL); }
    virtual ~ns2__RegisteredUser() { }
};

class licenseInfo:

class SOAP_CMAC ns2__LicenseInfo
{
public:
    class ns2__UnregisteredUser *UnregisteredUser;  /* optional element of type ns2:UnregisteredUser */
    class ns2__RegisteredUser *RegisteredUser;  /* optional element of type ns2:RegisteredUser */
    struct soap *soap;  /* transient */
public:
    virtual int soap_type() const { return 55; } /* = unique id SOAP_TYPE_ns2__LicenseInfo */
    virtual void soap_default(struct soap*);
    virtual void soap_serialize(struct soap*) const;
    virtual int soap_put(struct soap*, const char*, const char*) const;
    virtual int soap_out(struct soap*, const char*, int, const char*) const;
    virtual void *soap_get(struct soap*, const char*, const char*);
    virtual void *soap_in(struct soap*, const char*, const char*);
             ns2__LicenseInfo() { ns2__LicenseInfo::soap_default(NULL); }
    virtual ~ns2__LicenseInfo() { }
};

Error:

SOAP 1.1 fault: SOAP-ENV:Client[no subcode]
"No user identifier provided"
Detail: [no detail]

Sorry for long post, I hope this code is enough but if you need more code, I will post...
Thanks in advance :)

make it to the top first and last time ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.