Home arrow C++ arrow Page 4 - Building A SOAP Client With Visual C++
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
TABLE OF CONTENTS:
  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
SEARCH DEVARTICLES

Building A SOAP Client With Visual C++ - Demonstrating a sample SOAP client
(Page 4 of 5 )

For demonstrating the use of the SOAP classes that we've looked at in this article, I've used one of the services listed on http://www.xmethods.net/. The service indicates Yahoo Messenger's online presence. You can find the required details by following this URL. The only thing it expects is a method parameter i.e. the Yahoo user's login id. The result returned is a boolean value indicating 0 for offline and 1 for online. Other details are available on the site or by viewing the WSDL here.

Anyway, I guess the best way to learn something is to see the source code in action, so that's exactly what we will do now. Here's the C++ code for a console application that uses SOAP calls to find out if a Yahoo user is online:

#include

#import "msxml3.dll"
using namespace MSXML2;

#import "C:\Program Files\Common Files\MSSoap\Binaries\MSSOAP1.dll" \
exclude("IStream", "ISequentialStream", "_LARGE_INTEGER", \
"_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")

using namespace MSSOAPLib;

void main()
{
CoInitialize(NULL);

ISoapSerializerPtr Serializer;
ISoapReaderPtr Reader;
ISoapConnectorPtr Connector;

// Connect to the service
Connector.CreateInstance(__uuidof(HttpConnector));
Connector->Property["EndPointURL"] = "http://www.allesta.net:51110/webservices/soapx4/isuseronline.php";
Connector->Connect();

// Begin message
Connector->Property["SoapAction"] = "uri:allesta-YahooUserPing";
Connector->BeginMessage();

// Create the SoapSerializer
Serializer.CreateInstance(__uuidof(SoapSerializer));

// Connect the serializer to the input stream of the connector
Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));

// Build the SOAP Message
Serializer->startEnvelope("","","");
Serializer->startBody("");
Serializer->startElement("isuseronline","uri:allesta-YahooUserPing","","m");
Serializer->startElement("username","","","");
Serializer->writeString("laghari78");
Serializer->endElement();
Serializer->endElement();
Serializer->endBody();
Serializer->endEnvelope();

// Send the message to the web service
Connector->EndMessage();

// Let us read the response
Reader.CreateInstance(__uuidof(SoapReader));

// Connect the reader to the output stream of the connector
Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");

// Display the result
printf("Answer: %s\n", (const char *)Reader->RPCResult->text);
CoUninitialize();

}


As you can see, the code is fairly straight forward, and even if you haven't worked with C++ before, then I'm sure that you can figure out what the code does: Firstly, it connects to the remote server. Secondly, it creates the SOAP message and sends it. Lastly, it reads the response from the server and outputs it to the screen with printf.
blog comments powered by Disqus
C++ ARTICLES

- 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 
Support 

Developer Shed Affiliates

 




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