C++
  Home arrow C++ arrow Page 3 - 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++ - SoapSerializer


    (Page 3 of 5 )

    The SoapSerializer object is used to build a SOAP message to be sent to the service. The SoapSerializer object must be connected with the SoapConnector object before communicating with the server. To interconnect these two objects, we need to call the Init method of the SoapSerializer object. This method takes a single argument, which is the InputStream (the stream the sends data to the server):

    // Creating a SoapSerializer object and initializing it with InputSTream

    ISoapSerializerPtr Serializer; Serializer.CreateInstance(_uuidof(SoapSerializer)); Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));


    Before looking into other functions of SoapSerializer, let's take a look at a sample SOAP request to get an idea of what we are building in our code:

    <SOAP: Envelope xmlns:SOAP="soap namespace">
    <SOAP:Body>
    <m:someMethodName xmlns:m="some namespace">
    <someParameter> someParameterValue </someParameter>
    <m:someMethodName>
    </SOAP:Body>
    </SOAP: Envelope>


    A soap request is simply encapsulated into tags. The <Envelope> tag is the main tag of this SOAP Document. A SOAP message is always encapsulated in an envelope. The envelope contains a message body, which is specified by a <Body> tag. The body contains the actual request. In C++, we have the appropriate methods to create these tags and specify any values for them. The following code demonstrates the use of these methods:

    Serializer->startEnvelope("SOAP","","");
    // begins an element in a SOAP message, first argument defines the namespace, if it

    // is empty then SOAP-ENV is used by default, the second and the third argument defines the URI

    // and the Encoding Type respectively Serialzier->startBody("");

    // begins the <Body> element in the message, the first argument defines the encoding style Uri,

    // by default it is NONE.
    Serializer->startElement("someMethodName","","","m");

    // Begins a child element into the body element of a SOAP message, the first parameter is the

    // element name, the second parameter is the Uri, third is encoding style and the last element

    // is the namespace for the element.
    Serializer->WriteString("someParameterValue")

    // writes the value of an element.


    All the functions shown above that start with startXXX have their equivalent endXXX function to end the element as well. After finishing with the message, the connector's endMessage() method is called to actually send the message as described above.

    We have now connected with the service, prepared our request and sent it to the service. The next and the final step is to read the response from the server, which is what we will look at now.

    SoapReader
    This object reads the response from the service and parses the incoming message into the DOM for further processing. Following is a sample SOAP Response from the service:

    <SOAP: Envelope xmlns:SOAP="soap namespace">
    <SOAP:Body>
    <m:someMethodNameResponse xmlns:m="some namespace">
    <return> someResult </return>
    <m:someMethodNameResponse>
    </SOAP:Body>
    </SOAP: Envelope>


    Before calling any functions to get the result, we connect with the OutputStream to actually read the response in a SoapReader object (An OutputStream receives data from the service):

    // code to create a SOAPReader object and connecting with the outputstream

    ISoapReaderPtr Reader; Reader.CreateInstance(_uuidof(SoapReader)); Reader->Load(_variant_t((IUnknown*)Connector->OutputStream));

    // the load method can also accept an XML Document File or String


    After loading the response into our SoapReader object, we get the result by calling the RPCResult property of SoapReader object. But RPCResult doesn't return the actual result; it returns the first child element of the first entry in the <Body> element. We get the result by calling the text property:

    Reader->RPCResult->text

    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 2 hosted by Hostway
    Stay green...Green IT