Thursday, February 18, 2010

WCF Operations, Streaming, Faults - Part IV


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

Operations:
1- One-Way Operations:
- The methods should return void if they are marked as One-Way
- It is recommended that one-way operations should be applied on per-call or singleton services only.
2- Callback Operations: a.k.a Duplex Operations
- In order to wire a call back to a client it needs to be derived from a proxy with bidirectional communication , DuplexClientBase
i. Client needs to implement the call back interface,
ii. Create an instance off of the interface
iii. Create a new InstanceContext passing the callback instance
iv. Wait for call back while the proxy is still open
class MyContractClient : DuplexClientBase, IMyContract
{
public MyContractClient(object callbackInstance)
: base(callbackInstance)
{ }
//More constructors
public void DoSomething()
{
Channel.DoSomething();
}
}
class MyClient : IMyContractCallback, IDisposable
{
MyContractClient m_Proxy;
public void CallService()
{
m_Proxy = new MyContractClient(this);
m_Proxy.DoSomething();
}
public void OnCallback()
{...}
public void Dispose()
{
m_Proxy.Close();
}
}
Streaming
1- I/O Streams
WCF allows services to stream the reply, request or both.
2- Streaming and Binding
Only TCP, IPC and basic HTTP bindings support streaming.
You cannot use streaming if contract is set to SessionMode.Required
All streaming is off by default even you use Stream which is an abstract class.
To enable streaming set transferMode=”Streamed”
It is most likely required to set maxReceivedMessageSize to proper number (Default is 64K)
Faults:
1- Error Masking:
Client should not care about service errors just need to know something happened.
There are three types of exceptions that clients face dealing with WCF services.
1- Communication errors: bad network, bad uri and etc …
2- Proxy state errors: proxy is closed but is accessed or is faulted and is accesses , contract and binding mismatch, security protection level
3- Service generated errors:
2- Channel Faulting:
- Client can’t even close the proxy after an exception, only proxy.Abort is available
3- Fault propagation:
Using FaultException: T is an Exception (recommended)or any other type. This approach returns a non-CLR compatible type.

No comments:

Post a Comment