0 comments

Web Services Components in .net

Web Services Components

Web Services are piece of business logic that can be accessed over the internet. You can reuse someone else's business logic instead of replicating it yourself. This technique is similar to what programmers currently do with a library of APIs, classes and components. The main difference is that web services can be located remotely on another server and managed by another vendor such as a Google Search engine which is a kind of web service, you submit a search expression, and it compiles a list of matching websites, and returns the list to your web browser.

There are some key protocol flows that make a complete web services as in the following:
SOAP (Simple Object Access Protocol)
DISCO (discovery)
UDDI (Universal Description, Discovery and Integration)
WSDL (Web Services Description Language)

SOAP

Web Services manipulate objects through a XML message. SOAP enables you to expose and consume complex data structures that includes items such as data sets and tables. The Data Sets you send or consume can flow over the same internet wire (HTTP), thereby passing through firewalls. SOAP defines the message you use to exchange the data but it doesn't describe how you send the message. In other words, to communicate with web services a client opens an HTTP connection and sends a SOAP message. SOAP is XML based; it can be interpreted by a wide range of software on many operating systems.

SOAP Request
Here a typical SOAP message sent from a Web Service client to a server as in the following:
POST /TestWS/UtilityWebService.asmx HTTP/1.1
Host: localhost
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <addition xmlns="http://tempuri.org/">
      <a>int</a>
      <b>int</b>
    </addition>
  </soap12:Body>
</soap12:Envelope>

SOAP Response
Here is a part of the SOAP message back from the server:
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <additionResponse xmlns="http://tempuri.org/">
      <additionResult>int</additionResult>
    </additionResponse>
  </soap12:Body>
</soap12:Envelope>

DISCO

Before you can use a Web service, you need to know where to find the Service. The DISCO standard creates a single file that is the repository of all related web services. You can publish a DISCO file on its server that contains links to all the web services it provides. Then the client simply needs to request this file to find all the available web services. When you set a Web Reference inside .NET, the software automatically handles the details of discovery for you. But you can also get into the details of the process yourself by using DISCO.exe as in the following:

disco http://localhost:2186/TestWS/WebService.asmx

This tool disco.exe contacts the web service and creates two additional files with .discomap and .wsdl extension. These files are XML files that will show you the name of other file and the URL.

UDDI

UDDI is a centralized directory where web services are published. This is where potential client can go to search for their specific needs. Each organization may use different UDDI registries. To retrieve information from a UDDI directory, you use a web service interface.

WSDL

Before consuming a web service, it is required to have the knowledge of a SOAP message that it can send and receive. WDSL is a standard by which a web service can tell clients what message it accepts and what results it will return. WSDL defines everything about the public interface of a web service such as data type, the methods it exposes and the URL through which those methods can be accessed.

Consuming Web Service 

Before consuming a web service, we need to generate a Proxy class that wraps the call to the web services methods. It takes care of generating the correct SOAP message format and managing the transmission of the message over the wire using HTTP on port 80. When it gets the response message back, it also convert the results back to the corresponding .NET data types.

We can generate a Proxy class in .NET in either of the following two ways:
1. Visual Studio IDE web reference feature
2. Command line utility Wsdl.exe

                                     .NET InterView Questions
 
Toggle Footer
Top