WCF

1.What is WCF ?
Windows Communication Foundation is a framework for building Service
Oriented Application(SOA).It was introduced in .Net Framework 3.0 and is
basically a combined feature of WebService,Remoting,MSMQ and COM+.

2. Difference between Webservice and WCF ?
->WebService cab be  hosted only in IIS 
WCF can be hosted in IIS,windows Service,Self hosting and windows
activation service.
->WebService can be accessed only through http protocol. WCF cab be accessed through http,tcp,MSMQ and named pipes.
->WebService works in stateless env. WCF can maintain  states and sessions.
->Webservice uses System.Xml.serialization name space for serialization. WCF uses System.Runtime.Serialization namespace  for serialization

3.What is .svc file? 
Its the file where service is defined and it will be the point of contact from 
the consumers.It contains name of service and code behind file name.It is used to know about the service.

4.What are different ways in which WCF can be hosted ?
The different hosting techniques are
1.IIS hosting--This is the most commonly used hosting technique.Here IIS is
used as a  server and has following 
advantages -> starts automatically on the first client  request,process recyling.
Disadvantage-- It supports only http protocol

2.Self hosting-This is hosting the WCF  urself either in console/windows 
application also  in windows service .
  • The host process  should be running before a client makes a call to servc.
  •  Its easier to debug and deploy.
  •  Lifetime of services can be controlled using Open and Close methods.
3. WAS hosting(Windows Activation Server hosting)--WAS was introduced
with windows  vista and it is shipped with IIS 7.0. it is more powerful than
IIS 6.0 as it can support  http,tcp and named pipes whereas IIS 6.0 can 
support only http. 

4.Windows Service Hosting--Here the service can be programmed to start 
when the system starts.

5.What do you mean by ABC in WCF ?
ABC in WCF means -
Address ->  A stands for Address. It indicates where you service is located.A URL is used to point to the location.Depending on whethere the service is hosted in http,tcp... the address varies. eg-
http://localhost/Test
net.tcp//localhost/Test

Binding ->B stands for Binding which specifies how the client should communicate with the service.

Contract->C stands for contracts. It exposes the operation provided by the Service. It is a  contract.


6.What is an endpoint in WCF ? 
ABC together constitute an endpoint.Endpoint provides the client access to the functionality exposed by the service.
  
7.What do you mean by contarcts. What are the different types of contracts ? 
Contracts are  standard way of describing the operations performed by a Service.Diff types of contracts are--


1.Service Contracts 
It describes the operations provided by the service.WCF service  
should have atleast one ServiceContract.it has two attribute-
[ServiceContract] --Used to define the interface.Client can talk to services via interfaces.
Similar to [Webservice] attribute in Webservice
[OperationContract]-Used to define methods inside the interface.Similar to 
[WebMethods]   
        eg- 
                 [ServiceContract()]
                 public interface ISimpleCalculator
                {
                    [OperationContract()]
                    int Add(int a, int b);
                 }
2. DataContract
 This defines the data which is exchanged between the client and the service.
 these are used manily for used defined objects.They are of two types
 [DataContract]--defines the class
 [DataMember] --defines the properties.
eg-
[DataContract]
 class Name
  {
      public string Fullname; 
      [DataMember]
       public string FirstName;
       [DataMember]
       public string SurName;
   }

Inbuilt types like string (Fullname) are defined impicitly and they do not need
data contracts.
 
3.Fault Contracts.   
These are used to handle errors in a service.When a service throws an error it
does not reach the client side.  But by using fault contract we can come to know the
error that is raised by the service.
eg-
[ServiceContract()]
    public interface ISimpleCalculator
    {
        [OperationContract()]
        [FaultContract(typeof(ArgumentException))]
        int Add(int a, int b);
    }
Raise the exception as
throw new FaultException("error") ;

4.Message Contracts
Message Contract defines the way messages are transferred  using SOAP messages. It
is used if you want to customize the SOAP format.
eg-
[MessageContract]
public class CustomerDetails
{
    [MessageHeader]
    public string CustID;
    [MessageBodyMember]
    public string Name;
}

8.Whats the diff between Message Contract and Data Contract.
Data contracts are used to describe data types used by service.They can be either parameter or return type.
Message Contract are used to describe SOAP message format.They allow us to cotnrol the detail is SOAP header and body.

9.What namespace is used to access WCF ?
System.ServiceModel

10.What are the main components of WCF?
1.Service Class--functional class using any .net language.
2.Hosting environment--IIS,windows service etc
3.Endpoint--ABC

11.what is proxy in WCF?   
A proxy is a class by which a service client can Interact with the service.By the use of proxy in the client application we can call different methods in the service.


12.What are two method in which you can access WCF?
By Adding it as reference -- this will automatically generate the channel required for you to communicate with WCF.
By creating channel manullay- use ChannelFactory.
however the second method should be preferred one as pointed out in below article
http://www.eggheadcafe.com/tutorials/aspnet/a1647f10-9aa4-4b0c-bbd9-dfa51a9fab8e/adding-wcf-service-refere.aspx


13.How do you achieve method overloading in WCF?
By making use of name property in OperationContract
[ServiceContract]
interface ISimpleCalculator
{
 [OperationContract(Name="Add2numbers")]
 int Add(int a,int b)

 [OperationContract(Name="AddDouble")]
 int Add(double a,double b)
}
14.Why normal method overloading is not possible in WCF ?
Because WSDL is not a OO language and it does not support OOPs concept.

15. How do you host a webservice in windows service?

http://msdn.microsoft.com/en-us/library/ms733069.aspx

16.simple eg for using channel factory.

http://www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication

  
    

12 comments:

  1. Thanks a lot for such informative questions and answers.

    ReplyDelete
  2. Good collection.The answers are clear and simple to understand.Nice one!!

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Great knowledge I got from this post and very informative points you have shared here, Inmotion Review

    ReplyDelete
  5. Best Blog Ever !! For CSharp and Dot Net .

    Game Developers pm me .

    ReplyDelete
  6. "Great blog created by you. I read your blog, its best and useful information. You have done a great work. Super blogging and keep it up.php jobs in hyderabad.
    "

    ReplyDelete
  7. I really impressed for this blog because it has good content for learners. check it once now Angularjs Online Training

    ReplyDelete
  8. I have read your blog it is very helpful for me. I want to say thanks to you. I have bookmark your site for future updates.
    domeinnamen

    ReplyDelete
  9. Thanks for sharing this information. It is very helpful.

    ReplyDelete