Click below for Step by Step and Interview Q & A (dotnetinter) wrote,
Click below for Step by Step and Interview Q & A
dotnetinter

What are the various ways of consuming WCF services?(WCF C# interview questions with answers)

There are two ways of consuming WCF service one by using add reference and other by using channel factory.


  1. Add service reference and generate proxy

WCF services


   FirstServiceClient c =   newFirstServiceClient();
Console.WriteLine(c.GetData3());
   Console.ReadKey();


2.  We can use ChannelFactory
     
ChannelFactory<IFirstService> c = newChannelFactory<IFirstService>("b1");
IFirstService f = c.CreateChannel();
Console.WriteLine(f.GetData3());

When to use what?

ChannelFactory

When you have access to both service and client use channel factory. Because


  • In case channel factory, you need to explicitly define client endpoints.

  • You need to have direct access to service contract interface

Advantage


  • Every time when we make some changes into service contract , it’s not required to update reference at client side (because there is no reference)

Disadvantages

  • More client side work.

Proxy

When you won’t have control over the service use proxies

Advantages


  • Less client side work.

  • When we generate proxy, Visual studio does everything for us. It not only generates proxy service classes but also generates client endpoints.

Disadvantages


  • Every time you make changes into service contract you have to update service reference.

Below is a great WCF video created by www.questpond.com which discusses one more important WCF interview question which talks about canmethod overloading be done in WCF.



Other References:-
Tags: .net interview questions, c# interview questions, csharp interview questions, it interview questions with answers, programming iterview questions, wcf channelfactory interview questions, wcf fresher interview questions, wcf interview questions, wcf(windows communication foundation)
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments