Hi Check the attachment...and see if it helps u..
thanks kaushik

----- Original Message -----
From: "Vaibhav Joshi" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, April 15, 2002 7:38 PM
Subject: MS Soap Client


> Hi,
>  Can any one send me an example of MS SOAP CLIENT USING VB. AND CAN YOU
ALSO
> LET ME KNOW HOW ShOULD I GO ABOUT IT.
> V
>
> --------------------------------------------------------------------------
--
> --------
> Vaibhav Joshi
> Multicity
> tel: 703-790-0063, ext. 238 | fax: 703-790-3379
> e-mail: [EMAIL PROTECTED]
> http://www.multicity.com
>
> Voted "Best Chat" by Yahoo! Internet Life
> and proud to be part of the "100 Best Sites for 2001"
>
> ===========================================
> This email message is for the sole use of the intended recipient(s) and
may
> contain confidential and privileged information. Any unauthorized review,
> use, disclosure or distribution is prohibited.  If you are not the
intended
> recipient, please contact the sender by reply email and destroy all copies
> of the original message.
>
>
Title: PerfectXML.com - SOAP is really Simple
 PerfectXML.com
   Focus    Free Library    Info Bank    Software    News    PerfectXML
  You are here: home »» Info Bank »» Articles » SOAP is really Simple Thursday, 4 October 2001
 

Back to Articles Page      
        

SOAP is really Simple


Table of contents
Introduction
About Sample Application
The Client
The Server
Summary

Download source code for sample application

  • Introduction
    I still remember the day when I wrote my first DCOM (Distributed COM)What is DCOM? sample application, few years ago. I was really thrilled to see how simple it was to write an distributed application. The code was straightforward, but configuration needed some work (using DCOMCNFG.exe). Also, this DCOM application was not firewall friendly. Not just DCOM, but other Distributed Computing specifications (like CORBA, RMI, etc.) also have issues and complexities when firewalls are involved. What we need is really simple, solid protocol to facilitate distributed computing. It should be easy for the client to make calls to objects running on the server (a different machine, possibly on the internet and across the firewall boundaries) and get the results. Enter SOAP! A W3C specification based on two solid proven technologies (XML and HTTP).

    SOAP, or Simple Object Access Protocol is an XML-based object invocation protocol. SOAP was originally developed for distributed applications to communicate over HTTP and through corporate firewalls. SOAP defines the use of XML and HTTP to access services, objects and servers in a platform-independent manner.

    In this article, we'll learn how easy it is to write SOAP Web service and a client, that can communicate over internet without any firewall issues. Our server or Web service is an ASP Page and client is an Visual Basic 6.0 application.

  • About Sample Application
    Our client is an Visual Basic 6.0 Application, with a single form having two edit boxes to accept username and password. Here is how Visual Basic client looks like:
    Client Visual Basic 6.0 Application

    When clicked on Connect button, a method on the server (which is an ASP Page) is called which in turn returns result indicating successful or incorrect login, depending on input parameters with the method call. Visual Basic application gets the results and just pops up a message box indicating login success or failure.

    To call a method on the server, we build a XML packet (document/fragment) and post it to the server. The server (ASP Page) processes the input request, generates the result, again as an XML document and sends back to client as response. Please note that the username and password are hard-coded in the ASP page server code as PerfectXML and XML respectively (case-sensitive).

  • The Client
    The Visual Basic client accepts the username and password and calls DoLogin method on the server, passing username & password as method parameters. With SOAP, method call and input parameters needs to be XML-encoded, as below:

    <DoLogin>
       <UserName>PerfectXML</UserName>
       <Password>XML</Password>
    </DoLogin>


    According to SOAP specification, the above method call information needs to be enclosed in what is called as SOAP envelop, which is finally sent/posted to the server. The final SOAP request envelop is shown below:

    <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
       <SOAP:Header></SOAP:Header>
       <SOAP:Body>
         <m:DoLogin xmlns:m="urn:soapserver/soap:AuthorizationModule">
             <UserName>PerfectXML</UserName>
             <Password>XML</Password>
         </m:DoLogin>
       </SOAP:Body>
    </SOAP:Envelope>


    The Visual Basic client application simply builds the above method call SOAP envelop (as string) and now in order to post this to the server, we use XMLHTTPRequest object from MSXML. Here is the part of code which builds SOAP request envelop and sends it to the server using XMLHTTPRequest:

    Dim objXMLHTTP As New MSXML.XMLHTTPRequest
    Dim objOutputXMLDoc As New MSXML.DOMDocument

    Dim strMethodPkg As String
    Dim strMethodResultXML As String

    Dim iLoginResult As Integer

    strMethodPkg = "<SOAP:Envelope xmlns:SOAP=""http://schemas.xmlsoap.org/soap/envelope/"">"
    strMethodPkg = strMethodPkg & "<SOAP:Header></SOAP:Header>"
    strMethodPkg = strMethodPkg & "<SOAP:Body><m:DoLogin xmlns:m=""urn:soapserver/soap:AuthorizationModule"">"
    strMethodPkg = strMethodPkg & "<UserName>" & txtUserName.Text & "</UserName>"
    strMethodPkg = strMethodPkg & "<Password>" & txtPassword.Text & "</Password>"
    strMethodPkg = strMethodPkg & "</m:DoLogin></SOAP:Body></SOAP:Envelope>"

    objXMLHTTP.open "post", "http://127.0.0.1/soap/simplesoap.asp", False

    objXMLHTTP.setRequestHeader "Content-Type", "text/xml"

    objXMLHTTP.setRequestHeader "SOAPAction", "soapserver/soap:AuthorizationModule#DoLogin"

    objXMLHTTP.send strMethodPkg

    As mentioned earlier, the server for our sample application is an ASP Page. This ASP page is named simplesoap.asp and should be present in a virtual directory named soap. (You can keep the ASP page wherever you wish, just change the URL in the above client code.).

    Now let's have a look at our server application, simplesoap.asp.

  • The Server
    The server ASP page is very simple to understand - it uses MSXML DOM to get the username and password values from the input request XML document, maches those values, builds the result XML document/envelop and sends the response back to the client.

    Set objXMLDOM = Server.CreateObject("Microsoft.XMLDOM")

    objXMLDOM.load Request

    varUserName = objXMLDOM.selectSingleNode("SOAP:Envelope/SOAP:Body/m:DoLogin/UserName").Text
    varPassword = objXMLDOM.selectSingleNode("SOAP:Envelope/SOAP:Body/m:DoLogin/Password").Text

    if varUserName = "PerfectXML" and varPassword = "XML" then
    strResult = 1
    else
    strResult = -1
    end if

    strResultXML = "<SOAP:Envelope xmlns:SOAP=""http://schemas.xmlsoap.org/soap/envelope/""><SOAP:Header></SOAP:Header>"
    strResultXML = strResultXML & "<SOAP:Body><m:DoLoginResponse xmlns:m=""urn:soapserver/soap:AuthorizationModule"">"
    strResultXML = strResultXML & "<LoginResult>" & strResult & "</LoginResult></m:DoLoginResponse>"
    strResultXML = strResultXML & "</SOAP:Body></SOAP:Envelope>"

    Response.Write strResultXML

    The client receives the response. And since response from ASP page (method call) is again an XML document, the VB client app, loads the document and queries for result node's value. Depending on the result value, it then pops up either "login successful" or "login failure" message box. Here is rest of VB client code:
    strMethodResultXML = objXMLHTTP.responseText

    objOutputXMLDoc.loadXML strMethodResultXML

    iLoginResult = objOutputXMLDoc.selectSingleNode("SOAP:Envelope/SOAP:Body/m:DoLoginResponse/LoginResult").Text

    If iLoginResult > 0 Then
    MsgBox "Login Successful"
    Else
    MsgBox "Login Failed!"
    End If




  • Summary
    SOAP really is a way to build distributed application which are simple, extensible, and platform-independent. In this small article, we learned how SOAP works using a Visual Basic client application connecting to ASP page, acting as a server.

    If you would like to learn more about SOAP or have any question about SOAP, check out PerfectXML.com's exclusive section dedicated to SOAP. We'll continue to grow the SOAP resource center on PerfectXML.com. If you have any ideas/suggestions/comments, please direct them to [EMAIL PROTECTED].


What is DCOM?DCOM or Distributed COM is Microsoft's distributed computing protocol and is built on top of DCE RPC, an RPC protocol developed by the Distributed Computing Environment consortium and adopted and extended slightly by Microsoft to support communication between COM objects across machines. One of the main design goals of DCOM is location transparency - a client program invoking a remote procedure should use the exact same syntax used for local procedure calls.

  

Back to Articles Page      

All information on this site is for training only. We do not warrant its correctness or its fitness to be used. The risk of using it remains entirely with the user.

 

About us | Contact us | Ad Info | Link to us | Search | Site Guide | Privacy Policy
 ©2001 PerfectXML.com. All rights reserved.  Email comments to » [EMAIL PROTECTED]
Title: Simple Object Access Protocol: A Step-By-Step Approach


Home - What's New - Tools&Technologies - Resources - Books - Take&Use - VB Search Engine - Forum


Home - Tools&Technologies - XML and SOAP - SOAP: A Step-By-Step Approach

[Advertisement]

[Featured Book]

[Newsletter]

HTML Text

[Partners]

Acky.net is your one stop shop for all of your web
		developing needs


SOAP - Simple Object Access Protocol - is the hottest thing in XML development right now. It has a major role to play in Microsoft's next generation of Visual Studio, and it is the basis of their ".NET" strategy. If you're looking to write a bullet-proof SOAP service now, in VB6, then look no further than Microsoft's SOAP toolkit for VB; but if you really want to understand what SOAP is all about, then you need to get under the hood, and start building your own objects around the SOAP standard. This article aims to get you started.

In the article, we will create a simple SOAP service, and a client to access that service. The service will be in the form of an Active Server Page, which I have called soap.asp - it will need to live in the root directory of your Personal Web Service (by default c:\inetpub\wwwroot\) Our service will accept and process SOAP requests made by our client - a VB exe, with a single module, and a start-up Sub Main().

Simple Object Access Protocol: A Step-By-Step Approach
By Syd Egan

s we know, SOAP is a call-response mechanism, which operates in a client-server paradigm. The client (your application) makes a call to the server (a web server, somewhere on the internet), passing in parameters; and the server provides a response. Both call and response are transported in the form of XML documents. Therefore, to build our own example SOAP system, we need both a client and a server - a caller and a responder.

The example we will follow is a very simple one: we will build a service that will calculate the tax due on a sales transaction. In traditional VB terms well will create a function with the following definition:

Public Function GetSalesTax(ByVal pSalesTotal As Double) As Double
    GetSalesTax = pSalesTotal * 0.04
End Function

Crude, but effective (if you live in a state where the sales tax rate is 4%!)

This function defines a method name (GetSalesTax), a parameter (pSalesTotal - representing the total value of the sale) and a return value (the result of the function). In more traditional object-oriented terms, we might think of pSalesTotal as an "IN" parameter, and the GetSalesTax result as an "OUT" parameter. Quite straightforwardly: sales-total in; sales-tax out. A SOAP service can be thought of in terms of "IN" and "OUT" parameters - the client passes "IN" parameters to the server, and then receives the "OUT" parameters in return. So, in order to create our SOAP service, we need a server that will listen for requests to GetSalesTax, accompanied by "IN" parameters, and which will respond with "OUT" parameters, indicating the correct tax amount. Let's start with the client - the caller. How do we call the SOAP service to make our request.

The Client

In traditional VB terms, our request to the GetSalesTax function described above, would be something such as:

dblSalesTax = GetSalesTax(100)

Returning a value of $4.

If the GetSalesTax function was contained within an external object, such as an MTS server, then the call would need to reference the server DLL:

Dim objTax As New CTaxCalc
dblSalesTax = objTax.GetSalesTax(100)

In a SOAP system the call is little different, only the request is formatted as an XML document, which is passed up to the server. The appropriate document contains the same details as the MTS call -a method to call, and the parameter name and value.

<GetSalesTax>
    <SalesTotal>100</SalesTotal>
<GetSalesTax>

In order to ensure that the server can correctly identify and decrypt this method call, it is wrapped up in a larger document, called a SOAP envelope, which references the universal name-space of the SOAP envelope standard.

<SOAP:Envelope xmlns:SOAP="urn:schemas-xmlsoap-org:soap.v1">
    <SOAP:Header></SOAP:Header>
    <SOAP:Body>
        <GetSalesTax>
            <SalesTotal>100</SalesTotal>
        <GetSalesTax>

    </SOAP:Body>
</SOAP:Envelope>

Finally, to complete our SOAP request document, we will add a name-space reference to our method call, which points to the object which contains the method - the equivalent of the object declaration (Dim objTax As New CTaxCalc) in our MTS method call.

<SOAP:Envelope xmlns:SOAP="urn:schemas-xmlsoap-org:soap.v1">
    <SOAP:Header></SOAP:Header>
    <SOAP:Body>

        <m:GetSalesTax xmlns:m="urn:myserver/soap:TaxCalc">
            <SalesTotal>100</SalesTotal>
        </m:GetSalesTax>
    </SOAP:Body>
</SOAP:Envelope>

Now that we have built our SOAP request document, we are ready to send it to the server. The request is a simple HTTP post - just like posting a web form in your internet browser. Of course, your internet browser masks all the complexity of sending a form to a server; and in the longer-term .NET will mask this process from your VB code too. But for now, we need to do the job ourselves; and I have been using Microsoft's XML HTTP Request object to give me a helping hand. (The XMLHTTPRequest is an object within the MSXML class library (MSXML.DLL), and it comes with IE5.) Assuming that strEnvelope contains the XML document described above, the request is formatted thus:

Dim objHTTP As New MSXML.XMLHTTPRequest
Dim strEnvelope As String

'Set up to post to our localhost server
objHTTP.open "post", "http://localhost/soap/soap.asp"

'Set a standard SOAP/ XML header for the content-type
objHTTP.setRequestHeader "Content-Type", "text/xml"

'Set a header for the method to be called
objHTTP.setRequestHeader "SOAPMethodName", _
"urn:myserver/soap:TaxCalc#GetSalesTax"

'Make the SOAP call
objHTTP.send strEnvelope

'Get the return value
strReturn = objHTTP.responseBody

Now that we have sent our request, we move to the server, to see how we set up a SOAP service to listen and respond to our calls.

The Server

Our server needs to be configured to accept the HTTP post sent by the client. It will be noted that we direct the client's post to a URL on our local server - http://localhost/soap.asp. So our first job is to create this page, to listen for, and process, SOAP calls to our server. We know that our ASP will receive an XML document, in the form of an HTTP post, with a method name (GetSalesTax), and a parameter (SalesTotal). So, to write our basic listener service, all we need do is deconstruct the body of the request (the SOAP envelope) and pull out the value of the SalesTotal parameter.

The SOAP envelope posted by the client is contained in the body of the request, or in ASP terms the Request object; and because it is XML, we can load it into an instance of Microsoft's XMLDOM in our ASP. Soap.asp begins like this:

Set objReq = Server.CreateObject("Microsoft.XMLDOM")
objReq.Load Request

Thus objReq contains the SOAP envelope we created on the client, and we can extract the value of the SalesTotal parameter by running an XSL pattern query, using the SelectSingleNode method of the XML DOM object :

strQuery = "SOAP:Envelope/SOAP:Body/m:GetSalesTax/SalesTotal" 
varSalesTotal = objReq.SelectSingleNode(strQuery).Text

With the parameter extracted, we can make our calculation to get the sales-tax:

varSalesTax = varSalesTotal * 0.04

Now we have the return value for sales-tax - the response - ready to pass back to the client, but as with the request, we need to format this response correctly, in order to comply with the SOAP standard. The SOAP response envelope conforms to a format-type identical to the request. The only difference is that the "IN" parameter (SalesTotal, in our case) is replaced by an "OUT" parameter - SalesTax, and the method name indicates that the document is a response:

<SOAP:Envelope xmlns:SOAP="urn:schemas-xmlsoap-org:soap.v1">
    <SOAP:Header></SOAP:Header>
    <SOAP:Body>

        <m:GetSalesTaxResponse xmlns:m="urn:myserver/soap:TaxCalc">
            <SalesTax>4</SalesTax>
        </m:GetSalesTaxResponse>
    </SOAP:Body>
</SOAP:Envelope>

We can build up this document, either by string-concatenation, or by creating a new instance of a DOM, and appending the appropriate nodes.

Back on the client, the response is received, and can be decoded by extracting the appropriate node from the Envelope document:

Dim objReturn As New MSXML.DomDocument
objReturn.LoadXML strReturn

strQuery = _
"SOAP:Envelope/SOAP:Body/m:GetSalesTaxResponse/SalesTax"
dblTax = objReturn.SelectSingleNode(strQuery).Text

And that's it! A functional, compliant SOAP service in a few easy steps. Of course, the service that we have provided is far from sophisticated, but that is to miss the point. In the not-too-distant future, Visual Studio 7 will completely mask the implementation of SOAP; but I believe that there is value in understanding the way the engine turns beneath the hood. SOAP itself is a very simple protocol; and I hope you leave this article with a better understanding the infrastructure that lies behind SOAP, and the methodology through which SOAP-based component services are going to be provided in the future.

Appendix 1: VB Client Code

NB - This project contains a single module, with a Sub Main start-up object, and references the MSXML library. 

The code assumes you are running a local web server (localhost), and that soap.asp is located in the web root, as described below.

Sub Main()

   Dim objHTTP As New MSXML.XMLHTTPRequest
   Dim strEnvelope As String
   Dim
strReturn As String
   Dim
objReturn As New MSXML.DOMDocument
   Dim dblTax As Double
   Dim
strQuery As String

   'Create the SOAP Envelope
   strEnvelope = _
      "<SOAP:Envelope xmlns:SOAP=""urn:schemas-xmlsoap-org:soap.v1"">" & _
      "<SOAP:Header></SOAP:Header>" & _
      "<SOAP:Body>" & _
      "<m:GetSalesTax xmlns:m=""urn:myserver/soap:TaxCalculator"">" & _
      "<SalesTotal>100</SalesTotal>" & _
      "</m:GetSalesTax>" & _
      "</SOAP:Body>" & _
      "</SOAP:Envelope>"

   'Set up to post to our local server
   objHTTP.open "post", "http://localhost/soap.asp", False

   'Set a standard SOAP/ XML header for the content-type
   objHTTP.setRequestHeader "Content-Type", "text/xml"

   'Set a header for the method to be called
   objHTTP.setRequestHeader "SOAPMethodName", _
      "urn:myserver/soap:TaxCalculator#GetSalesTax"

   'Make the SOAP call
   objHTTP.send strEnvelope

   'Get the return envelope
   strReturn = objHTTP.responseText

   'Load the return envelope into a DOM
   objReturn.loadXML strReturn

   'Query the return envelope
   strQuery = _
      "SOAP:Envelope/SOAP:Body/m:GetSalesTaxResponse/SalesTax"
   dblTax = objReturn.selectSingleNode(strQuery).Text

   Debug.Print dblTax

End Sub

Appendix 2: ASP Server Code

This code resides in an ASP - Soap.asp, in the root directory of the web server.

<%

Set objReq = Server.CreateObject("Microsoft.XMLDOM")

'Load the request into XML DOM
objReq.Load Request

'Query the DOM for the input parameter
strQuery = "SOAP:Envelope/SOAP:Body/m:GetSalesTax/SalesTotal"
varSalesTotal = objReq.SelectSingleNode(strQuery).Text

'Calculate the sales tax
varSalesTax = varSalesTotal * 0.04

'Prepare the return envelope
strTmp = _
"<SOAP:Envelope xmlns:SOAP=""urn:schemas-xmlsoap-org:soap.v1"">" & _
"<SOAP:Header></SOAP:Header>" & _
"<SOAP:Body>" & _
"<m:GetSalesTaxResponse xmlns:m=""urn:myserver/soap:TaxCalc"">" & _
"<SalesTax>" & varSalesTax & "</SalesTax>" & _
"</m:GetSalesTaxResponse>" & _
"</SOAP:Body>" & _
"</SOAP:Envelope>"

'Write the return envelope
Response.Write strTmp

%>

Syd Egan is a Project Leader at ComponentSource
http://www.componentsource.com/
The Definitive Source Of Software Components


Please, post here only feedback for the article/tutorial/sample you have read above.
If you have any question and like to get an answer, post your messages in the Forum.

comments for Syd Egan
Sathyanathan Sundaram Saturday, March 24, 2001

Perpetual error message
Barney Monday, April 30, 2001

VB Module
Derrick Wednesday, May 02, 2001

explanation on TaxCalc component
mprb Thursday, May 03, 2001

Great example
Ray Carmody Monday, May 14, 2001

Best One
S Apte Monday, May 14, 2001

Great example
real term Sunday, May 20, 2001

Component
M.N.Arunkumar Thursday, June 28, 2001

Example a HUGE help.
Royden Friday, July 13, 2001

ERROR 91
Manoj Friday, July 13, 2001

Error 91 - object variable not set
Amin Monday, July 16, 2001

error 91.. solution doesn't work...
Manoj Monday, July 16, 2001

Soap does not work
jsevere Friday, July 27, 2001

Nice Example
Wesley Thursday, August 02, 2001

Good Example with some clarifications
Karthik Tuesday, August 07, 2001

Good example
Cesar Thursday, August 09, 2001

Exact what I needed
Abdullah Harput Tuesday, August 28, 2001

Worthless
Ned Robinson Tuesday, August 28, 2001

Worthless
Ned Robinson Tuesday, August 28, 2001

OK, I got it working
Ned Robinson Tuesday, August 28, 2001

Best I have seen
Partha Monday, September 03, 2001

Best I have seen
Partha Monday, September 03, 2001

It worked fine (local and remote)
Pablo Friday, September 21, 2001



Home - Tools&Technologies - XML and SOAP - SOAP: A Step-By-Step Approach

 

Home | What's New | Tools & Technologies | Resources | Books | Take&Use | VB Search Engine | Forum

Report about any problems and errors to [EMAIL PROTECTED]
Copyright © 1998 - 2001 by Oleg Gdalevich

Reply via email to