Click here to Skip to main content
13,861,006 members
Click here to Skip to main content
Add your own
alternative version


59 bookmarked
Posted 31 Mar 2004

SOAP client for C++

, 31 Mar 2004
Rate this:
Please Sign up or sign in to vote.
A base class to ease the work of calling a webservice in C++.


While creating web service and consuming it are very easy and intuitive in the .NET world, sometimes we still need to handle it in legacy systems. Several days ago, I faced a problem to call a web service in my old VC6 project. I Googled the web and realized that MS SOAP SDK will be the solution. Being familiar with C# language, going back to C++ is kind of frustrating, especially when handling COM interfaces. So I decided to write a helper class to ease the work of calling a web service, which is attached here.

The base class

The base class is called SoapClientBase, which is for inheritance only, implements most tasks to talk with the SOAP SDK. I will rather not talk a lot about the code of the base class. Instead, I'll give the steps about how to write an inherited class. The code of the base class is short, take a look at it for yourself if you want.

The inherited class

The code of the inherited class is even shorter. Here is the complete code of my class:

#pragma once
#include "SoapClientBase.h"

class AuthServiceClient : public SoapClientBase
 AuthServiceClient(void) : SoapClientBase()
  Init("<A href="http://localhost/AuthService/AuthService.asmx?wsdl">http://localhost/AuthService/AuthService.asmx?wsdl</A>", "AuthService", "");

 bool IsAuthorized(LPCTSTR username, LPCTSTR password)
  _variant_t varParams[2] = {  password, username };
  _variant_t varResult;
  m_hr = Invoke(L"IsAuthorized", varParams, 2, &varResult);
  return VARIANT_TRUE == varResult.boolVal;

The signature of my webservice method (C#) is:

public bool IsAuthorized(string username, string password);

As you have already seen, all that an inherited class should do is to call Init function in the constructor (or you might choose to call it explicitly outside the class), and then wrap all the web methods in local functions. You have to write all the wrap functions manually, but it's not hard to do. One thing that you should note here is that the parameter order should be reversed in the parameter array.

How to call

After you implemented the inherited class, use it to call the webservice almost the same way as you might do in C#. Here's an example:

AuthServiceClient service;
bool bResult = service.IsAuthorized(strName, strPassword);

Very simple, isn't it:)


First of all, SOAP Toolkit3.0 SDK or SOAP Toolkit3.0 Redistributable must be installed. The base class file contains the import instruction to load the SOAP DLL. You might have to change the path if you installed the SDK in another place.

The base class does not depend on MFC nor ATL. Instead, I copied a little code from ATL to make life easier:) Therefore, you can use this class anywhere, no matter which library the application uses.

Okay, that's all. The code is very short, so don't expect too much :) The point is: it makes my life easier. And I hope it makes your life easier too. Happy programming!


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

Neil Yao
China China
I'm a chinese programer living in Shanghai, currently working for a software company whose main business is to deliver computer based testing. Software simulation for computer based testing and certifications is my main responsibility in this company. Execpt for software development, I like out-door activities and photography. I am willing to make friends in China and all over the world, so contact me if you have anything in common with meSmile | :)

You may also be interested in...

Comments and Discussions

QuestionSOAP Toolkit3.0 SDK Pin
Member 1300255322-Nov-17 5:43
memberMember 1300255322-Nov-17 5:43 
Questionsame problem Pin
monimon15-Mar-13 7:22
membermonimon15-Mar-13 7:22 
tahar12-Mar-13 7:46
membertahar12-Mar-13 7:46 
QuestionCoCreateInstance Failed Pin
Lianchang_Mou29-Feb-12 19:03
memberLianchang_Mou29-Feb-12 19:03 
GeneralNo Deserializer found Error Pin
denemeew21-Sep-10 5:08
memberdenemeew21-Sep-10 5:08 
GeneralCannot create soap client object ! Pin
Battosaiii7-Feb-10 23:52
memberBattosaiii7-Feb-10 23:52 
GeneralRe: Cannot create soap client object ! Pin
Rahul B S15-Mar-10 21:45
memberRahul B S15-Mar-10 21:45 
GeneralRe: Cannot create soap client object ! Pin
levashoff28-May-10 15:29
memberlevashoff28-May-10 15:29 
GeneralRe: Cannot create soap client object ! Pin
keatsin18-Feb-11 16:52
memberkeatsin18-Feb-11 16:52 
GeneralFacing Problem in calling C# Web service Pin
Binni shah28-Nov-09 0:12
memberBinni shah28-Nov-09 0:12 
GeneralHELP!!! Pin
newhis26-Nov-09 21:10
membernewhis26-Nov-09 21:10 
QuestionRe: HELP!!! Pin
Rahul B S15-Mar-10 21:38
memberRahul B S15-Mar-10 21:38 
GeneralRe: HELP!!! Pin
winstond14-Apr-10 19:55
memberwinstond14-Apr-10 19:55 
GeneralRe: HELP!!! Pin
MedXLnce22-Oct-10 9:55
memberMedXLnce22-Oct-10 9:55 
GeneralRe: HELP!!! Pin
MedXLnce22-Oct-10 9:54
memberMedXLnce22-Oct-10 9:54 
GeneralRe: HELP!!! Pin
Nicholas Bowen19-Jan-12 14:53
memberNicholas Bowen19-Jan-12 14:53 
Generalcool Pin
Aung Sithu10-Feb-09 17:29
memberAung Sithu10-Feb-09 17:29 
GeneralError compiling SoapClientBase.h Pin
qwertypik28-Jan-09 4:55
memberqwertypik28-Jan-09 4:55 
GeneralRe: Error compiling SoapClientBase.h Pin
8200151819-Aug-09 20:47
member8200151819-Aug-09 20:47 
QuestionSee this subject in simple-Chinese code Pin
ShinGoZhang15-Dec-08 15:24
memberShinGoZhang15-Dec-08 15:24 
AnswerRe: See this subject in simple-Chinese code Pin
ShinGoZhang15-Dec-08 15:26
memberShinGoZhang15-Dec-08 15:26 
QuestionHow to declare at MFC if webservice function return a recordset Pin
otcinvestor27-Aug-07 7:26
memberotcinvestor27-Aug-07 7:26 
GeneralMessage Removed Pin
15-Aug-07 7:38
memberFranco Amato15-Aug-07 7:38 
Generalneed help Pin
fllsm31-May-07 18:31
memberfllsm31-May-07 18:31 
gbjbaanb6-Nov-07 8:54
membergbjbaanb6-Nov-07 8:54 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190214.1 | Last Updated 1 Apr 2004
Article Copyright 2004 by Neil Yao
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid