Thursday, 12 April 2012

Web Services: Exposing and Consuming

A Web Service is programmable application logic accessible via standard Web protocols. One of these Web protocols is the Simple Object Access Protocol (SOAP). SOAP uses standards based technologies (XML for data description and HTTP for transport) to encode and transmit application data.

Consumers of a Web Service do not need to know anything about the platform, object model, or programming language used to implement the service; they only need to understand how to send and receive SOAP messages (HTTP and XML).

Example:

We'll use an Add() method that accepts two Integers and returns their sum. Below is this simple Visual Basic logic:

Public Class MyMath
  Public Function Add(a As Integer, b As Integer) As Integer
    Return a + b
  End Function
End Class

We could use this class and its method as follows:

Dim mymath As new MyMath
Dim result As Integer
result = mymath.Add(10, 20)

To expose the above class, MyMath, as an ASP.NET Web Service we need to move the application logic into a *.asmx file. Just as we use the extension *.aspx for ASP.NET Pages, we use *.asmx to tell ASP.NET that the file is an ASP.NET Web Service.

After we created the *.asmx source file and add our application logic, we need to make a few more small changes:


 <%@ WebService Language="VB" Class="MyMath" %>
Public Class MyMath
  Public Function <WebMethod()>Add(a As Integer, b As Integer) As Integer
    Return a + b
  End Function
End Class

Exposing

The changes we've made to the *.asmx file include adding a WebService directive that names both the Language as well as the Class we're exposing as a Web Service. The WebService directive is required, as we must tell ASP.NET the class that contains the application logic. Next, we've added a <WebMethod()> attribute to our Add() function declaration. An attribute is a declarative code element that lets us change the behavior of our application logic without necessarily writing more code. In the case of the <WebMethod()> attribute, this tells ASP.NET that the method with this attribute is to be treated as 'Web callable'. Web callable in the sense that ASP.NET does the necessary work for this method to support SOAP.

Consuming

There are many ways to consume Web Services and have three examples. The first one uses HTTP-POST/HTTP-GET protocol and it has advantage to coexist with today’s application quite well. The second one uses SOAP Proxy Client Object generated by WSDL utility and it provides programmers with their familiar object modal that they call methods provided by the generated Proxy Interface. The final one uses SOAP standard request message and it parses SOAP response message with the help of XMLHTTP COM object that is installed by Microsoft XML Parser 3.0.
.
 

8 comments:

  1. Using soapUI?

    ReplyDelete
  2. Tree House Resort, Jaipur is the main common tree house resort around the local area loaning a serene and near nature experience to its visitors. This acclaimed resort is situated in the midst of slopes, woods and streams. It gives a perfect setting to a one of a kind ordeal.
    Visit: http://resortsnearjaipur.com/

    ReplyDelete

  3. Delhi is a center of delights for fun lovers and for those who want to enjoy each and every moment of life. If are you planning for a holiday celebration around Delhi then you have reached the very right place. ResortsNearDelhi.co.in, a Division of ‘COMFORT YOUR JOURNEY PVT LTD’ avails you the options for Weekend Getaways Near Delhi.
    visit: http://www.bestholidaystrip.com/

    ReplyDelete
  4. New Year 2017 is an event of pleasures. So we should praise it together with charming and a brilliant flavoring of move gathering, boundless beverages, mixed drink, barkeeps, bucketful of snacks, commencement to be the most energizing one and exquisite scrumptious food stuff with New Year bundles close Delhi.
    visit: http://newyearpackagesneardelhi.com/

    ReplyDelete
  5. Observe New Year's Eve in style by heading out to experience it in one of the world's most energizing goals with British Airways. Mark the commencement to 2017 with a New Year's Eve break to one of the numerous urban areas we travel to overall, for example, Edinburgh, New York, Rio or Sydney, and wake up to a radical new view on New Year's Day. Visit: New Year Packages 2017

    ReplyDelete
  6. Observe New Year's Eve in style by heading out to experience it in one of the world's most energizing goals with British Airways. Mark the commencement to 2017 with a New Year's Eve break to one of the numerous urban areas we travel to overall, for example, Edinburgh, New York, Rio or Sydney, and wake up to a radical new view on New Year's Day. visit: New Year Packages Near Delhi

    ReplyDelete
  7. I like this blog, saved to my bookmarks.I have got some important suggestions from it. erp software solutions chennai.

    ReplyDelete