Thursday 2 August 2012

Web services : Fundamentals

1. What is a web service?

Web service is the way to publish application's function on web that can be accessible to the rest of the world.Web services are the components that can be used by other applicationsASP.NET offers easy way to develop web services, just precede the functions with a special WebMethod ()> attribute in order them to work as Web Service.These are discovered using UDDI directory services.
Web services are built on XML standard and use SOAP protocol that allows them to communicate across different platforms and programming languages.Web services easily manage to work across corporate firewalls as they use HTTP protocol which is firewall friendly.
Web services platform elements are

  • SOAP (Simple Object Access Protocol) 
  • UDDI (Universal Description, Discovery and Integration) 
  • WSDL (Web Services Description Language)

The web services are built on internet standards that are not platform or language specific.The .Net framework provides in-built classes to build and consume web services.The components offered by web services are reusable.
The examples of web service components can be shipment tracking, translation utility, weather forecasting, sports scores etc.

2. How are web services implemented in .NET?

Web services are implemented as HTTP Handlers that intercept requests to .asmx files.

3. Define the characteristic of web services ?

  • XML-based: XML based is totally platform independent and run on any operating system and also language independent
  • Loosely Coupled: Loosely coupled means consumer of a web service does not tied web services directly.  A tightly coupled system implies that the client and server logic are closely tied to one another.
  • Coarse-grained: Its provide Coarse-grained facility for JAVA programs and methods.
  • Ability to be synchronous or asynchronous: Synchronized provide the facility  to binding the client when client want to execute the Web Services. Means client synchronously used the services.  Asynchronous operations allowed  the client  a client to invoke the web service when client want to execute other functions.
  • Supports to Remote Procedure Calls (RPCs): Web services support the remote procedure calls when transaction occur during exchange of documents.
  • Supports document exchange: Web services support the transfer the  exchange of documents to utilize business transaction. Exchange of document totally XML based.
  • Interoperability provide system to system work without any external effort.

4. What is difference between remoting and webservices.
  • WEb Services are platform independent , .net remoting is not platform independent.
  • In Remoting both applications know each other but in Web services this may not be the case.
  • Web Services are stateless whereas .Net Remoting can be stateless or Stateful
  • Web Services are easy to develop and deploy Remoting is complex.
5.What are advantages of Web Services ?
  • Interoperability: Most important benefit  of Web services, its  work outside of private networks and  offering developers to find their solutions in appropriate way. Its provide Interoperability between many software's running ion different platform. Web Services are virtually platform-independent
  • Reusability: Web services use open standards and protocols. Deployment of services possible easily because  they are not a component-based model of application for development. This makes it easy to reuse Web Service components as appropriate in other services.
  • Deploy ability: Web services deploy over the Web and any user use this without any independent and mapping problems.
  • Usability: Web services allow the reuse of services and components within an infrastructure. Web Services allow the business logic of  different platform and exposed it over the Internet. This thigh provide the facility to use web services any where for different platform.
6. What are the disadvantages of Web Services ?
  • Web services suffered poor performance in comparison other distributed application  RMI, CORBA, or DCOM.
  • XML explicitly does not count among its design goals either conciseness of encoding or efficiency of parsing.
  • Transaction in Web Services is not infancy like other distributed standards like CORBA. The web service transaction is nonexistent.
  • When client make a request to the server and while server is  responding at that time if power fails or client end crash, in this condition server never known that client not activated.
7. What is SOAP?
  • SOAP, Simple Object Access Protocol is a communication protocol, a way to structure data before transmitting it, 
  • is based on XML standard. 
  • It is developed to allow communication between applications of different platforms and programming languages via internet.
  • It can use range of protocols such as HTTP, FTP, SMTP, Post office protocal 3(POP3) to carry documents.
  • SOAP serializes complex structure, such as ASP.NET DataSets, complex arrays, custom types and XML nodes before transmitting and thus allows exchange of complex objects between applications.
  • Two components can easily communicate using Remote Procedure Calls protocol. But because of their compatibility and security issues, most of firewalls and proxy server block this type of messages.
  • SOAP uses HTTP channel to transport which makes it widely accepted protocol over the internet.
8. What is WSDL?
  • WSDL stands for Web Services Description Language,
  •  XML-based language that describes Web services and 
  • how to access and locate them.
9. What is UDDI?
  • UDDI stands for Universal Description, Discovery and Integration. 
  • It is an open, Internet-based specification that offers directory service for storing information about web services.
10. Explain the protocols a .Net Web Service uses.
  • In .Net, a web service is bind with three different protocols such as HTTP/POST, HTTP/GET, and SOAP. 
  • This allows client with three options to choose for communication. 
  • The protocols are included in the WSDL file that is automatically generated in .NET.
  • Http-Get and Http-Post can only be used when name/value pairs of data is dealt with. But when data is complex in nature such as ASP.NET dataset, XML notes etc, then we can use SOAP that serializes data in simpler form before sending.  
11. Explain how to document web services.
  • ASP.NET web services are considered as self documenting as they provides all information about what methods are available and what parameters they require using XML based standard called WSDL. 
  • We can also provide addition information about the web services using their WebService and WebMethod attributes. 
  • You can add descriptions to each method through the Description property of the WebMethod attribute and to the entire web service as a whole using the Description property of the WebService attribute.
  •  You can also apply a descriptive name to the web service using the Name property of the WebService attribute.
  •  The attributes have name, description and namespace as properties which are shown in following example:
[WebService(Name = "Customer Service", Description = "Retrieve the Customer details",Namespace=http://www.apress.com/ProASP.NET/)] 
public class Customer : System.Web.Services.WebService
{
     [WebMethod(Description = "Returns Customer Count")]
     public int GetCustomerCount()
     { ... }
     [WebMethod(Description = "Returns the list of Customer")]
     public DataSet GetCustomer()
     { ... }
}
  • Namespace allows your web service to be uniquely identified. By default, ASP.NET web services use the default XML namespace http://tempuri.org/, which is suitable only for testing. XML namespace simply identifies your web service. 
  • XML namespaces usually look like URLs. However, they don't need to correspond to a valid Internet location.
12. Explain when do we required ASP.NET web services.
  • ASP.NET web services are the great way to expose your middle tier components via internet. 
  • These components offer no issue communicating across firewalls as they use SOAP as transport protocols that transmit structured data using HTTP channel.
  •  Thus, message can be easily exchanged through port 80, i.e. through internet data port without being getting hampered by corporate firewalls or proxy server.
  • Web services can fit in the situation when we require integrating disparate systems written by separate vendors via internet. 
  • Web services are primarily being used for B2B integration like authorizing employees, supplier, electronically signing of invoice etc. 
13. How do you deploy a Web Service
  • Deploying the .Net Web Services is as simple as any ASP.NET application. 
  • Similar to ASP.NET applications, you need to copy or upload the .ASMX file and the .DISCO files to the appropriate directories, and that's it.
14. Explain in brief Web Service Standards.
Following are the standards used by web services:
  • WSDL is used to create interface definition for a web services. It describes all about methods to the client, i.e. methods available in a web service, their parameters and return values.
  • SOAP, Simple Object Access Protocol is a communication protocol, a way to structure data, based on XML. The web services use SOAP message format to encode information before sending.
  • HTTP:The SOAP message format in web services uses HTTP as communication protocol, i.e. SOAP messages are sent over HTTP channels. 
  • DISCO: It is used to create discovery documents that provide links to multiple web service endpoints. The DISCO standard creates a single file that groups a list of related web services. A company can publish a DISCO file on its server that contains links to all the web services it provides. 
  • UDDI: A standard for creating business registries that catalog companies, the web services they provide, and the corresponding URLs for their WSDL contracts.
15. Define the specifications that help in the discovery of a web service.
  • DISCO, an abbreviation of discovery, is a file that groups together a list of related web services. A company that offers web services publishes a DISCO file on its server that has links of all the web services it provides. The client requests this file to see all the available web services. This standard is useful when client already know about a company that offers web services. You can also use DISCO standard while working in local network. It is not helpful to find all web services over the internet.
  • UDDI (Universal Description, Discovery, and Integration) offers centralized directory for web services over the internet. It hosts web services from different companies and can be used by the clients to find web services of their specific need. To make web services shared publicly, they have to be published in UDDI.  
16. What are the data types supported by Web Services?
  • .Net web services are built on XML-based standards for exchanging data. This means .NET web services can support only those data types that can be recognized by the XML schema standard. There are many proprietary .Net objects such as FileSteam, Eventlog etc. are not supported in the web services. These data types are .Net specific types that are not universally recognized, i.e. .Net specific only.
  • You can even exchange custom objects using .Net web services. The only limitation is that only public data members are transmitted, and all public members and properties must use one of the other supported data types.
  • You can use DataSet and DataTable to return information from database but can't use other ADO.NET objects such as DataColumns and DataRows.
  • .Net offers a distributed technology called .Net remoting that can plays around wide range of .Net specific data type. But unfortunately, .Net remoting doesn't support client other than .Net.
 
16. How to test and consume a .Net web service.
Testing a Web Service
.NET has a test web page that ASP.NET uses automatically when you request the URL of an .asmx file in a browser. This page uses reflection to read and show information about the web services, such as the names of the methods it provides.
 
Consuming a Web Service
Web services are built on XML standard. So, a client needs to equip itself to understand XML-based message in order to exchange messages. The .Net framework provides proxy component that enable clients to interact with web services. The proxy has all necessary information that can be utilized by the client application to share data with web services.
The proxy class wraps the calls to the web service's methods. It generates SOAP message format and manages the transmission of the messages over the network (using HTTP). When it receives the response message, it converts the results back to the corresponding .NET data types.
You can create a proxy class in .NET in two ways: 
  • By using wsdl.exe command-line tool 
  • By using Visual Studio web reference feature  
 
17. What is the use of the mustUnderstand attribute in the Header element of a SOAP message?
The mustUnderstand attribute indicates that a header entry is either required or optional for the recipient to process further
18. How can you prevent your Web services from unauthorized access?
The following are the ways to prevent your Web service from unauthorized access:
  • Using encryption and message-based security.
  • Using authentication and access controls for the Web service.
 
19. Mention the namespace that you must import in code to build a Web service.
System.Web.Services is the elementary namespace, which must be imported to develop code of a Web service.
20. Which property of the WebMethod attribute allows you to maintain the state of objects across sessions in a Web method?
The WebMethod attribute's EnableSession property enables you to enable session state for a Web method.
Write the names of public properties defined in the WebService class.
There are many properties defined in the WebServices class:
  • Application - Obtains the application object for the current HTTP request
  • Context - Obtains the HttpContext object for the current request, which encapsulates all HTTP-specific context used by the HTTP server to process Web requests
  • Server - Obtains the HttpServerUtility object for the current request
  • Session - Obtains the HttpSessionState object for the current request
  • SoapVersion - Obtains the version of the SOAP protocol used to make the SOAP request to a Web service
  • User - Obtains the Server User Object. This property can be used to authenticate whether a user is authorized to execute the request.
 
21. What do you understand by SOAP encoding?
The Serialization of the types, such as integers and strings, inside a SOAP message is called encoding. The SOAP objects use XML elements and attributes to serialized data, for example, encodingStyle is an attribute of the Envelop element, which is used to specify the encoding rules for a SOAP object.
 22. Mention the name of the directory where it is necessary to locate the proxy file to use a Web service.
 The proxy file must be stored in the /bin directory. This directory is situated under the root directory of the application.

No comments:

Post a Comment