YouTube Icon

Interview Questions.

Top 49 Windows Communication Foundation (WCF) Interview Questions - Jul 28, 2022

fluid

Top 49 Windows Communication Foundation (WCF) Interview Questions

Q1. What Is The Use Of Is Required Property In Data Contracts?

Data Contracts, is used to outline Required or NonRequired facts individuals. It may be executed with a property named IsRequired on DataMember characteristic.

[DataContract]

public elegance test

[DataMember(IsRequired=true)]

public string NameIsMust;

[DataMember(IsRequired=false)]

public string Phone;

 

Q2. What Is Service And Client In Perspective Of Data Communication?

A service is a unit of capability exposed to the world.

Q3. 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 viceversa.

By default WCF makes use of DataContractSeriazer.

Q4. What Is Proxy And How To Generate Proxy For Wcf Services?

The proxy is a CLR elegance that exposes a unmarried CLR interface representing the service contract. The proxy presents the equal operations as carrier's agreement, but additionally has additional techniques for dealing with the proxy life cycle and the connection to the provider. The proxy absolutely encapsulates every issue of the carrier: its vicinity, its implementation era and runtime platform, and the communique transport.

The proxy may be generated using Visual Studio with the aid of proper clicking Reference and clicking on Add Service Reference. This brings up the Add Service Reference dialog box, wherein you need to supply the base cope with of the provider (or a base address and a MEX URI) and the namespace to comprise the proxy.

Proxy also can be generated via using SvcUtil.Exe commandline application. We need to offer SvcUtil with the HTTPGET deal with or the metadata alternate endpoint address and, optionally, with a proxy filename. The default proxy filename is output.Cs however you could additionally use the /out transfer to suggest a unique name.

SvcUtil http://localhost/MyService/MyService.Svc /out:Proxy.Cs

When we are website hosting in IIS and deciding on a port aside from port 80 (which includes port 88), we should provide that port range as a part of the base address:

SvcUtil http://localhost:88/MyService/MyService.Svc /out:Proxy.Cs

Q5. What Does A Windows Communication Foundation, Or Wcf, Service Application Use To Present Exception Information To Clients By Default?

However, the carrier cannot go back a .NET exception to the consumer. The WCF service and the consumer talk by means of passing SOAP messages. If an exception occurs, the WCF runtime serializes the exception into XML and passes that to the purchaser.

Q6. Where We Can Host Wcf Services?

Every WCF services have to be hosted someplace. There are 3 ways of hosting WCF offerings.

They are

IIS

Self Hosting

WAS (Windows Activation Service)

Q7. What Is .Svc File In Wcf?

.Svc document is a textual content report. This record is similar to our .Asmx document in internet services.

This record includes the details required for WCF service to run it correctly.

This report carries following details :

Language (C# / VB)

Name of the service

Where the service code resides

Example of .Svc report

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

Q8. What Are The Main Components Of Wcf?

The important components of WCF are

Service magnificence

Hosting surroundings

End factor

Q9. What Is Wcf?

Windows Communication Foundation (WCF) is an SDK for developing and deploying offerings on Windows. WCF presents a runtime surroundings for offerings, enabling you to show CLR kinds as services, and to devour other services as CLR types.

WCF is a part of .NET 3.Zero and requires .NET 2.0, so it could handiest run on structures that guide it.

Q10. What Are Contracts In Wcf?

In WCF, all services expose contracts. The agreement is a platformneutral and general manner of describing what the provider does.

WCF defines four forms of contracts.

Service contracts: Describe which operations the purchaser can perform at the provider.

There are  varieties of Service Contracts.

ServiceContract This characteristic is used to outline the Interface.

OperationContract This characteristic is used to outline the method inner Interface.

Data contracts: Define which records sorts are surpassed to and from the carrier. WCF defines implicit contracts for builtin types such as int and string, but we can effortlessly outline explicit optin facts contracts for custom kinds.

There are two forms of Data Contracts.

DataContract attribute

used to outline the magnificence

DataMember characteristic

used to outline the homes.

Fault contracts: Define which errors are raised by the service, and the way the service handles and propagates mistakes to its clients.

Message contracts: Allow the carrier to have interaction without delay with messages. Message contracts may be typed or untyped, and are useful in interoperability instances and when there may be an present message format we must follow.

Q11. In Wcf Which Bindings Supports The Reliable Session?

In WCF, following bindings supports the dependable session

wsHttpBinding

wsDualHttpBinding

wsFederationHttpBinding

netTcpBinding

Q12. What Are Tha Advantages Of Hosting Wcf Service In Was?

WAS (Windows Activation Service) is a part of IIS 7.@Following are few benefits :

We are not best confined to HTTP protocol. We can also use supported protocols like TCP, named pipes and MSMQ

No want to completely deploy IIS. We can best deploy WAS aspect and keep away the WebServer.

Q13. Which Are The three Types Of Transactions Manager Wcf Supports?

WCF helps following 3 forms of transactions managers:

LightWeight

OLE Transactions

WSAtomic Transactions

Q14. Which Bindings In Wcf Support The Message Streaming?

Following bindings helps the streaming in WCF:

basicHttpBinding

netTcpBinding

netNamedPipeBinding

Q15. How To Set The Instancing Mode In Wcf Service?

In WCF, instancing mode is set at carrier level. For ex.

//Setting PerSession instance mode

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]

class MyService : IMyService

//Implementation goes there

 

Q16. In Wcf, Which Contract Is Used To Document The Errors Occurred In The Service To Client?

Fault Contract is used to record the mistakes happened inside the carrier to consumer.

Q17. What Is Data Contract Equivalence?

Two statistics contracts are stated to be equal, if they fulfill the subsequent conditions.

Both the datacontracts need to have identical namespace

Both the datacontracts have to have same name

The statistics member on statistics contract ought to have an equivalent records member on the other.

The participants within the datacontract should appear in the equal order in both datacontracts.

Ex:

The following  statistics contracts are same.

[DataContract]

public class Person

[DataMember]

public string Name;

[DataMember]

public string Email_ID;

[DataContract(Name = "Person")]

public magnificence Employee

[DataMember(Name = "Name")]

non-public string EmpName;

private string deal with;

[DataMember(Name = "Email_ID")]

private string EmpEmailId;

 

Q18. What Is Three Major Points In Wcf?

We Should recall ABC.

Address Specifies the vicinity of the provider as a way to be like http://Myserver/MyService.Clients will use this area to speak with our provider.

Binding Specifies how the 2 paries will speak in time period of shipping and encoding and protocols

Contract Specifies the interface among patron and the server.It's a easy interface with some attribute.

Q19. What Are The Various Ways Of Hosting A Wcf Service?

Self hosting the service in his very own utility domain. This we've got already included in the first segment. The provider comes in to existence while you create the object of ServiceHost class and the service closes when you call the Close of the ServiceHost elegance.

Host in utility area or procedure supplied by using IIS Server.

Host in Application area and procedure provided through WAS (Windows Activation Service) Server.

Q20. What Is The Purpose Of Base Address In Wcf Service? How It Is Specified?

When multiple endpoints are related to WCF carrier, base address (one number one deal with) is assigned to the carrier, and relative addresses are assigned to each endpoint. Base cope with is laid out in <host> element for every carrier.

E.G.

<configuration>

<system.Servicemodel>

<Services>

<service name=”MyService>

<host>

<baseAddresses>

<add baseAddress =”http://localhost:6070/MyService”>

</baseAddresses>

</host>

</service>

<services>

</system.Servicemodel>

</configuration>

Q21. What Is A Soa Service?

SOA is Service Oriented Architecture. SOA provider is the encapsulation of a excessive stage enterprise concept. A SOA service is composed of three parts.

A provider magnificence enforcing the service to be provided.

An environment to host the carrier.

One or extra endpoints to which clients will connect.

Q22. What Are The Different Wcf Binding Available?

BasicHttpBinding

WSHttpBinding

WSDualHttpBinding

WSFederationHttpBinding

NetTcpBinding

NetNamedPipeBinding

NetMsmqBinding

NetPeerTcpBinding

MsmqIntegrationBinding

Q23. What Is The Address Formats Of The Wcf Transport Schemas?

Address format of WCF transport schema continually follow

[transport]://[machine or domain][:optional port] layout.

As an example:

HTTP Address Format

http://localhost:8888

the way to examine the above url is

"Using HTTP, go to the device referred to as localhost, in which on port 8888 a person is ready"

When the port range isn't unique, the default port is 80.

TCP Address Format

net.Tcp://localhost:8888/MyService

When a port variety isn't targeted, the default port is 808:

internet.Tcp://localhost/MyService

NOTE: Two HTTP and TCP addresses from the identical host can percentage a port, even on the identical gadget.

IPC Address Format

net.Pipe://localhost/MyPipe

We can most effective open a named pipe once in step with gadget, and therefore it isn't always feasible for two named pipe addresses to proportion a pipe name at the equal gadget.

MSMQ Address Format

internet.Msmq://localhost/private/MyService

internet.Msmq://localhost/MyService

Q24. What Are Different Elements Of Wcf Srevices Client Configuration File?

WCF Services patron configuration report includes endpoint, cope with, binding and agreement. A pattern client config report looks as if

<system.ServiceModel>

<client>

<endpoint name = "MyEndpoint"

address = "http://localhost:8000/MyService/"

binding = "wsHttpBinding"

contract = "IMyContract"

/>

</client>

</system.ServiceModel>

Q25. What Is Abc Of Wcf?

ABC is the three constructing blocks of WCF and they're known as

A Address (Where): Address tells us where to discover the services, like url

B Bindings (How): Bindings tells us a way to locate the services or the usage of which protocols unearths the services (SOAP, HTTP, TCT and so forth.)

C Contacts (What): Contracts are an agreement among the client and the service vendors that explains what parameters the carrier expects and what go back values it gives.

Q26. How To Deal With Operation Overloading While Exposing The Wcf Services?

By default overload operations (techniques) are not supported in WSDL based operation. However by means of the usage of Name assets of OperationContract attribute, we are able to cope with operation overloading scenario.

[ServiceContract]

interface ICalculator

[OperationContract(Name = "AddInt")]

int Add(int arg1,int arg2);

[OperationContract(Name = "AddDouble")]

double Add(double arg1,double arg2);

 

Notice that both technique call in the above interface is identical (Add), but the Name belongings of the OperationContract is distinctive. In this example client proxy may have two strategies with exclusive name AddInt and AddDouble.

Q27. Which Protocol Is Used For Platformindependent Communication?

SOAP (Simple Object Access Protocol), which is at once supported from WCF (Windows Communication Foundation).

Q28. What Is Binding And How Many Types Of Bindings Are There In Wcf?

A binding defines how an endpoint communicates to the world. A binding defines the delivery (which include HTTP or TCP) and the encoding getting used (including textual content or binary). A binding can contain binding factors that explain details just like the protection mechanisms used to comfy messages, or the message pattern utilized by an endpoint.

WCF helps 9 varieties of bindings.

Basic binding: Offered by means of the BasicHttpBinding elegance, this is designed to expose a WCF carrier as a legacy ASMX web provider, so that old customers can work with new offerings. When used by the consumer, this binding allows new WCF customers to work with antique ASMX offerings.

TCP binding: Offered by means of the NetTcpBinding magnificence, this makes use of TCP for crossmachine verbal exchange at the intranet. It helps a diffusion of features, such as reliability, transactions, and protection, and is optimized for WCFtoWCF communication. As a result, it requires both the patron and the provider to use WCF.

Peer community binding Offered by the NetPeerTcpBinding magnificence, this makes use of peer networking as a transport. The peer networkenabled consumer and offerings all subscribe to the identical grid and broadcast messages to it.

IPC binding: Offered by means of the NetNamedPipeBinding class, this makes use of named pipes as a delivery for samemachine conversation. It is the most comfortable binding since it can not receive calls from outside the system and it helps a diffusion of features much like the TCP binding.

Web Service (WS) binding: Offered by the WSHttpBinding elegance, this uses HTTP or HTTPS for shipping, and is designed to provide a diffusion of capabilities including reliability, transactions, and protection over the Internet.

Federated WS binding: Offered through the WSFederationHttpBinding elegance, that is a specialization of the WS binding, presenting aid for federated security.

Duplex WS binding: Offered by the WSDualHttpBinding class, this is similar to the WS binding except it also helps bidirectional communique from the service to the patron.

MSMQ binding: Offered by the NetMsmqBinding class, this uses MSMQ for delivery and is designed to provide aid for disconnected queued calls.

MSMQ integration binding: Offered by means of the MsmqIntegrationBinding class, this converts WCF messages to and from MSMQ messages, and is designed to interoperate with legacy MSMQ clients.

Q29. Advantages Of Hosting Wcf In Iis?

Provides system activation and recycling ability thereby growing reliability

It is a simplified manner of deployment and improvement of hosted offerings.

Hosting WCF offerings in IIS can take gain of scalability and density features of ASP.NET

Q30. How Do We Customize Data Contract Names For Generics Types?

We can personalize the standard datacontract names with the aid of allowing parameters. Find the Example below

[DataContract(Name = "Shape_1_brush_and_0_shape")]

public class Shape< Square,RedBrush>

// Code not shown.

 

Here, the Data Contract Name is "Shape_RedBrush_brush_and_Square_shape”

0 - First Parameter in the everyday kind.

1 - Second Parameter inside the familiar type.

Q31. What Is Message Contract In Wcf?

Message Contract : Message Contract is the way to manipulate the SOAP messages, sent and received with the aid of the consumer and server.

Message Contract can be used to add and to get the custom headers in SOAP message Because of Message Contract we will customize the parameters despatched the usage of SOAP message between the server and consumer.

Q32. How To Configure Reliability While Communicating With Wcf Services?

Reliability can be configured within the patron config report by way of including reliableSession below binding tag.

<system.ServiceModel>

<services>

<service name = "MyService">

<endpoint

address = "net.Tcp://localhost:8888/MyService"

binding = "netTcpBinding"

bindingConfiguration = "ReliableCommunication"

contract = "IMyContract"

/>

</service>

</services>

<bindings>

<netTcpBinding>

<binding name = "ReliableCommunication">

<reliableSession enabled = "true"/>

</binding>

</netTcpBinding>

</bindings>

</system.ServiceModel>

Reliability is supported by means of following bindings only

NetTcpBinding

WSHttpBinding

WSFederationHttpBinding

WSDualHttpBinding

Q33. What Are Various Ways Of Hosting Wcf Services?

There are three major ways of web hosting a WCF services

Selfhosting the service in his very own application domain. This we have already blanketed within the first phase. The provider is available in to lifestyles when you create the object of Service Host elegance and the service closes whilst you name the Close of the Service Host magnificence.

Host in utility area or process furnished through IIS Server.

Host in Application area and system furnished with the aid of WAS (Windows Activation Service) Server.

Q34. What Is Transport And Message Reliability?

Transport reliability (along with the one offered by way of TCP) gives pointtopoint guaranteed shipping on the community packet level, in addition to guarantees the order of the packets. Transport reliability isn't resilient to dropping community connections and a diffusion of other verbal exchange problems.

Message reliability offers with reliability on the message level impartial of how many packets are required to deliver the message. Message reliability affords for endtoend assured transport and order of messages, regardless of what number of intermediaries are concerned, and how many network hops are required to deliver the message from the customer to the provider.

Q35. What Is The Use Of Servicebehavior Attribute In Wcf ?

ServiceBehaviour characteristic is used to specify the InstanceContextMode for the WCF Service elegance (This can be used to maintained a nation of the carrier or a customer too)

There are 3 instance Context Mode within the WFC

PerSession : This is used to create a brand new example for a service and the identical instance is used for all technique for a particular patron. (eg: State may be maintained consistent with consultation via affirming a variable)

PerCall : This is used to create a new example for each name from the client whether or not identical purchaser or extraordinary. (eg: No state may be maintained as on every occasion a new instance of the carrier is created)

Single : This is used to create handiest one instance of the carrier and the identical example is used for all the patron request. (eg: Global kingdom can be maintained but this will be relevant for all clients)

Q36. How To Define A Service As Rest Based Service In Wcf?

WCF 3.Five gives specific help for RESTful verbal exchange the use of a new binding named WebHttpBinding.

The under code shows how to show a RESTful provider

[ServiceContract]

interface IStock

[OperationContract]

[WebGet]

int GetStock(string StockId);

 

Q37. What Is Endpoint In Wcf?

Every provider have to have Address that defines where the provider resides, Contract that defines what the provider does and a Binding that defines a way to communicate with the service. In WCF the connection between Address, Contract and Binding is known as Endpoint.

Q38. What Was The Code Name For Wcf?

The code call of WCF became Indigo .

WCF is a unification of .NET framework conversation technologies which unites the following technology:

NET remoting

MSMQ

Web services

COM+

Q39. What Is The Difference Between Xmlserializer And The Datacontractserializer?

DataContractSerializer is the default serializer fot the WCF

DataContractSerializer could be very fast.

DataContractSerializer is essentially for very small, easy subset of the XML infoset.

XMLSerializer is used for complex schemas.

Q40. What Are The Different Platforms Where We Can Host Wcf Service ?

WCF Services can be hosted on following structures

WAS(Windows Activation Service)

Self Hosting

IIS

Q41. What Is Address Header In Wcf?

Address Header includes the records that's sent with every request, it is able to be used by either cease factor provider or any intermediate tool for figuring out any routing logic or processing good judgment.

WCF offers AddressHeader elegance for this purpose.

Example :

AddressHeader addressHeader= AddressHeader.CreateAddressHeader("Name of the header", "Information blanketed in header ");

Once the AddressHeader example is created, it could be associated with stop factor example as follows :

EndpointAddress endpoint = new EndpointAddress(new Uri("http://myserver/myservice"), addressHeader);

Q42. What Is The Messaging Pattern? Which Messaging Pattern Wcf Supports?

Messaging Pattern : Messaging patterns describes how patron and server ought to exchange the message. There is a protocol between client and server for sending and receiving the message. These are also known as Message Exchange Pattern.

WCF helps following 3 varieties of Message Exchange Patterns

request respond- (default message alternate sample)

OneWay (Simplex / datagram)

Duplex(CallBack)

Q43. What Is Address In Wcf And How Many Types Of Transport Schemas Are There In Wcf?

Address is a way of letting client understand that in which a provider is located. In WCF, every provider is associated with a completely unique deal with. This incorporates the vicinity of the service and delivery schemas.

WCF supports following delivery schemas

HTTP

TCP

Peer network

IPC (InterProcess

Communication over named pipes)

MSMQ

Q44. What Is Service Host Factory In Wcf?

Service host factory is the mechanism by way of which we can create the times of provider host dynamically because the request is available in.

This is useful while we need to enforce the occasion handlers for opening and ultimate the provider.

WCF offers ServiceFactory class for this cause.

Q45. How To Set The Timeout Property For The Wcf Service Client Call?

The timeout belongings can be set for the WCF Service customer call the usage of binding tag.

<client>

<endpoint

...

Binding = "wsHttpBinding"

bindingConfiguration = "LongTimeout"

...

/>

</client>

<bindings>

<wsHttpBinding>

<binding name = "LongTimeout" sendTimeout = "00:04:00"/>

</wsHttpBinding>

</bindings>

If no timeout has been detailed, the default is taken into consideration as 1 minute.

Q46. How The Concurrency Mode Is Specified In Wcf Service?

The concurrency mode is precise the use of the ServiceBehavior characteristic on the magnificence that implements the provider.

Ex.

[ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Single)]

Public class ServiceClass : IServiceInterface

//Implementation Code

 

There are 3 viable values of ConcurrencyMode enumeration

Single

Reentrant

Multiple

Q47. What Is Fault Contracts In Wcf?

Fault Contracts is the way to deal with exceptions in WCF. The trouble with exceptions is that those are era precise and consequently can not be exceeded to different stop due to interoperability issue. (Means either from Client to Server or viceversa).

There should be another way representing the exception to guide the interoperability. And right here the SOAP Faults comes into the image.

Soap faults aren't specific to any particular generation and they may be based totally on industry standards.

To assist SOAP Faults WCF affords FaultException elegance. This class has  bureaucracy:

FaultException : to send untyped fault lower back to purchaser

FaultException<T>: to ship typed fault records to the customer

WCF service also presents FaultContract characteristic in order that developer can specify which fault may be despatched by using the operation (approach). This attribute may be applied to operations most effective.

Q48. What Is The Difference Wcf And Web Services?

Web offerings can simplest be invoked by way of HTTP (traditional webservice with .Asmx). While WCF Service or a WCF thing may be invoked via any protocol (like http, tcp etc.) and any shipping kind.

Second net offerings are not bendy. However, WCF Services are bendy. If you're making a new edition of the service you then want to simply divulge a brand new quit. Therefore, offerings are agile and that is a very practical approach looking on the cutting-edge commercial enterprise developments.

We broaden WCF as contracts, interface, operations, and records contracts. As the developer we are greater targeted on the commercial enterprise good judgment services and want no longer worry approximately channel stack. WCF is a unified programming API for any form of services so we create the service and use configuration statistics to installation the conversation mechanism like HTTP/TCP/MSMQ and so forth

Q49. Difference Between Wcf And Web Services?

Web Services

It Can be accessed best over HTTP

It works in stateless environment

WCF

WCF is bendy because its services may be hosted in one-of-a-kind kinds of applications. The following lists several not unusual situations for web hosting WCF offerings:

IIS

WAS

Selfhosting

Managed Windows Service




CFG