.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!




Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.


Post New Question Subscribe to Interview Questions
 
Quick Links For Interview Questions Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  OOPs  JQuery  JavaScript/VBScript
BiztalkPatten/PracticesIISWCFWPFWWF
NetworkingAptitudeOthers  All    
 

WCF Interview Questions and Answers

What are Reliable Sessions in WCF?

Author: Alankar          Posted Date: April 02, 2015    Category: WCF     Points: 40

Reliable sessions actually ensure that the caller for messages will know about the lost message(s) but it can't guarantee about the delivery of message(s).
There is a misconception about reliable sessions that it ensures the session will never expire or stays for a very long time. This we can achieve by using timeout for sessions.

Difference between BasicHttpBinding and WsHttpBinding with respect to security?

Author: Alankar          Posted Date: April 02, 2015    Category: WCF     Points: 40

but basic difference with respect to security is as follows:
As WsHttpBinding supports advanced WS-* specification, it has a lot more security options available. For example, It provides message-level security i.e. message is not sent in plain text. Also it supports for WS-Trust and WS-Secure conversation.
While in case of BasicHttpBinding, it has fewer security options, or we can say, there is no security provided, by default. At transport level, it can provide confidentiality through SSL.

What are the core security concepts supported by WCF?

Author: Alankar          Posted Date: April 02, 2015    Category: WCF     Points: 40

There are four core security Features
1. Confidentiality: It's a confirmation about the recipient. Only the valid recipient can read the message when it passed between service and client.
2. Integrity: is to ensure that message received is not being tempered or changed during exchange.
3. Authentication: is a way for the parties (sender and receiver) to identify each other.
4. Authorization: ensures that what actions an authenticated user can perform?

What is a fault contract?

Author: Alankar          Posted Date: April 02, 2015    Category: WCF     Points: 40

Normally, by default, when some exception occurs at a WCF service level, it will not expose as it is to client. Reason is that WCF exception is a CLR exception and it doesn't make sense to expose it outside CLR because it contains internal details of service code like stack trace. So, WCF handles and returns error details to client using Fault Contract."So, fault contract is a contract that contains the details of possible exception(s) that might occur in a service code."
[ServiceContract]
public interface IService1
{
[OperationContract]
[FaultContract(typeof(MyFaultDetails))]
int MyOperation1();
}
[DataContract]
public class MyFaultDetails
{
[DataMember]
public string ErrorDetails { get; set; }
}
In implementing service...
public int MyOperation1()
{
Try{ //Do something.. }catch()
{
MyFaultDetails ex = new MyFaultDetails();
ex.ErrorDetails = "Specific error details here.";
throw new FaultException(ex,"Reason: Testing...");
}
}

Difference between using ChannelFactory and Proxies in WCF?

Author: Alankar          Posted Date: April 02, 2015    Category: WCF     Points: 40

A ChannelFactory creates a kind of Channel used by clients to communicate with service endpoints.
If we have control over Server and Client, then ChannelFactory is a good option because it relies on having local interfaces that actually describes the service i.e. service contract.
On the other hand, If we don't have control over server and only have WSDL/URL, then it's better to generate proxy using Visual Studio or SvcUtil.
SvcUtil is better option as compared to Visual Studio because we have more control in case of SvcUtil.

What is mexHttpBinding in WCF?

Author: Alankar          Posted Date: April 02, 2015    Category: WCF     Points: 40

In order to generate proxy, we need service metadata and mexHttpBinding returns service metadata.
If we look into our configuration file, service will have an endpoint with mexHttpBinding as follows:
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
and service metadata behavior will be configured as follows:
<serviceMetadata httpGetEnabled="true"/>
Before deployment of application to production machine, it should be disabled.
In order to support other protocols, related bindings are mexHttpBinding, mexHttpsBinding, mexTcpBinding.

What are the different ways to expose WCF Metadata?

Author: Alankar          Posted Date: April 02, 2015    Category: WCF     Points: 40

By default, WCF doesn't expose metadata. We can expose it by choosing one of the following ways:
1. In configuration file, by enabling metadata exchange as follows:
<system.serviceModel>
<services>
<service name="MyService.Service1?
behaviorConfiguration="MyService.Service1?>
<endpoint address=""
binding="wsHttpBinding"
contract="MyService.IService1?>
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyService.Service1?>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
2. ServiceHost can expose a metadata exchange endpoint to access metadata at runtime.
using (ServiceHost host = new ServiceHost(typeof(MyService)))
{
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = true;
host.Description.Behaviors.Add(behavior);
host.Open();
Console.WriteLine("My Service here...."); Console.ReadLine();
host.Close();
}

Can we have multiple endpoints for different binding types in order to serve different types of clients?

Author: Alankar          Posted Date: April 02, 2015    Category: WCF     Points: 40

Yes, we can have multiple endpoints for different binding types. For example, an endpoint with wsHttpBinding and another one with netTcpBinging.

Why to use WCF? or What are the advantages for using WCF?

Author: Alankar          Posted Date: April 02, 2015    Category: WCF     Points: 40

. Service Orientation is one of the key advantages of WCF. We can easily build service-oriented applications using WCF.
. If compared with ASMX web services, WCF service provides reliability and security with simplicity.
. As oppose to .NET Remoting, WCF services are interoperable.
. Different clients can interact with same service using different communication mechanism. This is achieved by using service endpoints. A single WCF service can have multiple endpoints. So, developer will write code for service once and just by changing configuration (defining another service endpoint), it will be available for other clients as well.
. Extensibility is another key advantage of WCF. We can easily customize a service behavior if required.

Which command is used to convert WSDL to a proxy

Author: Alankar          Posted Date: April 02, 2015    Category: WCF     Points: 40

svcutil.exe command will convert the WSDL to a proxy class for our client

Open visual studio command prompt window
click on visual studio command prompt,set the current folder to the location where you want the generated proxy and configuration files to be created.

Run SvcUtil.exe to generate the output files.




Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend