WCF Questions and Answers 

1.       How to develop Wcf rest service with XML and Json Format using get, post, put and delete protocols and how to consume this service with another web application and how to configure with different end points?
               i.      There are two ways in which you can develop REST services which can be queried using ODATA queries.
             ii.      Note that WEB APIs work over HTTP only.

2.       How to implement security concept in WCF service.
There are 2 things you need to take care of.
1.       Security over the wire
2.       Authentication and Authorization at the endpoint
I have made a video describing all the security features of WCF, and uploaded it to an FTP workspace. Please review these two videos, and get back to me with further questions:
Password: ^*21)!Hlw+Z1$D

3.       How can we host a service on two different protocols on a single server?
To do this you have to add multiple end points to your service. When you add an end point, you will be able to choose the protocol you want to use for that end point.

4.       Enumerate three message exchange patterns in the WCF model.
These are:
1.       Request-Reply, 2. One Way, 3. Duplex
Message Exchange patterns are used to define how the client and server should communicate. Review the following link and let me know if you have further questions.

5.       If the service operation returns void, what is the message exchange pattern? Is the client waiting the operation to be completed in this case?
If you have a return value in your operation, then you should not be using One Way message exchange. If your return value is void, you may still use Request-Reply. The above article makes this clear.

6.       What is the difference between the request-response pattern and the duplex pattern?
Duplex communication means both the client and the service can send messages to each other. A duplex communication can either be one-way or request-response. The above article makes this concepts clear.

7.       Is the server set up a client address or the client sets it up in the duplex communication? Server uses this address to send the data back to the client.
In duplex communication, the client defines a callback for the service. The server uses a callback channel created when the client communicated with the service for the first time. Review the above article for the configuration.

8.       In what order do we have to catch the exceptions: TimoutException, FaultException, FaultException<MyException>, CommunicationException?
The Order of the exception handlers does not matter. What you need to know is when to catch which exception. The following is an overview of the different kinds of exceptions, the client needs to be aware of: http://blogs.msdn.com/b/pedram/archive/2008/01/25/wcf-error-handling-and-some-best-practices.aspx

9.       You are developing a WS. Do you have to include the error(s)/success nodes into the response or have to use a Fault message to handle the WS  errors? What is the difference in these approaches?
Do not understand the question. Please elaborate.

10.   Is it possible to log the messages on the service side? On the client side? How to switch on the logging?
In WCF message tracing needs to be enabled using the configuration file. I have spoken about it in the video link. Find more information here: http://msdn.microsoft.com/en-us/library/ms730064.aspx

11.   What is a difference between the service messages and transport messages?
You can log messages at both Service Level and transport level. Transport level logs will have diagnostic information about the transport, encoding decoding etc..
Service level logs will have information about the execution of the service contract.

12.   What kind of behaviors are possible in WCF?
·         Service Behaviors
·         Endpoint Behaviors
·         Operation Behaviors
·         CallBack Behaviors

13.   Why the Endpoint behavior cannot be used as an attribute?
The services are independent of endpoints. You can have many endpoints for a service. Therefore it does not make sense to provide Endpoint Behavior within Service contract.

14.   Why the Contract and the Operation behavior cannot be used in the configuration files?
The same reason as above.

15.   What is the difference in the attributes the binding and the bindingConfiguration of the <endpoint> element?
Binding specifies which binding type you will be using (http, net.tcp, msmq, wsHTTP, etc.). The additional configurations for that binding can be specified in the Binding configurations.
You can define as many binding configurations as you want but for any given end point you can only use one of those configurations. Also the binding configuration selected should be for the binding type selected in the endpoint element.

16.   Where session stores the session information? What is the general store for the WCF session?
WCF sessions are stored in the instance of the service object that is created. The session is available for the lifetime of the instance.

17.   Does the SessionMode.NotAllowed increase the performance?
Yes, there are a lot of performance implications for using sessions. You will only use sessions if you want to tie a client to the service instance. Please review the following article on instance management: http://msdn.microsoft.com/en-us/magazine/cc163590.aspx

18.   What is it the Terminating and Initiating of the OperationContract? Could be the OperationContract Terminating and Initiating at the same time?
IsInitiating and IsTerminating are used to control the lifetime of a session. Review the following link for more details:

19.   How does a client start a session?
The WCF session are explicitly initiated and terminated by the calling application (WCF Client).
 The SessionMode property on the Service contract can be used to mandate, allow, or prohibit a session. The 3 session modes are Allowed, NotAllowed, and Required.
However note that the session mode property does not specify the type of session-based behavior the contract requires. That is specified by the binding at runtime.
If the session mode is Required, and the binding does not support sessions, then a runtime exception is thrown.
If the session mode is Required/Allowed then the bindings can implement sessions. The following are some sytem provided bindings and their corresponding session options:
Binding
Interoperability
Mode of Security (Default)
Session (Default)
Transactions
Duplex
BasicHttpBinding Basic Profile 1.1 (None), Transport, Message, Mixed None, (None) (None) n/a
WSHttpBinding WS None, Transport, (Message), Mixed (None), Transport, Reliable Session (None), Yes n/a
WS2007HttpBinding WS-Security, WS-Trust, WS-SecureConversation, WS-SecurityPolicy None, Transport, (Message), Mixed (None), Transport, Reliable Session (None), Yes n/a
WSDualHttpBinding WS None, (Message) (Reliable Session) (None), Yes Yes
WSFederationHttpBinding WS-Federation None, (Message), Mixed (None), Reliable Session (None), Yes No
WS2007FederationHttpBinding WS-Federation None, (Message), Mixed (None), Reliable Session (None), Yes No
NetTcpBinding .NET None, (Transport), Message,
Mixed
Reliable Session, (Transport) (None), Yes Yes
NetNamedPipeBinding .NET None,
(Transport)
None, (Transport) (None), Yes Yes
NetMsmqBinding .NET None, Message, (Transport), Both (None) (None), Yes No
NetPeerTcpBinding Peer None, Message, (Transport), Mixed (None) (None) Yes
MsmqIntegrationBinding MSMQ None, (Transport) (None) (None), Yes n/a

Sessions are also related to the instancing behavior of the service. You can have one instance with multiple sessions, or you can have a single service instance for each session. You can control this using the instance context mode on the service behavior. The 3 instance context modes are:
1.       Per call: which means new instance for every message from any client. Using session makes no sense in this case
2.       Per session: Which means new instance for every client. In this case one session will be associated with every client instance
3.       Single: Which means that there is only a single instance of the service. And all sessions are associated with this instance. 

No comments: