C++
  Home arrow C++ arrow Page 4 - Building A SOAP Client With Visual C++
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C++

Building A SOAP Client With Visual C++
By: Nauman Laghari
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 22
    2002-04-29

    Table of Contents:
  • Building A SOAP Client With Visual C++
  • Fundamentals of SOAP Programming
  • SoapSerializer
  • Demonstrating a sample SOAP client
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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.

    More C++ Articles
    More By Nauman Laghari


     

    C++ ARTICLES

    - Multiplying Large Numbers with Karatsuba`s A...
    - Large Numbers
    - Dijkstra`s Shunting Algorithm with STL and C...
    - Brief Introduction to the STL Containers
    - The Standard Template Library
    - Templates in C++
    - C++ Programmer Alerts
    - C++ Programming Tips
    - First Steps in (C) Programming, conclusion
    - First Steps in (C) Programming, continued
    - First Steps in (C) Programming, introduction
    - C++ Preprocessor: Always Assert Your Code Is...
    - C++ Preprocessor: The Code in the Middle
    - Programming in C
    - Temporary Variables: Runtime rvalue Detection






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT