We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Sunday, August 30, 2015

Interview questions and answers of web service


1. What is a "Web Service"?

A "Web Service" is a .NET component that replies to HTTP requests that are formatted using SOAP syntax.

Web services are one of the cornerstones of the .NET initiative in that they allow a degree of interoperability among applications over the internet that was inconceivable before.

2. How are web services implemented in .NET?


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

3. What are the drawbacks of "Response Caching"?

If the method or accepts a wide range of values, response caching might be inefficient or even wasteful because a great deal of information might be stored in a cache.

If the method depends on other information not supplied in parameters (like user authentication or session data), it will be bypassed.

The method will be bypassed even if it needs to perform actions other than returning values (like writing to a log file)

4. How to overcome the limitations of response caching while providing an acceptable level of caching?

By using data caching (System.Web.Caching.Cach)

5. What are the protocols supported by web services built with ASP.NET to exchange data?

  • HTTP GET
  • HTTP POST
  • SOAP
6. Q. What are the limitations of using GET & POST to communicate with a web service?
  • It is less secured than SOAP.
  • It prevents the user from passing structures and objects as arguments
  • It prevents the user from passing ByRef arguments

7. Q. How to make a class accessible as a web service?


By making the class inherits from the System.Web.Services.WebService class

By qualifying the class with the WebService attribute

Inheriting from the WebService class is beneficiary in that it allows the class to access the ASP.NET context and other useful objects such as the session and application objects. On the other hand, qualifying the class with the WebService attribute allows for setting additional properties of the web service such as its description and namespace.

C#

[WebService]

public class TestService : System.Web.Services.WebService

8. Q. How to make a method of a web service class accessible through the internet?

A. By qualifying the method with the WebMethod attribute.

C#

[WebMethod()]

public string MethodName()

9. How can you ensure that only authorized users access your Web service?

You should use the <authorization> element to ensure that only authorized users access your Web service. This element allows or denies access to your Web service according to their role.

10. Describe the EventLog class.

The EventLog class is used to access the Windows event logs from Windows services. Using EventLog, you can also customize Windows event logs that record information about important software and hardware events, such as the events of the .NET controls, keyboard, or other hardware devices.

The EventLogclass allows you to read or write to event logs, delete logs, and create as well as delete event sources. You can use the EventLog class to create event logs while creating an event source. An event source can be used to write to only one event log at a particular time. However, it is possible to associate one event log to multiple sources.

11. 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.

12. Explain the concept of Web services in brief.

A Web service may be defined as an independent and self-sustained unit of a software application that is hosted on the Web and implements specific functionalities to execute the business logic. Web service provides so many functionalities, such as generating payslips for employees, computing tax, broadcasting weather reports, and providing updated news. The Web service allows an application to share information or exchange data with other applications across different operating systems and hardware.

Therefore, the work of a Web service is to unite software by exchanging data irrespective of their operating systems, supported hardware, and programming language used in their development. The Web services transfer data in the XML format and use Simple Object Access Protocol (SOAP) to communicate. It is an XML based protocol. Web services use Web Services Description Language (WSDL) and Universal Description, Discovery, and Integration (UDDI) to describe itself.

13. What advantages have Web services over Component Object Model (COM) and Distributed Component Object Model (DCOM)?
The advantages of Web services over COM and DCOM are as follows:

Web services are simple to use and can be implemented on varied platforms.

Web services are loosely coupled; as a result, their interfaces and methods can be extended.

Web services do not carry any state information with them so that multiple requests can be processed simultaneously.

14. Mention the namespace that you must import in code to build a Web service.

System.Web.Services are the elementary namespace, which must be imported to develop the code of a Web service.

15. What does the portType element of a WSDL document contain?

The portType element contains the operations exposed by the Web service, and the messages involved in the communication between the Web service and its consumers.

16. What is DISCO?

DISCO is a technology developed by Microsoft to publish and discover Web services. It discovers URLs of all XML Web services located on a Web server and creates a list of these Web services in a file called a DISCO file.

17. Which two methods are used to discover the URL of Web services?

The two methods to discover the URL of Web services are Web service discovery tool (Disco.exe) and UDDI.

18. Which step is necessary to perform before a Web service can be consumed?

It is necessary to build a proxy class by using the wsdl.exe utility before a Web service can be consumed.

19. 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.

20. 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 attribute 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. What is the use of a .disco file?

A client application uses a .disco file to locate or discover the documents that contain the description of a Web service. The .disco file contains links to other resources, which describe essential features, such as capabilities of a Web service. The links contained in a .disco file can refer to other discovery documents or XSD schemas. The description of the services and capabilities of a Web service is written in Web services Description Language (WSDL). A .disco file can also contain information about other XML Web services that reside on the same or a different Web server.

23. 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.

24. Does a Web service have a state?


The Web services do not have any technique to maintain state. However, it can access ASP.NET objects, such as application and session if they extend from the WebService base class.

25. Which namespace must be included in a code that enables an XML Web service to write events in an event log file?
The System.Diagnostics is the namespace, which must be included in code to enable a Web service for writing events in an event log file.

26. Which tool installs the DLL on your local computer and installs the Windows service in a transactional manner?

The Installutil.exe tool.

27. What are web method and all its various properties?

Adding [WebMethod()] attribute to a method within an XML Web service created using ASP.NET makes method callable from remote Web clients. This class cannot be inherited. the Bypassing following properties, we can get additional capability or control over method behavior.

Ex:

[WebMethod (Description="Obtains the Server Machine Name", EnableSession=true)]
public string GetMachineName()
{
return Server.MachineName;
}
Properties:
Name Description
EnableSession Indicates whether the session state is enabled for an XML Web service method.

MessageName To overload WebMethod in WebService.

CacheDuration Gets or sets the number of seconds the response should be held in the cache.

Description A descriptive message describing the XML Web service method.

TransactionOption Indicates the transaction support of an XML Web service method.

TypeId When implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.)

28. WCF Vs ASP.NET Web API?

Actually, the Windows Communication Foundation is designed to exchange standard SOAP-based messages using a variety of transport protocols like HTTP, TCP, NamedPipes or MSMQ, etc.
On the other hand, ASP.NET API is a framework for building non-SOAP based services over HTTP only.

29. What are web services?

A "web service is the communication platform between two different or same platform applications that allows using their web method."

In the preceding definition, you observed that I used the two main points in the definition of web service; they are different or the same platform application and the second is web method.
so let us learn some basics about it.

30. What does a different or same application and platform mean

It means that I can create a web service in any language, such as Java or other languages and that the language web service can be used in a .Net based application and also a .Net web service or in another application to exchange the information.

31. What does web method mean

The method in web services always start with [webMethod] attributes, it means that it is a web method that is accessible anywhere, the same as my web application.

32). What is a Proxy?

Proxy is a program or class that contains code to convert a local call to a remote call(also called marshaling).

33). Who creates a Proxy?

In which language client application is developed(c#) , with the same language client is responsible for the creation of Proxy class. Afterward, it will communicate with the service through Proxy class.

34). How does the Proxy gets created by the client application?

Actually when you are developing a service usually you will expose those functionalities which are required by the client application. With the metadata of our service, WSDL will create an XML file describes everything related to our service.Client applications first get the information from the WSDL file, through that information client will create

a proxy so that it will communicate with the service but not directly to the service.

35). What are Formatters and Dispatchers?

Formatter is a class to converts the message into a stream or set of bytes so that it is about to transport

A dispatcher is a class converts the stream of bytes to an actual message as like before.

36). Can we host a WCF service in different environments?
Yes, you can host it. These are the following hosting options which we have in our WCF framework
  • Self Hosting.
  • IIS.
  • WAS(Windows Activation Service).
  • Windows Service.

37). What is WCF?

Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application. An endpoint can be a client of a service that requests data from a service endpoint. The messages can be as simple as a single character or word sent as XML, or as complex as a stream of binary data. A few sample scenarios include:
  • A secure service to process business transactions.
  • A service that supplies current data to others, such as a traffic report or other monitoring service.
  •  A chat service that allows two people to communicate or exchange data in real-time.
  • A dashboard application that polls one or more services for data and presents it in a logical presentation.
  • Exposing a workflow implemented using Windows Workflow Foundation as a WCF service.
  • A Silverlight application to poll a service for the latest data feeds.
38). What are the features of WCF?
  • Service Orientation
  • Interoperability
  • Multiple Message Patterns
  • Service Metadata
  • Data Contracts
  • Security
  • Multiple Transports and Encodings
  • Reliable and Queued Messages
  • Durable Messages
  • TransactionsAJAX and REST Support
  • Extensibility

39). What are the other technologies that you can integrate with WCF?

WCF is a flexible platform. Because of this extreme flexibility, WCF is also used in several other Microsoft products. By understanding the basics of WCF, you have an immediate advantage if you also use any of these products.
  • Silver Light
  • Microsoft Biztalk Server
  • Windows Workflow Foundation(WF).
And also it is using new web standards like:
  • REST
  • JSON etc.

40). What is an Endpoint?

All communication with a Windows Communication Foundation (WCF) service occurs through the endpoints of the service. Endpoints provide clients access to the functionality offered by a WCF service.

Each endpoint consists of four properties:
  • An address that indicates where the endpoint can be found.
  • A binding that specifies how a client can communicate with the endpoint.
  • A contract that identifies the operations available.
  • A set of behaviors that specify local implementation details of the endpoint.

41). What is an Address?

The address uniquely identifies the endpoint and tells potential consumers of the service where it is located. It is represented in the WCF object model by the EndpointAddress class. An EndpointAddress class contains:

A Uri property, which represents the address of the service.

An Identity property, which represents the security identity of the service and a collection of optional message headers. The optional message headers are used to provide additional and more detailed addressing information to identify or interact with the endpoint.

42). What is Binding?
The binding specifies how to communicate with the endpoint.

This includes:
  • The transport protocol to use (for example, TCP or HTTP).
  • The encoding to use for the messages (for example, text or binary).
  • The necessary security requirements (for example, SSL or SOAP message security).
43). what is Contract?

The contract outlines what functionality the endpoint exposes to the client.

A contract specifies:

What operations can be called by a client?

The form of the message.

The type of input parameters or data required to call the operation.

What type of processing or response message the client can expect.

44). What are Behaviors?

You can use endpoint behaviors to customize the local behavior of the service endpoint. Endpoint behaviors achieve this by participating in the process of building a WCF runtime. An example of an endpoint behavior is the ListenUri property, which allows you to specify a different listening address than the SOAP or Web Services Description Language (WSDL) address.

45). What is the diff b/w Web services and WCF services?

Web service is a part of WCF. WCF offers much more flexibility and portability to develop a service when comparing to web service. Still, we are having more advantages over Web service, following are the basic difference between them.
  • In Web services we use System.Xml.serialization namespace for serialization but for WCF we use System.Runtime.Serialization namespace for serialization
  • Web service can be hosted in IIS, whereas WCF service can be hosted in IIS, windows activation service, Self-hosting, Windows service
  • Here we use WebService, WebMethod to make a class as service, but in WCF we use ServiceContract, OperationContract Attributes.
  • Duplex message communication is not possible in ASMX web service.
46). Why we are moving to WCF as already we have Web services?

ASMX is great and simple - but it's very limited in many ways:

you can only host your web services in IIS

you can only reach your web services over HTTP

security is very limited

WCF remedies this - and offers much more beyond that. You can host your WCF services in IIS - or self-host in a console app or Win NT Service, as need be. You can connect your WCF services using HTTP, TCP/IP, MSMQ, Peer-to-peer protocols, named pipes for on-machine communications and much more.

47). What is the full form of WCF and in which framework it was introduced?

Windows Communication Foundation. Introduced in 3.0

48). What do you mean by client?

The client of a service is the program unit consuming its functionality. The client can

be literally anything—for instance, Console application, Windows Forms, WPF, or Silverlight class, anASP.NET page, or another service

49). How can we host the WCF service?
Every WCF service needs to be hosted in a windows process called the host process. A single host process can host multiple services, and the same service type can be hosted in multiple host processes.

50). What is binding?

A binding is the set of configurations regarding the transport protocol, message encoding, communication pattern, reliability, security, transaction propagation, and interoperability.

No comments: