Click here to Skip to main content
13,400,969 members (39,589 online)
Click here to Skip to main content
Add your own
alternative version


36 bookmarked
Posted 31 May 2003

Invoking Web Services

, 31 May 2003
Rate this:
Please Sign up or sign in to vote.
How to invoke Web Services with Visual C++ .NET
<!-- Add the rest of your HTML here -->

Invoking a Web services with .NET

<!------------------------------- STEP 3 ---------------------------><!-- Add the article text. Please use simple formatting (


etc) -->


The .NET platform provides support for invoking web services. No additional tools or SDKs are needed. This platform is very easy to use.

Invoking a Web services with .NET

To show you how easy it is to build a web services consumer application. I am going to drive you in the various stages to build an application which is going to translate a text in a pre-defined language. The translation will be realized by a call to the Web service of Altavista "BabelFish". This sample is written with Visual Studio C++ .NET 2003.

First of all, create a new Visual C++ Project using MFC application template and on MFC application wizard choose a dialog based application and press Finish button.

Modify the new dialog box to have a control ComboBox and 2 EditBox as presented below.

dialog box to invoke BabelFish Web service

Add 3 members variables associated to each control.

<PRE lang=c++>CComboBox m_ctlLang; CString m_strSource; CEdit m_ctlResult;

If you have used the dialog box "Add Member Variable Wizard" you should see the code following in the member function DoDataExchange().

<PRE lang=c++>CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_COMBO1, m_ctlLang); DDX_Text(pDX, IDC_EDIT1, m_strSource); DDX_Control(pDX, IDC_EDIT2, m_ctlResult);

It is necessary to initialize the control ComboBox in the member function OnInitDialog() in the following way:

<PRE lang=c++>// TODO: Add extra initialization here // Add translation modes to the ComboBox m_ctlLang.AddString("en_fr"); m_ctlLang.AddString("en_it"); m_ctlLang.AddString("en_de"); m_ctlLang.AddString("en_pt"); m_ctlLang.AddString("en_es"); m_ctlLang.AddString("fr_en"); m_ctlLang.AddString("it_en"); m_ctlLang.AddString("de_en"); m_ctlLang.AddString("pt_en"); m_ctlLang.AddString("es_en"); m_ctlLang.AddString("ru_en"); m_ctlLang.SetCurSel(0);

Now we are going to integrate the Web service into our application. We select in the Project menu the choice "Add Web Reference...". In the field of the dialog box which appears type the following url: " dl " and click refresh or go button. The result which you have to obtain must be close to this one :

dialog box to invoke BabelFish Web service

Now click the "Add Reference" button

By verifying in the Solution Explorer View you will notice that a file in the name of WebService.h was added in Header Files. This file contains a class and all the member functions describing the Web service.

We are going to add in our project all the necessities to use this service.

1st step : add the following code in the Header File of your dialog box:

<PRE lang=c++>#include "WebService.h" using namespace BabelFishService;

Then Create an Event Handler on the button Translate, put in comment the call to the function OnOK() and write the following code:

// Initialize COM

// Create a pointer to Babel Fish Service
CBabelFishService *fish = new CBabelFishService();
// invoke Web Service
HRESULT hr = fish->BabelFish(bstrMode,bstrSource,&bstrResult);
if (FAILED(hr))
    // transfert response to a CString variable
    str = bstrResult;
    // copy texte translated to the EditBox
... / ...
// deleting the pointer to Babel Fish Service
delete fish;
// Uninitialize COM


The detail of the functioning of the service Web BabelFish is described on the Internet site. You will find so many others useful examples of Web services there.

Demo project

The demo project contains the complete code to invoke the BabelFish service that I covered in this article.


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

joel garel
Web Developer
France France
No Biography provided

You may also be interested in...


Comments and Discussions

ymalik10-Oct-07 14:37
memberymalik10-Oct-07 14:37 
Morten Fjeldstad10-Oct-07 21:51
memberMorten Fjeldstad10-Oct-07 21:51 
Rob Staveley31-Oct-07 9:05
memberRob Staveley31-Oct-07 9:05 
GeneralAuthentication problem Pin
mmagnani7121-Apr-05 0:30
membermmagnani7121-Apr-05 0:30 
GeneralDeserializing SOAP Pin
awidjaja24-Mar-05 10:34
memberawidjaja24-Mar-05 10:34 
GeneralRe: Deserializing SOAP Pin
eyadalagha2-Oct-07 0:13
membereyadalagha2-Oct-07 0:13 
bionet2-Dec-04 1:59
memberbionet2-Dec-04 1:59 
GeneralGet Data from user in Webservice Pin
DoesnotMAtter13-Nov-04 19:38
memberDoesnotMAtter13-Nov-04 19:38 
Generalerror SDL1013 Pin
bionet4-Nov-04 15:14
memberbionet4-Nov-04 15:14 
GeneralRe: error SDL1013 Pin
joel garel9-Nov-04 2:40
memberjoel garel9-Nov-04 2:40 
GeneralRe: error SDL1013 Pin
joel garel9-Nov-04 23:17
memberjoel garel9-Nov-04 23:17 
GeneralRe: error SDL1013 Pin
bionet11-Nov-04 7:29
memberbionet11-Nov-04 7:29 
Generalthe service is __gc ... Pin
Anonymous24-Sep-04 10:56
sussAnonymous24-Sep-04 10:56 
Generalcalling Webservice from , invoking methods by creating cookies Pin
baijumax13-Aug-04 21:10
memberbaijumax13-Aug-04 21:10 
QuestionCan the SoapClient Run under win98/me? Pin
Yu_Matrix1-Apr-04 21:08
memberYu_Matrix1-Apr-04 21:08 
QuestionDoes it require .Net frameware? Pin
Davidi22-Feb-04 21:19
memberDavidi22-Feb-04 21:19 
AnswerRe: Does it require .Net frameware? Pin
Shail_Srivastav7-Feb-06 8:16
memberShail_Srivastav7-Feb-06 8:16 
Generalusing VC++ 6.0 Pin
mattroos4-Dec-03 15:00
membermattroos4-Dec-03 15:00 
GeneralRe: using VC++ 6.0 Pin
joel garel6-Jan-04 5:37
memberjoel garel6-Jan-04 5:37 
GeneralRe: using VC++ 6.0 Pin
Anonymous26-Oct-04 11:46
sussAnonymous26-Oct-04 11:46 
QuestionCan i set dataset as the return value? Pin
Yu_Matrix5-Jul-03 0:54
memberYu_Matrix5-Jul-03 0:54 
Questionhow to dynamic change the URL of the service? Pin
Yu_Matrix5-Jul-03 0:12
memberYu_Matrix5-Jul-03 0:12 
GeneralATL Server, not .NET Framework Pin
Fazlul Kabir2-Jun-03 8:29
memberFazlul Kabir2-Jun-03 8:29 
Generalexciting Pin
Majid Shahabfar2-Jun-03 4:37
memberMajid Shahabfar2-Jun-03 4:37 
GeneralRe: exciting Pin
joel garel3-Jun-03 0:33
memberjoel garel3-Jun-03 0:33 

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 | Terms of Use | Mobile
Web03 | 2.8.180218.2 | Last Updated 1 Jun 2003
Article Copyright 2003 by joel garel
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid