WCF Exclusive Interview Questions and Answers (54) - Page 3

  • A joint initiative from DotNetFunda.Com and Questpond.
  • A one stop place on the internet to get trusted and proven Interview Questions (based on more than a decade of experience in this field) to ensure the success of the candidates.
  • You will find almost all Interview questions from Questpond here and this list is growing day by day with all latest and updated interview questions.

54 records found.

Get 650+ Questpond's Interview videos on discount

What is the concept of tracelevel in trace listeners?

In the previous question we have specified switch value as information. This value indicates what type and level of tracing information you want to record. Below is the list of the same.
 


Trace Level

Description

Off

Ignore all trace messages

Critical

Log unexpected processing events or unhandled exceptions have occurred. The application will terminate immediately or shortly.

Error

An unexpected processing event or exception has occurred. The application is still capable of continuing its processing.

Warning

Indicates there is a possible problem but the application will continue running.

Information

Application is running smoothly only that informative message is recorded. In this case messages are just milestones.

Verbose

Very similar to information but provides more details as compared.

ActivityTracing

In this case messages are related to communication between components and the activities.

All

In this case all messages are captured.
Trace level value is specified in ‘source’ tag in switch value. For instance the below ‘web.config’ snippet indicates the trace type as ‘Information’.

<system.diagnostics>

<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing">
............
............
............
............

What is a service level message and transport level message?

You can log WCF message at two levels one is service level and the other is transport level. Service level:-In this the messages are logged as they enter the user code or leave the user code. Transport level: - In this the messages are logged as they are ready to be encoded / decoded. All transport level, infrastructure messages and also reliable messaging is logged. You specify the message levels in the diagnostics node as shown in the below code snippet.


<system.serviceModel> 

<diagnostics>
<messageLogging
logEntireMessage="true"
logMalformedMessages="false"
logMessagesAtServiceLevel="false"
logMessagesAtTransportLevel="true"
maxMessagesToLog="3000"
maxSizeOfMessageToLog="10000"/>
</diagnostics>
</system.serviceModel>

‘Messagelogging’ also has other attributes , below is the short description about the same.

 

Attribute

Description

logEntireMessage

Should the entire message be logged on only the header.

logMalformedMessages

Should malformed messages be logged.

logMessagesAtServiceLevel

Should service-level messages be logged.

logMessagesAtTransportLevel

Should transport level messages be logged.

maxMessageToLog

Number indicating how many messages should be logged.  

maxSizeOfMessageToLog

The default value is 256Kb. Max size of the message log.

 

WCF Interview Question - What is WCF?

WCF is a unification technology, which unites the following technologies:-
     NET remoting
     MSMQ
     Web services
     COM+.


Below figure depicts WCF fundamentals pictorially.



Regards,


WCF Interview Question - What are Address,Binding,Contract(A-B-C)?

Address(Where):- An Address indicates where we can find the service. Address is a URL, which points to the location of the service.


Binding(How):- Bindings determine how the endpoints interacts(communicate) with the services.In other words it determines how communications is done.


Contract(What):-It defines, what kind of protocol your service is using currently.


Regards,


WCF Interview Question - What are the different ways of hosting WCF services?

WCF  service can be hosted by three diffrent way as below.



  1. Self-hosting.

  2. IIS Server.

  3. WAS (Windows Activation Service).

Regards,



WCF Interview Question - How do you do Self-Hosting?

The following steps are followed to do Self-hosting.


Step1:    //Create a URI to serve as the base address
            // Address as well binding

Uri httpUrl = new Uri("http://localhost:8010/MyService/HelloWorld");


Step2: //Create ServiceHost           

 ServiceHost host = new ServiceHost(typeof(ClassLibrary1.HelloWorldService),httpUrl);

Step3: //Add a service endpoint      

host.AddServiceEndpoint(typeof(ClassLibrary1.IHelloWorldService) , new WSHttpBinding(), "");

Step4: //Enable metadata exchange

ServiceMetadataBehavior smb = new ServiceMetadataBehavior();

smb.HttpGetEnabled = true;          
host.Description.Behaviors.Add(smb);


Step5: //Start the Service           

host.Open();

Step6:

Console.WriteLine("Service is host at " + DateTime.Now.ToString());          

Console.WriteLine("Host is running... Press <Enter> key to stop");          
Console.ReadLine();

Regards,

 


WCF Interview Question - What are Service Contract,Operation Contract and Data Contract?

Service Contract:-Service Contract is used to define the service name.


