Click here to Skip to main content
12,702,455 members (33,665 online)
Click here to Skip to main content
Add your own
alternative version


27 bookmarked

SOAP Client: Using SOAP Toolkit 3.0

, 2 Nov 2003
Rate this:
Please Sign up or sign in to vote.
A SOAP client, using SOAP Toolkit 3.0.


This article describes a project that provides a SOAP Client using SOAP Toolkit 3.0. It can be altered to use with SOAP Toolkit 2.0.

Using the code

The project is a Win32 console application. The user needs to change the method name as well as the path of the WSDL file.


  • SOAP Toolkit 2.0 or 3.0
  • MSXML 4.0

Instructions to download as well as install these are present in the MSDN website.

HRESULT hRes = CoInitialize(NULL);

    ///////////////////NEW VERSION
    CString csMethodName="MEthodName";
    //OLECHAR FAR* fszMemberFunc[] = {L"MethodName"}; 
                    //Name of method being called

    LPOLESTR fszMemberFunc;
    IDispatch FAR* pdisp; //Pointer to IDispatch object
    DISPID dispid; //ID of method
    unsigned int uArgErr = 0;
    DISPPARAMS dispparams; //Parameter workarea
    EXCEPINFO excepinfo; //Exception Information
    HRESULT hresult; //return value, system functions
    VARIANT returnval; //return value(s) from server being called
    CString CEMessage;

    _bstr_t bstrWSDLFile

    BSTR xmlInput;
    CString tempValue= "<TEST>Hi there</TEST>";
    xmlInput= tempValue.AllocSysString();

    dispparams.rgvarg = NULL;
