WCF Interview Questions and Answers (209) - Page 2

What are the various ways of hosting a WCF service?

Self hosting the service in his own application domain. This we have already covered in the first section. The service comes in to existence when you create the object of ServiceHost class and the service closes when you call the Close of the ServiceHost class.
Host in application domain or process provided by IIS Server.
Host in Application domain and process provided by WAS (Windows Activation Service) Server.
Difference between WCF and Web services?

Web Services

1.It Can be accessed only over HTTP
2.It works in stateless environment

WCF

WCF is flexible because its services can be hosted in different types of applications. The following lists several common scenarios for hosting WCF services:
IIS
WAS
Self-hosting
Managed Windows Service
What is WCF?

Answer edited by Webmaster

Windows Communication Foundation (WCF) is an SDK for developing and deploying services on Windows. WCF provides a runtime environment for services, enabling you to expose CLR types as services, and to consume other services as CLR types.

WCF is part of .NET 3.0 and requires .NET 2.0, so it can only run on systems that support it.

(content from another post: http://www.dotnetfunda.com/interview/exam283-what-is-wcf.aspx)
Which namespace is used to access WCF service?

NOTE: This is objective type question, Please click question title for correct answer.
What is a SOA Service?

SOA is Service Oriented Architecture. SOA service is the encapsulation of a high level business concept. A SOA service is composed of three parts.
1. A service class implementing the service to be provided.
2. An environment to host the service.
3. One or more endpoints to which clients will connect.
What is the use of ServiceBehavior attribute in WCF ?

ServiceBehaviour attribute is used to specify the InstanceContextMode for the WCF Service class (This can be used to maintained a state of the service or a client too)

There are three instance Context Mode in the WFC

PerSession : This is used to create a new instance for a service and the same instance is used for all method for a particular client. (eg: State can be maintained per session by declaring a variable)

PerCall : This is used to create a new instance for every call from the client whether same client or different. (eg: No state can be maintained as every time a new instance of the service is created)

Single : This is used to create only one instance of the service and the same instance is used for all the client request. (eg: Global state can be maintained but this will be applicable for all clients)
Which namespace is required in a class to use DataContract or DataMember attribute for a class or properties?

NOTE: This is objective type question, Please click question title for correct answer.
Difference between Web Services and WCF

Major Difference is That Web Services Use XmlSerializer But WCF Uses
DataContractSerializer which is better in Performance as Compared to XmlSerializer.
Key issues with XmlSerializer to serialize .NET types to XML

* Only Public fields or Properties of .NET types can be translated into XML.
* Only the classes which implement IEnumerable interface.
* Classes that implement the IDictionary interface, such as Hash table can not be serialized.

The DataContractAttribute can be applied to the class or a strcture. DataMemberAttribute can be applied to field or a property and theses fields or properties can be either public or private.

Important difference between DataContractSerializer and XMLSerializer.

* A practical benefit of the design of the DataContractSerializer is better performance over Xmlserializer.
* XML Serialization does not indicate the which fields or properties of the type are serialized into XML where as DataCotratSerializer Explicitly shows the which fields or properties are serialized into XML.
* The DataContractSerializer can translate the HashTable into XML.
in WCF, Which contract is used to document the errors occurred in the service to client?

Fault Contract is used to document the errors occurred in the service to client.
Which is the default Message Exchange Pattern (MEP) ?

NOTE: This is objective type question, Please click question title for correct answer.
What is the Messaging Pattern? Which Messaging Pattern WCF supports?

Messaging Pattern : Messaging patterns describes how client and server should exchange the message. There is a protocol between client and server for sending and receiving the message. These are also called Message Exchange Pattern.

WCF supports following 3 types of Message Exchange Patterns
1. request - reply (default message exchange pattern)
2. OneWay (Simplex / datagram)
3. Duplex(CallBack)

Thanks
Prasham
What is .svc file in WCF?

.svc file is a text file. This file is similar to our .asmx file in web services.

This file contains the details required for WCF service to run it successfully.

This file contains following details :
1. Language (C# / VB)
2. Name of the service
3. Where the service code resides

Example of .svc file

<%@ ServiceHost Language="C#/VB" Debug="true/false" CodeBehind="Service code files path" Service="ServiceName"

We can also write our service code inside but this is not the best practice.
What is XML Infoset?

The XML Information Set defines a data model for XML. It is an abstract set of concepts such as attributes and entities that can be used to describe a valid XML document. According to the specification, "An XML document's information set consists of a number of information items; the information set for any well-formed XML document will contain at least a document information item and several others."
What are the various ways of hosting a WCF Service?

1.IIS
2.Self Hosting
3.WAS (Windows Activation Service)
What is DataContractSerializer in WCF?

DataContractSerializer is new WCF serializer.

This is serialization engine in WCF. DataContractSerializer translate the .NET framework objects into XML and vice-versa.

By default WCF uses DataContractSeriazer.
What is Message Contract in WCF?

Message Contract :
Message Contract is the way to control the SOAP messages, sent and received by the client and server.

Message Contract can be used to add and to get the custom headers in SOAP message

Because of Message Contract we can customize the parameters sent using SOAP message between the server and client.

Thanks
Prasham
What is Fault Contracts in WCF?

Fault Contracts is the way to handle exceptions in WCF. The problem with exceptions is that those are technology specific and therefore cannot be passed to other end because of interoperability issue. (Means either from Client to Server or vice-versa). There must be another way representing the exception to support the interoperability. And here the SOAP Faults comes into the picture.

Soap faults are not specific to any particular technology and they are based on industry standards.

To support SOAP Faults WCF provides FaultException class. This class has two forms:

a. FaultException : to send untyped fault back to consumer
b. FaultException<T>: to send typed fault data to the client

WCF service also provides FaultContract attribute so that developer can specify which fault can be sent by the operation (method). This attribute can be applied to operations only.
What is the difference between XMLSerializer and the DataContractSerializer?

a. DataContractSerializer is the default serializer fot the WCF
b. DataContractSerializer is very fast.
c. DataContractSerializer is basically for very small, simple subset of the XML infoset.
d. XMLSerializer is used for complex schemas.

Thanks
Prasham
What is the purpose of base address in WCF service? How it is specified?

When multiple endpoints are associated with WCF service, base address (one primary address) is assigned to the service, and relative addresses are assigned to each endpoint. Base address is specified in <host> element for each service.
E.g.
<configuration>

<system.servicemodel>
<Services>
<service name=”MyService>
<host>
<baseAddresses>
<add baseAddress =”http://localhost:6070/MyService”>
</baseAddresses>
</host>
</service>
<services>
</system.servicemodel>
</configuration>


Thanks
Prasham
Which protocol is used for platform-independent communication?

SOAP (Simple Object Access Protocol), which is directly supported from WCF (Windows Communication Foundation).
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories