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


Top 5 Contributors of the Month
Sandeep Singh
Mayuri
stevemarkayden
kumarfurima
Preethi


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/Practices.IISWCFWPFWWF
NetworkingAptitudeOthers  All    
 

Interview Questions And Answers

In WCF, can a struct be used as a DataContract ?

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

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;

}

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 ?

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

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.

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

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

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

Can you show me an example in how to write a Message Contract in WCF ?

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

[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.


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

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

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.

What is a proxy class for WCF Service ?

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

It is a class by which a service client can interact with the service. The client will make an object of the proxy class and with the help of it will call different methods exposed by the service.

Are SOAP faults inter-operable ?

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

Yes, SOAP faults are inter-operable as they are expressed to clients in XML form.

.Net exception classes are not good to be used in SOAP faults. Instead we should define our own DataContract class and then use it in a FaultContract.
public interface ICalculator

{

[OperationContract]

[FaultContract(typeof(MathFault))]
int Divide(int n1, int n2);

}

[DataContract]

public class MathFault

{

[DataMember]

private string operation { get; set; }

[DataMember]

private string problemType { get; set; }

}

public int Divide(int n1, int n2)

{

try

{

return n1 / n2;

}

catch (DivideByZeroException)

{

MathFault objMath = new MathFault();

objMath.operation = "division";

objMath.problemType = "divide by zero";

throw new FaultException<MathFault>(objMath);

}

}

In WCF, what happens if there is an unhandled exception ?

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

The service model returns a generic SOAP fault to the client which does not include any exception specific details by default. However, an exception details in SOAP faults can be included using IncludeExceptionDetailsInFaults attribute. If IncludeExceptionDetailsInFaults is enabled, exception details including stack trace are included in the generated SOAP fault. IncludeExceptionDetailsInFaults should be enabled for debugging purposes only. Sending stack trace details is risky.

IncludeExceptionDetailsInFaults can be enabled in the web.config file :-
<behaviors>

<serviceBehaviors>
<behavior name="ServiceGatewayBehavior">

<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->

<serviceMetadata httpGetEnabled="true"/>

<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->

<serviceDebug includeExceptionDetailInFaults="true"/>

</behavior>

</serviceBehaviors>

</behaviors>


Can we propagate CLR Exception across service boundaries in WCF ?

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

No, we cannot propagate CLR Exceptions across service boundaries.

If you want to propagate exception details to the clients then it can be done through "FaultContract " attribute. This way a custom exception is being passed to the client.

What does the namespace "System.Runtime.Serialization" exactly do in WCF ?

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

WCF uses the class to convert objects into a stream of data suitable for transmitting over the network (this process is known as Serialization). It also uses them to convert a stream of data received from the network back into objects (De-Serialization).


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