Home arrow C++ arrow Page 2 - Building A SOAP Client With Visual C++

Building A SOAP Client With Visual C++

SOAP, or Simple Object Access Protocol, is the backbone of web services and a variety of new technologies. In this article Nauman shows us how to create a simple SOAP client with Visual C++. He describes several methods found in the SOAP toolkit, and finishes off by creating a SOAP client that checks whether or not a Yahoo user is currently online.

Author Info:
By: Nauman Laghari
Rating: 4 stars4 stars4 stars4 stars4 stars / 35
April 29, 2002
  1. · Building A SOAP Client With Visual C++
  2. · Fundamentals of SOAP Programming
  3. · SoapSerializer
  4. · Demonstrating a sample SOAP client
  5. · Conclusion

print this article

Building A SOAP Client With Visual C++ - Fundamentals of SOAP Programming
(Page 2 of 5 )

I'll start this article with an introduction of the classes involved in a basic SOAP Application. Before that however, we have to import the required type libraries so that our program will be able to use the SOAP classes.

Importing Type libraries
All of the objects and interfaces used in SOAP are found in mssoap1.dll. This file is installed with the Microsoft SOAP Toolkit 2.0. You can find this file in "C:\Program Files\Common Files\MSSoap\Binaries\MSSOAP1.dll". All you have to do to import this file into your source is use an #import directive, which is used to incorporate information from a type library. The contents of the type library are converted into COM smart pointers, which describe the COM interfaces.

SOAP relies completely on XML as its data format, therefore the Microsoft XML Parser is also needed for XML processing. The Microsoft XML parser is included in msxml3.dll where # is the version number. Again, you need to import this file before importing mssoap1.dll:

#import "msxml3.dll"

using namespace MSXML2;

#import "C:\Program Files\Common Files\MSSoap\Binaries\MSSOAP1.dll" \
exclude("IStream", "ISequentialStream", "_LARGE_INTEGER", \
using namespace MSSOAPLib;

That's all what is needed to include all class definitions required to develop a SOAP program. There are three steps that are necessary for making a SOAP client:
  1. Specifying and connecting with the web service.
  2. Preparing and sending the message.
  3. Reading the response back from the service.
Now lets take a look at the classes involved. The code that follows are the classes that we will use to develop a basic SOAP Client:

The first thing that's required for any client in a client / server application is to connect with the server. The SoapConnector class implements the protocol that is used as a transport between the client and the server. SoapConnector acts as an abstract class for defining interfaces for implementing other protocols. That is for the fact that SOAP is not limited to a specific protocol, as you'll see that some implementations also support MSMQ, MQ Series, SMTP and TCP/IP Transports. For the sake of simplicity however, I am demonstrating the use of HTTP Transport, which is implemented by the HttpConnector class available with the Microsoft SOAP Toolkit 2.0.

The steps involved in using SoapConnector class
Firstly, creating a object to SoapConnector:

ISoapConnectorPtr connector; Connector.CreateInstance(__uuidof(HttpConnector));

Then specifying the Web Service Address. Next, we have to define the web service that we are using as a client. The service is specified using the Property (an attribute of HttpConnector). There are two things to specify when dealing with this attribute: which property we are referring to, and the value of the respective property type. Here, for specifying the web service, we use the EndPointURL property:

Connector->Property ["EndPointURL"] = "some url pointing to web service";

The following table provides a list of properties (The property names are case sensitive):




The password used for end point authentication.


The user name used for end point authentication.


The end point URL.


The password used for proxy authentication.


The port of the proxy server to use.


The IP address or host name of the proxy server.


The user name used for proxy authentication.


The value used in the "SoapAction" HTTP header. This property can be set only from the low-level API. It is ignored if the property is set using the ConnectorProperty property of the SoapClient interface (high-level API)


A string identifying the client certificate to use for the Secure Sockets Layer (SSL) protocol, if any. The syntax is: [CURRENT_USER | LOCAL_MACHINE\[store-name\]]cert-name with the defaults being CURRENT_USER\MY (the same store that Microsoft Internet Explorer uses).


The timeout for HttpConnector. This timeout is in milliseconds.


A Boolean property that specifies whether a to use a proxy server. By default, this property is set to False indicating that a proxy server should not be used. Set this property to True if you want to use a proxy server. If you set this property to True and don't specify the ProxyServer property, then the HttpConnector uses the proxy server set in the default settings of Microsoft® Internet Explorer. In this release, the HttpConnector ignores the "Bypass Proxy" settings in Internet Explorer.


A Boolean value (True or False) that specifies the use of SSL. If this property is set to True, the HttpConnector object uses SSL connection regardless of whether HTTP or HTTPS is specified in the WSDL. If this property is set to False, the HttpConnector object will use SSL connection only if HTTPS is specified in the WSDL.

Next, we need to connect with the Web Service. The connect method of HttpConnector is used to initialize the SoapConnector object and actually prepares a connection with the service:


After connecting with the server, we need to specify the action that we are going to perform on the web service. To specify the Action, we again use the Property attribute of the SoapConnector:

Connector->Property ["SoapAction"] = "some uri";

After connecting with the service and specifying other details, we signal the start of a SOAP message being sent to the server. This function must be called before calling any other method of the SoapSerializer ( which is used to prepare message):


After finishing with the message, we must call the EndMessage() function to actually send the message to the service:

[ message preparation code ]

This is all that is needed to actually connect with the service. In the next part, we will look at how to create and prepare a message.
blog comments powered by Disqus

- Intel Threading Building Blocks
- Threading Building Blocks with C++
- Video Memory Programming in Text Mode
- More Tricks to Gain Speed in Programming Con...
- Easy and Efficient Programming for Contests
- Preparing For Programming Contests
- Programming Contests: Why Bother?
- Polymorphism in C++
- Overview of Virtual Functions
- Inheritance in C++
- Extending the Basic Streams in C++
- Using Stringstreams in C++
- Custom Stream Manipulation in C++
- General Stream Manipulation in C++
- Serialize Your Class into Streams in C++

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials