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.
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:
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:
Specifying and connecting with the web service.
Preparing and sending the message.
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:
SoapConnector 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:
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: