Wednesday, February 17, 2010

Notes on Programming WCF - Part III - Client side programming


Excerpts on a great WCF book: "Programming WCF Services- by Juval Lowy"


Client Side Programming:
1- Generating the Proxy
a. Add a reference , point to metadata address click go and then ok to generate proxy and have client config file modified
1. Regenerate by going to service references right click on your service and choose update
b. SvcUtil : the only advantage of this to VS 2008 method (above) is that you can run it before build in a command line
1. When in-proc client and server configuration file could be one
2- WCF provided host
a. WcfSvcHost.exe
3- Working with the proxy
a. Closing the proxy
Always close proxy after being done with it to release the connection held toward the service
Call to Close() could be replaced by calling Dispose() which means we can use
Using (MycontractProxy proxy = new MycontractProxy ())
{
// …
}
Or
IMyContract proxy = new MyContractClient( );
using(proxy as IDisposable)
{
proxy.MyMethod( );
}
b. Call time out
Each call made by a WCF client must complete within a configurable timeout, this offers an elegant way to deal with deadlocks.
The exact value of the timeout is a property of the binding, where the default timeout is one minute. To provide a different timeout, set the SendTimeout property of the abstract Binding base class.
4- Transport Level Sessions
- The transport session is one of the key fundamental concepts of WCF, affecting reliability, instance management, error management, synchronization, transactions and security.
- WCF makes sure that every request from the same client gets channeled through same transport channel,
- This will insure that calls from client are processed in the same order they have been sent
- Transport session is usually closed upon closing the proxy, but if connection breaks there’s a 10 minutes timeout by default,
- If client tries to use the proxy after 10 minutes an exception will be thrown CommunicationObjectFaultedException
- You can reconfigure the idle time time-out through ReliableSession or OptionalReliableSession property from bindings that support the time-out, InactivityTimeout
- If both client and service configure the time-out the shorter period prevails
5- Reliability
Message reliability in WCF does not guaranty message delivery. All it provides is a guarantee that is the message does not reach its destination, the sender will be notified.
Ordered Delivery
WCF guarantees ordering of messages if protocol supports it
6- Client-side proxy hierarchy
- Proxy chaining
- Contract factoring:
Proper contract factoring results in more specialized, loosely coupled, fine-tuned and reusable contracts.

No comments:

Post a Comment