Operation Contract:-Operation contract defines the methods in the services.


Data Contract:-Data contract defines custom data types in the services.


Regards,


WCF Interview Question - How do you do IIS-Hosting?

IIS-Hosting is done using .SVC file.

For more details please click the following link


Regards,


WCF Interview Question - What is the difference between Basic httpbinding and WShttpbinding?

Basic Httpbinding:In httpbinding Data is sent as a plain text.In other words,there is no security provided for the message when the client calls happen.
This is aimed for clients who do not have .NET 3.0 installed and it supports wider ranges of clients. Many of the clients like Windows 2000 still do not run .NET 3.0. So older version of .NET can consume this service.
It uses SOAP1.1 version.


WShttpbinding:As WsHttBinding supports WS-*, it has WS-Security enabled by default. So the data is not sent in plain text.
As its built using WS-* specifications, it does not support wider ranges of client and it cannot be consumed by older .NET version less than 3 version.
It uses SOAP 1.2 and WS-Addressing specification.


Regards,




WCF Interview Question - How do we do security in WCF?

In WCF there are two types of Security,transport level security and message level security.


Transport Security:Transport level security happens at the channel level. Transport level security is the easiest to implement as it happens at the communication level. WCF uses transport protocols like TCP, HTTP, MSMQ etc and every of these protocols have their own security mechanisms. One of the common implementation of transport level security is HTTPS. HTTPS is implemented over HTTP protocols with SSL providing the security mechanism. No coding change is required it’s more of using the existing security mechanism provided by the protocol.


Message Security:Message level security is implemented with message data itself. Due to this it is independent of the protocol. Some of the common ways of implementing message level security is by encrypting data using some standard encryption algorithm.


Below Diagram illustrate the concept of security in WCF.



Regards,


WCF Interview Question - Why do we need WCF?

We need WCF when we want to expose a service which can be consumed by clients, which are in different technologies.


Regards,


WCF interview questions - What are the 3 ways of implementing WCF(Windows Communication Foundation) concurrency?

Three ways by which you can handle concurrency in WCF is Single, multiple and reentrant. To specify WCF concurrency we need to use the ‘ServiceBehavior’ tag as shown below with appropriate ‘ConCurrencyMode’ property value.



Figure:


Single: - A single request has access to the WCF service object at a given moment of time. So only one request will be processed at any given moment of time. The other requests have to wait until the request processed by the WCF service is not completed.


Multiple: - In this scenario multiple requests can be handled by the WCF service object at any given moment of time. In other words request are processed at the same time by spawning multiple threads on the WCF server object. So you have great a throughput here but you need to ensure concurrency issues related to WCF server objects.


Reentrant: - A single request thread has access to the WCF service object, but the thread can exit the WCF service to call another WCF service or can also call WCF client through callback and reenter without deadlock.


You can also view video on WCF one way contract as follows: -



WCF interview questions: - What is WCF REST?

Before we define WCF REST, lets define REST. REST is an architectural style built on certain principles using the current “Web” fundamentals.


It has five important principle: -




  • Everything is a resource.
  • Every resource is identified by a unique identifier
  • Use simple and uniform interfaces.
  • Communication are done by representation.
  • Be Stateless.




To implement WCF REST we need to use first enable webhttp bindings in behavior as shown in the below code snippet: -


 <endpointBehaviors>

<behavior name="NewBehavior0">
<webHttp />
</behavior>
</endpointBehaviors>

We can then use WebGet or WebInvoke to ensure that our URL is invoked by using HTTP POST or GET: -




[OperationContract]

[WebGet(UriTemplate = "/Students/{id}")]
string getStudents(string id);


Also see our following video on explanation of REST: -




WCF Interview questions: - Can we do method overloading in WCF service?

Many developers would answer this question as Yes because C# is used in WCF and C# is Object oriented, so a natural thinking would be WCF should also support method overloading.


The fact is it does not, surprised right :-). If you have a method which is overloaded you need to use the "Name" parameter in the "OperationContract" to ensure that the proxy class generates different names.


See the below code for more details. In the below code we have "GetData" which is overloaded but we are saying to the client to generate the methods with name "GetData" and "GetData1".


[ServiceContract]

public interface IService1
{

[OperationContract(Name="GetData")]
string GetData(int value);

[OperationContract(Name="GetData1")]
string GetData(int value, int value1);


// TODO: Add your service operations here
}

Do also see the below video why practically we can not do method overloading in WCF service: -



More WCF Interview Questions & Answers here

Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Exclusive Interview Questions and Answers Categories