WCF Interview Questions and Answers (209) - Page 5

Explain briefly the three way of communication between source and destination in WCF ?

Simplex - Also known as one way communication. Source will send a message to the target, but target will not respond to the message.

Request/Replay - It is two way communications, source send message to the target, target will resend the response message to the source. But in this scenario at a time only one can send a message (that is), either source or destination.

Duplex -Also known as two way communication, both source and target can send and receive message simultaneously.



Thanks and Regards
Akiii
Can you show me an example in how to write a Message Contract in WCF ?

[MessageContract]

public class EmployeeDetails
{
[MessageHeader]
public int ID;

[MessageBodyMember]
public string First_Name;

[MessageBodyMember]
public string Last_Name;
}


Message contract can be applied to type using MessageContract attribute as shown above. We can add custom header and custom body by using MessageHeader and MessageBodyMember attribute respectively.

When EmployeeDetails type in the service operation is used as parameter then WCF will add an extra header call 'ID' to the SOAP envelope. It also add First_Name, Last_Name as an extra member to the SOAP Body.



Thanks and Regards
Akiii
Why do we need MessageContract when DataContract can do the job ?

When we need a higher level of control over the message, such as sending custom SOAP header, then we can use MessageContract instead of DataContract . But in general cases, most of the messaging needs can be fulfilled by DataContracts.




Thanks and Regards
Akiii
State 3 primary aspects of WCF ?

(1) Inter-operability with applications built on differnet technologies.

(2) Unification of the original Dotnet Framework communication Technologies.

(3) Support for Service Oriented Architecture (SOA).



Thanks and Regards
Akiii
If you have a Dotnet Web Service and a Java Client Application, then which Communication technology will you use other than WCF ?

Web Service (that is), ASMX will be the most likely way to achieve cross-vender inter-operability.



Thanks and Regards
Akiii
If both the application are in Dotnet then which technology is used for better performance apart from WCF ?

NOTE: This is objective type question, Please click question title for correct answer.
State the three components that a WCF service must have ?

The three components that a WCF must implement are :-

(1) Service Class = This can be implementated in any dotnet language. It implements one or more methods.

(2) Host Process = A process in which the service will run.

(3) End-Points = One or more end-points are provided that allow the clients to access the service.



Thanks and Regards
Akiii
In WCF, can we have multiple endpoints with the same address ?

NOTE: This is objective type question, Please click question title for correct answer.
Suppose you have created a WCF service. You have an interface stating your methods that must be exposed to the clients. But you have forgotten to specify "[OperationContract]" attribute in any of your method. What will happen ?

If you do not specify "[OperationContract] " in any of the methods in your interface then you will get the following error :-

IService1' has zero operations; a contract must have at least one operation 



Here, Iservice is the name of my Interface. you can have your own name.
So, it is mandatory to label "[OperationContract] " attribute to at least one method while declaring your interface methods or ServiceContract.



Thanks and Regards
Akiii
In WCF, can a struct be used as a DataContract ?

Yes, a struct can be used as a DataContract. For example :-

[DataContract]

struct EmployeeInfo
{
[DataMember]
public int id;

[DataMember]
public string name;

[DataMember]
public DateTime joining_date;
}



Thanks and Regards
Akiii
In WCF, does BasicHttpBinding supports HTTPS ?

NOTE: This is objective type question, Please click question title for correct answer.
In WCF, is SOAP envelope created while using WebHttpBinding ?

No, SOAP envelope is not created in WebHttpBinding . The information is trasmitted through HTTP or HTTPS.



Thanks and Regards
Akiii
In WCF, which is the right binding for RESTful communication and other situations where SOAP isn't required ?

NOTE: This is objective type question, Please click question title for correct answer.
In WCF, which is/are used for representing content in WebHttpBinding ?

NOTE: This is objective type question, Please click question title for correct answer.
How can you define an Endpoint problematically in WCF ?

ServiceHost s = new ServiceHost(typeof(EmployeeReservations));

s.AddEndpoint(typeof(EmployeeReservations), new BasicHttpBinding(),
"http://www.google.com/employee/emp.svc");


EmployeeReservations is the name of the contract.
http://www.google.com/employee/emp.svc is the address of the web service.



Thanks and Regards
Akiii
Defining endpoints programmatically in WCF is a good practice or not ?

Even though defining endpoints programmatically is possible, the most common approach
today is to use a configuration file associated with the service. Endpoint definitions embedded in code are difficult to change when a service is deployed, yet some endpoint characteristics, such as the address, are very likely to differ in different deployments. Defining endpoints in config files makes them easier to change, since changes don?t require modifying and recompiling the source code for the service class.



Thanks an Regards
Akiii
Which element is the prime element in the config file in which all WCF-based application configuration is contained ?

Configuration information for all services implemented by a WCF-based application is
contained within the system.serviceModel element. This element contains a services element that can itself contain one or more service elements.



Thanks and Regards
Akiii
How can I encrypt sensitive data in the WCF configuration file?

To encrypt sensitive data in WCF configuration file, use aspnet_regiis.exe tool.

Example: If you want to encrypt Connection String section of WCF config file, use -pe that means provider encryption .

aspnet_regiis -pe "connectionStrings" -app "/MachineDPAPI" 

-prov "DataProtectionConfigurationProvider"


-pe means provider encryption of configuration section.
-app means your application's virtual path.
-prov means provider name

For more info: http://msdn.microsoft.com/en-us/library/k6h9cz8h(VS.80).aspx
In WCF, which bindings/bindings doesn't support reliable session ?

NOTE: This is objective type question, Please click question title for correct answer.
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