Click here to Skip to main content
11,925,292 members (55,536 online)
Click here to Skip to main content
Add your own
alternative version


34 bookmarked

MS Soap Toolkit 2.0 - Oi! Where's My Rope Gone

, 6 Feb 2001
Rate this:
Please Sign up or sign in to vote.
Using the high level API to send and receive SOAP messages in MFC
<!-- Link to source file download -->
  • Download MFC Calculator Client source files - 28 Kb
  • <!-- Link to demo file download -->
  • Download Demo ATL object and Web Service MFC client - 57 Kb
  • <!-- Article image -->

    Sample Image - calc_eg.gif

    <!-- Add the rest of your HTML here -->


    This is true - the day after I had completed converting ROPE.dll to work for my Win98 users, the Microsoft Soap Toolkit 2.0 arrives! Not only does the new toolkit work on more flavours of Windows but it has all changed.

    So OK, now I can get down to the real work of providing my users with great new Web Services using a single DLL set, but hang on where's the CPP samples??? Yet again, a new technology blighted by VB only samples! I decided as my first step in getting to grips with the new toolkit was to convert the samples to MFC, and here is the first. An MFC implementation using the high level Soap Client API. The first set of sample code uses the simple parameter types Calculator Service included with the Soap Toolkit. The second is a simple ATL object, client and ASP listener, to test passing strings around.

    Getting Started

    Before starting you should follow the instructions in the SOAP Toolkit samples.htm file. First, you will need to create a virtual directory on your web server. Then, you will need to create the ClcVBSrv DLL. The VB project can be found in the samples/ClcVBSrv folder under your SOAP Toolkit installation directory. After building the DLL, you will need to recreate the Web Services Description Language (WSDL) file and Web Services Meta Language (WSML) file, using wsdlgen.exe, to include the location of your web server. The ASP listener for this service does not need to be changed.

    The Project

    The project is a straight forward MFC dialog application. I have created a very simple interface similar to the one in the VB client.

    Including the SoapClient in the project

    The easiest way to include the SoapClient in an MFC application is by using COleDispatchDriver class. Basically the COleDispatchDriver class allows you to implement the client side of COM, providing access to an object's methods and properties.

    To add the SoapClient into the project, go to the Class Wizard. Click the 'Add Class' button and choose 'From a Type Library'. Then, locate MSSOAP1.dll. You will then be given a list of interfaces, contained within the DLL, to choose from. For the purposes of this simple project, I only needed the ISOAPClient interface. This adds two files to the project mssoap1.cpp and mssoap1.h.

    To use the SoapClient interface add a variable of type ISOAPClient, e.g.ISOAPClient * m_pClient

    Creating the ISOAPClient pointer

    As I have used a pointer for my SoapClient interface variable, two steps are required before it can actually be used. First, create a new pointer of type ISOAPClient. This creates a C++ wrapper for the object. Then create an IDispatch object which is automatically attached to our wrapper.

    //Allocate a new SoapClient pointer
    m_pClient = new ISOAPClient;
    //Now create the SoapClient pointer

    The CreateDispatch function handles the creation of the IDispatch pointer for us. We just need to supply the ProgId (in this case MSSOAP.SoapClient) of the object we want to use.

    Note: You can create a version dependant instantiation by including the version (e.g. "MSSOAP.SoapClient.1") This is something I have never found a need for!

    After creating the SoapClient, initialise it using the mssoapinit function passing the name of the server, port and WSML file.

    m_pClient->mssoapinit("", "CalcVB", "CalcVBPortType", NULL);

    Calling the Web Services functions

    So we have got our SoapClient ready to use, but how do we call the services functions. In this case, simply calling m_pClient->Add(23.34, 34.2 ) will cause a compiler error. The application needs to know something about the functions. To use the Web Services functions, a function header and body needs to be declared. Using the Add function as an example the header and body look like this

    //Function header
    double Add(double dblA, double dblB, DISPID dispid);
    //Function body
    double ISOAPClient::Add(double dblA, double dblB, DISPID dispid)
    	double result;
    	static BYTE parms[] =
    		VTS_R8 VTS_R8;
    	InvokeHelper(dispid, DISPATCH_METHOD, VT_R8, (void*)&result, parms, dblA, dblB);
    	return result;

    The function itself takes as parameters two doubles and returns a double. I have added the dispid parameter to the function to pass the dispatch id of the function I am calling. The function body uses InvokeHelper to call the Add function. The InvokeHelper function is fairly easy to use. Full details on using this function can be found in the MSDN documentation.

    I have added these functions to the mssoap cpp and header files, although you could declare them elsewhere and pass in the SoapClient pointer/object.

    Note: If you do add additional functions to the wizard created files, care must be taken when adding further interfaces from the COM object, as the additional functions maybe deleted.

    This only leaves getting the dispatch id of the function to call.

    In actual fact, a quick and dirty method for calling the functions is to use the internal index of the OLE controller. This will generally index the functions in the order that they are numbered. Indexing them from -1 upwards. This will probably work nine times out of ten. However, it is not a rule of COM that the controller must do this and so the result cannot be guaranteed.

    So, I have created a function to get the dispid that I need.

    //Function to get the Dispatch ID of the function we want to call
    //Pre : strFXName is the name of the function
    //Post: returns the dispath id of the function 
    DISPID CDemo1Dlg::GetDispid(CString strFxName)
    	OLECHAR * name = strFxName.AllocSysString();
    	DISPID dispid;
    	//Using the dispatch pointer member get the dispatch id of the required
    	//function from the interface
    	m_pClient->m_lpDispatch->GetIDsOfNames(IID_NULL, &name, 1, GetUserDefaultLCID(), &dispid);
        return dispid;

    This function takes the name of the Web Service function we want to call and retrieves its dispatch id.


    So OK, there's a whole lot more code here than in the VB sample. And no, the high level API approach to SOAP messaging is not the most flexible. However, if you just want to get going, using your language of choice, and to start including SOAP in your MFC projects then this is a relatively painless way of doing it.


    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

    Nic Oughton
    Architect SPTS Technologies
    United Kingdom United Kingdom
    Nic has been programming for Windows and devices for many, many years using a wide variety of languages and methodologies including C,C++,C#,.Net,MFC.

    He is employed as the Global Applications Manager for SPTS Technologies ( a world leading supplier of capital equipment to the semi-conductor industry. Responsible for the smooth running and development of all of SPTS's business systems Nic still gets to, occasionally, write a little code!

    Currently pursuing all things mobile Nic is particularly interested in Windows phone development and cloud computing.

    Nic has a varied background including an honours degree in Drama, 18 months as a mechanical buyer and stints as lead singer in several (unknown) bands. He lives in Bristol, UK with his wife and two children.

    You may also be interested in...

    Comments and Discussions

    Questionsetting proxy Pin
    wunderbart31-Jul-06 1:14
    memberwunderbart31-Jul-06 1:14 
    GeneralMSSOAP1.dll program problem in VC++ Pin
    smpshehan9-Jun-05 17:46
    membersmpshehan9-Jun-05 17:46 
    Questionhow to use startHeaderElement for my soap message? Pin
    smpshehan9-Jun-05 2:15
    membersmpshehan9-Jun-05 2:15 
    GeneralOleException Pin
    utekii@yahoo.com7-Jan-05 6:48
    memberutekii@yahoo.com7-Jan-05 6:48 
    GeneralRe: OleException Pin
    smpshehan9-Jun-05 2:49
    membersmpshehan9-Jun-05 2:49 
    GeneralRe: OleException Pin
    Anonymous9-Jun-05 15:48
    sussAnonymous9-Jun-05 15:48 
    GeneralDitched Soap 3.0 Pin
    LikePork8-Sep-04 12:09
    memberLikePork8-Sep-04 12:09 
    QuestionWindows XP can not send big xml file throught SOAP??? Pin
    sue15962020-Aug-04 4:31
    membersue15962020-Aug-04 4:31 
    QuestionSOAP ..needs COM or .NET ??? Pin
    hittmann4@hotmail.com8-Jul-04 22:07
    memberhittmann4@hotmail.com8-Jul-04 22:07 
    GeneralMSSOAP.SoapClient Pin
    miss_mystikal30-May-04 23:41
    sussmiss_mystikal30-May-04 23:41 
    QuestionParameter names? Pin
    Tony Truong21-Feb-04 7:40
    memberTony Truong21-Feb-04 7:40 
    QuestionDeleting after use? Pin
    tobylang31-Dec-02 6:34
    membertobylang31-Dec-02 6:34 
    GeneralUsing a string Pin
    tobylang23-Dec-02 12:17
    membertobylang23-Dec-02 12:17 
    GeneralSoap toolkit 2.0 Pin
    Anonymous21-Apr-02 8:47
    memberAnonymous21-Apr-02 8:47 
    GeneralNo installation at all! Pin
    om30-Jan-02 3:05
    memberom30-Jan-02 3:05 
    GeneralNo rope.dll at all Pin
    Marleen Körner22-Nov-01 21:06
    memberMarleen Körner22-Nov-01 21:06 
    GeneralRe: No rope.dll at all Pin
    Zekester11-Jan-02 6:00
    memberZekester11-Jan-02 6:00 
    GeneralRe: No rope.dll at all Pin
    Anonymous12-Sep-02 19:54
    sussAnonymous12-Sep-02 19:54 
    GeneralC++ Documentation Pin
    E. Brown26-Jul-01 14:15
    memberE. Brown26-Jul-01 14:15 
    GeneralRe: C++ Doc. MSSoaptoolkit 2.0 Pin
    kondi23-Nov-01 2:19
    memberkondi23-Nov-01 2:19 
    GeneralI receive one error... Pin
    Adrian Bacaianu31-May-01 3:23
    memberAdrian Bacaianu31-May-01 3:23 
    GeneralRe: I receive one error... Pin
    d@hotman.com23-Nov-01 2:10
    memberd@hotman.com23-Nov-01 2:10 
    GeneralAutomation method calls... Pin
    Paul Wolfensberger12-Jan-01 4:33
    memberPaul Wolfensberger12-Jan-01 4:33 
    GeneralRe: Automation method calls... Pin
    Nic Oughton12-Jan-01 6:30
    memberNic Oughton12-Jan-01 6:30 
    GeneralRe: Automation method calls... Pin
    Paul Wolfensberger12-Jan-01 9:41
    memberPaul Wolfensberger12-Jan-01 9:41 

    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
    Web03 | 2.8.151126.1 | Last Updated 7 Feb 2001
    Article Copyright 2001 by Nic Oughton
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid