Click here to Skip to main content
15,888,111 members
Articles / All Topics

WebServices in .NET

Rate me:
Please Sign up or sign in to vote.
3.50/5 (3 votes)
11 Jan 2016CPOL4 min read 16.3K   4   1
WebServices in .NET

Definition

It is a technology introduced by Microsoft in .NET to provide distributed services over the network. Web Service performs the distribution of the logic always in an XML standard.

History

To develop distributed services, many technologies are available in the market like DCOM, CORBA, RMI, etc. before .NET.

Picture4

Advantages

  • Easy to develop and use
  • Cross application communication
  • Cross platform communication
  • Cross Language communication
  • Supports Firewalls for security reasons

Standards of Web Services

SOAP (Simple Object Access Protocol)

  • This standard is used for data transformation and data conversion.
  • It contains XML which is the universal understandable format which is used for transferring the request and response in XML format which is called as SOAP Envelope.
  • To take the SOAP Envelope b/w client and service, universal communication protocol is used, i.e. HTTP
  • Because its port number is configured on most of the firewalls and proxy.

WSDL (Web Service Description language)

  • This standard will describe a web service in an XML Schema.
  • It provides the description about the methods available, method parameters list, type and the return type of the method.
  • It also specifies how the request and responses are perform with the protocols along with the path of a web service.

DISCO (Discovery Standards)

  • This file will maintains the links of WSDL.

UDDI (Universal Discovery Description Integration)

  • It is a centralized repository where all the web services links are maintained in terms of discovery files. (www.UDDI.org)

Architecture

Local Architecture

Picture2

  1. When a Client app gives a request, it will search the web service and the WSDL file of that web service and the WSDL file of that web service is returned back to the client program.
  2. The client program gives the WSDL file to proxy class which checks your request in the description and generates the request object by binding, parameter list, Type and return type.
  3. Request object is converted to XML standard which is called SOAP request Envelope.
  4. SOAP request Envelope is transferred to server using http protocol
  5. The Soap server on the web server will accept the soap request envelope and converts it to an ordinary request object, then forward into the web services.
  6. Web service will process the request and gives the response to the SOAP server.
  7. SOAP server will convert the response to SOAP response envelope send it back to the client using http protocol.
  8. The proxy class on the client machine converts the SOAP response object to display the output.

Global Architecture

Picture3

  1. When a client wants to search a web service or access a web service, the request is first accepted by the UDDI server.
  2. UDDI contains that web service discovery files.
  3. UDDI server chooses the discovery file according to the request and returns the link of WSDL file to the client.
  4. The client program will give the request to the WSDL file. Then web service will return the WSDL file to the client.
  5. Remaining steps are the same as Local Architecture.

Developing Web Service in ASP.NET

  1. Web Services are stateless.
  2. They should save with .asmx (Active Server Method extension) extension.
  3. The method which you want to provide for internet accessibility should be declares with [WebMethod] attribute.
  4. To develop web service in ASP.NET, .NET Framework has provided System.Web.Services namespace.

Developing a Web Service in Notepad

C#
<%@ WebService Language="C#" Class="Sample"%>
using System;
using System.Web.Services;
public class Sample
{
[WebMethod]
public int Sum(int a, int b)
{
return a+b;
}
}
  • Save the file with .asmx extension and copy the file to the virtual directory.
  • To test the WebService and to view the description, go to ?browser and type the url of the like example: http://localhost/aspnet/first.asmx

State Management with Web Services

  • As Web Services are stateless technology whose memory will be allocated with every request and automatically destroys with every response.
  • So to maintain some information on the web service hosted system for a specific time interval, we can use state management.
  • State management with web service always supports Server Side State management by using 3 concepts:
    1. Sessions 
    2. Applications
    3. Caching

Sessions with Web Service

  • Session is some information maintained on a server machine with a default life span of 20 minutes after sending the response.
  • It is local for every user.
  • Session along with Web Services are by default disabled so to use the session, we should enable it for every Web Method.

Application object with Web Service

  • It is similar like session maintaining information on server for life span of 5 minutes after sending the response.
  • It is sharable among more than one user.

Caching with Web Service

  • Caching is used to maintain some data, output of webpage in a fast accessing temporary memory, i.e., caching memory.

Security with Web Services

  1. If the web service is placed under UDDI server, anybody can access your web services.
  2. So the UDDI server requires registration before accessing the web services from it. And to provide the communication between UDDI server and application, we require passport services.
  3. In .NET 1.1 version, the passport services need to install by downloading from http://www.hotmail.com or http://www.ms.com and then we need to specify authentication, authorization settings in application web.config file.
  4. In the Web.Config file
    HTML
    <authentication mode = "Passport">
    	<Passport redirecturl = " "/>
    	</authentication>
  5. From .NET 2.0 version onwards, passport services are by default integrated and also they are configured on IIS.

Image 4 Image 5

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
https://dotnetcynosure.wordpress.com

Comments and Discussions

 
GeneralMy vote of 2 Pin
jackmos21-Jan-16 3:10
professionaljackmos21-Jan-16 3:10 
Nothing new and incomplete. You talk about security but don't show how to do it. You don't even mention WCF which adds a lot of functionality to web services.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.