//  CComPtr<ISOAPClient> m_ptrSoapClient;
    CComPtr<ISoapClient> m_ptrSoapClient;//For SOAPTOOLKIT 3.0
        hresult = AnsiToUnicode(csMethodName,&fszMemberFunc); 

            CEMessage.Format("Unable to execute AnsiToUnicode"
                " for ProgID %s, with Error : %d",
                csMethodName, hresult);
            throw (CEMessage);
            //error converting the method anme
        //For SOAPTOOLKIT 2.0
    //  hresult = 
        //For SOAPTOOLKIT 3.0
        hresult = m_ptrSoapClient.CoCreateInstance(__uuidof(SoapClient30));
        if (S_OK != hresult)    {

            CEMessage.Format("CoCreateInstance failed for"
                   " SOAP CLIENT  with the Error : %d",
            throw (CEMessage); //error creating an instance 
        _bstr_t tmp(_T(""));

        hresult = m_ptrSoapClient->MSSoapInit(bstrWSDLFile, 
                              "","","");//For SOAPTOOLKIT 3.0
//      hresult = m_ptrSoapClient->mssoapinit(bstrWSDLFile,
                              "","","");//For SOAPTOOLKIT 2.0

        if (S_OK != hresult) {

            CEMessage.Format("Initialization failed"
                    " for SOAP Client  with Error : %d", 
            throw (CEMessage);
        }//Falied to inialize

        //    GetID of Member Function Being called
        hresult = -1;

        hresult = m_ptrSoapClient->GetIDsOfNames(IID_NULL, 
                    &fszMemberFunc, 1,    
                    LOCALE_SYSTEM_DEFAULT, &dispid);
        if (S_OK != hresult) {

            CEMessage.Format("GetIDsOfNames failed for"
              " ProgID SoapClient, Function Name %s,  with Error : %d", 
            throw (CEMessage);

        //Now setup arguments for transfer to server
        dispparams.rgvarg = new VARIANTARG[1];

        if (NULL == dispparams.rgvarg)
            throw ("Unable to allocate from the heap");

        dispparams.cArgs = 1;
        dispparams.cNamedArgs = 0;
        dispparams.rgdispidNamedArgs = NULL;
        dispparams.rgvarg[0].vt = VT_BYREF|VT_BSTR;
        dispparams.rgvarg[0].pbstrVal = &xmlInput;     

        //Setup initial conditions and Invoke Call
        excepinfo.wCode = 0;
        excepinfo.bstrSource = NULL;
        excepinfo.bstrDescription = NULL;
        excepinfo.bstrHelpFile = NULL;
        hresult = -1;
        hresult = m_ptrSoapClient->Invoke(dispid, IID_NULL, 
                    &dispparams, &returnval, &excepinfo, &uArgErr);

        if (S_OK != hresult) {
            if (DISP_E_EXCEPTION == hresult) {

                char src[256];
                char dsc[256];
                DWORD iLengthS = 
                   SysStringByteLen (excepinfo.bstrSource);
                DWORD iLengthD = 
                   SysStringByteLen (excepinfo.bstrDescription);
                WideCharToMultiByte(CP_ACP, NULL, 
                    src, sizeof(src), NULL, NULL);
                WideCharToMultiByte(CP_ACP, NULL, 
                    dsc, sizeof(dsc), NULL, NULL);
                CEMessage.Format("exceptinfo: bstrSource '%s', 
                    bstrDescription '%s', wCode '%d'", 
                    src, dsc, excepinfo.wCode);

            bstr_t faultString=m_ptrSoapClient->GetFaultString();
            CString tempFaultString=(LPCSTR)faultString;
            bstr_t  detail=m_ptrSoapClient->GetDetail();
            CString tempfaultdetail=(LPCSTR) detail;
            CEMessage.Format("IDispatch.Invoke() failed for"
                 " ProgID SoapClient, Function Name %s  with HRESULT"
                 "   %d  FaultString %s and FaltDetails %s", 
            throw (CEMessage);

        CString temp= returnval.bstrVal;//temp has the results

    catch (CString& csMsg)

    catch (CException* pException)
        char msg[256];

        delete pException;
    catch (...)

    if (m_ptrSoapClient)
        pdisp = NULL;
    if (NULL != dispparams.rgvarg)
        delete [] dispparams.rgvarg;


Points of interest

Couple of points which are worth mentioning:

  1. In case the user encounters this error:
    exceptinfo: bstrSource 'Connector', bstrDescription 
      'Connector:Connection time out. 
    HRESULT=0x800A1527 - Client:An unanticipated error occurred 
      during the processing of this request. 
    HRESULT=0x800A1527 - Client:Sending the Soap message failed or no 
      recognizable response was received 
    HRESULT=0x800A1527 - ClieConnector', wCode '0'

    Bump up the timeout. It might fix it.

  2. If WinINET connector to be used instead of WinHTTP, rename/delete whsc30.dll under program files\common files\MSSoap\Binaries.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Vipul Bansal
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionVT_Dispatch to BSTR conversion issue Pin
Member 267324721-Aug-11 21:58
memberMember 267324721-Aug-11 21:58 
Questionhow to pass base64binary Pin
rsobies1-Oct-06 22:49
memberrsobies1-Oct-06 22:49 
QuestionSOAP Error Pin
SolomonGnanaraj5-Aug-06 3:04
memberSolomonGnanaraj5-Aug-06 3:04 
AnswerRe: SOAP Error Pin
jlclua25-Sep-06 15:06
memberjlclua25-Sep-06 15:06 
Questionerror in the client Pin
jamni12319-Jul-06 18:31
memberjamni12319-Jul-06 18:31 
QuestionRe: error in the client Pin
SolomonGnanaraj5-Aug-06 3:03
memberSolomonGnanaraj5-Aug-06 3:03 
Generalthis code example Pin
johncodep22-Jun-06 9:11
memberjohncodep22-Jun-06 9:11 
QuestionUrgent Help:How to Use ProxyPort and Proxy Server Pin
mardan mustak12-Apr-06 2:49
membermardan mustak12-Apr-06 2:49 
QuestionHi.. what about Dataset as a return value?? Pin
walrusman29-Nov-05 19:11
memberwalrusman29-Nov-05 19:11 
Generalsolution for 0x800A1527 Pin
prosagar8-Sep-05 22:36
memberprosagar8-Sep-05 22:36 
GeneralRe: solution for 0x800A1527 Pin
amccool9-Sep-05 15:10
sussamccool9-Sep-05 15:10 
GeneralRe: solution for 0x800A1527 Pin
SrinivasV5-Jan-06 0:59
memberSrinivasV5-Jan-06 0:59 
GeneralRe: solution for 0x800A1527 Pin
dewins10-May-12 7:33
memberdewins10-May-12 7:33 
Generalsh SOAP Toolkit 3.0 Pin
mkharwadkar31-Jul-05 21:47
sussmkharwadkar31-Jul-05 21:47 
QuestionHow to get method names of the web service Pin
grinder13-Mar-05 22:49
membergrinder13-Mar-05 22:49 
GeneralSOAP C++ Pin
Pierre Cloutier6-Mar-05 3:53
memberPierre Cloutier6-Mar-05 3:53 
GeneralRe: SOAP C++ Pin
z11aalex17-Dec-08 6:02
memberz11aalex17-Dec-08 6:02 
QuestionHELP ME!!!why toolkit3.0 generate these bad XML for me? Pin
gxulg16-Jan-05 20:05
membergxulg16-Jan-05 20:05 
AnswerRe: HELP ME!!!why toolkit3.0 generate these bad XML for me? Pin
mehdi_tn12-Jul-05 23:31
membermehdi_tn12-Jul-05 23:31 
QuestionHTTPS? Pin
Nirav Doshi23-Sep-04 8:13
memberNirav Doshi23-Sep-04 8:13 
AnswerRe: HTTPS? Pin
nguyen Ngoc Tuan8-Jan-07 16:12
membernguyen Ngoc Tuan8-Jan-07 16:12 
AnswerRe: HTTPS? Pin
Nirav Doshi8-Jan-07 22:04
memberNirav Doshi8-Jan-07 22:04 
QuestionRe: HTTPS? Pin
SRANI9-Jun-08 6:00
memberSRANI9-Jun-08 6:00 
AnswerRe: HTTPS? Pin
Nirav Doshi9-Jun-08 6:44
memberNirav Doshi9-Jun-08 6:44 
QuestionRe: HTTPS? Pin
SRANI9-Jun-08 11:16
memberSRANI9-Jun-08 11:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170118.1 | Last Updated 3 Nov 2003
Article Copyright 2003 by Vipul Bansal
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid