Click here to Skip to main content
12,823,439 members (46,265 online)
Click here to Skip to main content
Add your own
alternative version


25 bookmarked
Posted 22 Jun 2007

WebService Call From VC++6.0

, 22 Jun 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
Useful for beginners who want to call Webserive from VC6.0


This article is useful for those who have never worked with WebService call from VC++ and they want to know how to send a request and get a response? This is my first application which I have created for learning purposes.


I have referred to one CodeProject article. For WebService call, we require two things: one is that WebService must be created before calling it and the other is this VC++ application which calls it.

Using the Code

First of all, I would like to give you a brief on how to create a WebService. I am a System developer, that's why I don't have that good knowledge of creating a Webservice. You need to start Visual 2005, then File ->New-> website-> ASP.NET webservice. Then one default function will be created by the browser. Inside that function, you need to write some functionality that you want to take as request and return something on input basis. I have taken name as input and return address as per input name. That's why you can see Chaitanya name inside the XML code which I am posting on that link. Once the web service is created, you need to publish your site (which you can do using Inet manager).

Here is the code which I have used for posting a request and getting a response from WebService.

// Any source code blocks look like this
IXMLHttpRequestPtr httpReq( _uuidof(MyXMLHTTPRequest));
 _bstr_t  HTTPMethod ;
 _variant_t noAsync = _variant_t( (bool)false );
 CString strUserName = "mahesh"; // this one is user name of webservice machine
 vUser.vt = VT_BSTR;
 vUser.bstrVal = strUserName.AllocSysString();
 CString strPass = "gtl=11"; // this is system password
 VARIANT vPassword;
 vPassword.vt = VT_BSTR;
 vPassword.bstrVal = strPass.AllocSysString();
 HTTPMethod = _bstr_t( "POST" );
// http://gtl-334/XmlTesting/Service.asmx this is url as webservice.
 httpReq->open(HTTPMethod ,
 httpReq->setRequestHeader("Content-Type", "application/soap+xml");
 CString szRequest;
 szRequest = "<?xml version=\"1.0\" encoding=\"utf-8\"?> \
<soap12:Envelope xmlns:xsi=\"\" 
	xmlns:soap12=\"\"> \
    <HelloWorld xmlns=\"\"> \
 VARIANT vRequest;
 vRequest.vt = VT_BSTR;
 vRequest.bstrVal = szRequest.AllocSysString();
 httpReq->send(vRequest); // sending to that URL
 BSTR strText;
 _bstr_t bsResponse = httpReq->responseText; //receiving reply from web service

One very important thing is that we need to import MSXML.dll which you can see in the code in stdafx.h and "using namespace MSXML;" line in file.

Points of Interest

You can advise me on how to improve this article so that I can also learn new things. If you have any queries, you can post a message. I will try to solve it, and that way I will also learn new things in this area. You can mail me at


  • 22nd June, 2007: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

chaitanya shah
Technical Lead Tata Consultancy Servcies
India India
I have experience in iOs, Objective C,Java,C++/Vc++ 6.0,vc.Net,MFC,ATL,COM,WTL.

You can contact me on if you have any query.

You may also be interested in...

Comments and Discussions

Questionmsxml6r.dll cannot be loaded Pin
ArvindRSingh1-Sep-11 6:11
memberArvindRSingh1-Sep-11 6:11 
GeneralAssertion is coming when i use the same code Pin
Member 35010954-Jun-09 2:03
memberMember 35010954-Jun-09 2:03 
GeneralRe: Assertion is coming when i use the same code Pin
chaitanya shah11-Jun-09 4:22
memberchaitanya shah11-Jun-09 4:22 
GeneralYou can also import a WSDL file - it's a little easier to maintain Pin
jimbosetwe6-Nov-08 4:41
memberjimbosetwe6-Nov-08 4:41 
If you turn on CLR (right-click your project in solution explorer, go to properties, first page should have a selection for common language runtime - set to /clr.
Close & reopen solution (sometimes setting clr doesn't always take effect immediately for me) - then go to Project -> Add web reference
Enter the URL of your Web service file - it shoud figure out what your WSDL file is and import it. The system will then auto-generate a .h file that you can import into your classes - the .h file has the functions listed in your webservice and provides a straightforward method for sending & receiving data from them.

Please note that all of the calls will need to be made using System data types - i.e. get used to using gcnew.
GeneralRe: You can also import a WSDL file - it's a little easier to maintain Pin
chaitanya shah11-Jun-09 4:27
memberchaitanya shah11-Jun-09 4:27 
Questionhow can send to the web service xml data Pin
nabeel826-Oct-08 23:04
membernabeel826-Oct-08 23:04 
AnswerRe: how can send to the web service xml data Pin
chaitanya shah11-Jun-09 4:32
memberchaitanya shah11-Jun-09 4:32 
Questionwhat if a out parameter of a web service is a dataset, how will we handle in VC++ Pin
cooldeo18t18-May-08 16:24
membercooldeo18t18-May-08 16:24 
AnswerRe: what if a out parameter of a web service is a dataset, how will we handle in VC++ Pin
chaitanya shah21-May-08 2:37
memberchaitanya shah21-May-08 2:37 

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
Web01 | 2.8.170308.1 | Last Updated 22 Jun 2007
Article Copyright 2007 by chaitanya shah
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid