Saturday, October 16, 2010

Asynchronous Invocation in WCF (WCF Part 7)

 


The client calls the Begin operation by passing any required parameters, a callback function, and a state object. The callback function is called when the operation finishes.

object can be any object you want to pass to the callback function and in WCF it is usually a reference to the proxy:

 

[C#]
IAsyncResult iar = proxy.BeginAdd(i1, i2, MyCallback, proxy);

/*This function returns immediately and provides an IAsyncResult that the caller can use to check the state of the operation.*/

 

 

The callback function is executed when the service operation completes, and the callback function calls the matching End method:

 

[C#]

static void MyCallback(IAsyncResult iar)

{

   double val = ((AddProxy)iar.AsyncState).EndAdd(iar);

}

 

 


WCF Service Behavior:

it's very necessary to demonstrate how the clients will connect with the WCF Services (e.g. How many service instances will be used to serve the clients, operation counts, Error handling, Security, such as impersonation, authorization, Metadata   etc)

Behaviors may be code-only, or may also use configuration settings. e.g.

 

[C#]
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]

/*This line of code will make all the clients using the same instance of the service.*/

 

OR you can use Throttling:

Throttling allows you to set limits on access to a service, such as the number of connections or pending calls.

You configure throttling in the configuration file:
 

[XML]

<throttling maxConcurrentCalls = "12" maxConnections = "34" maxInstances = "56" />

 

Developers can also retrieve the throttling settings at runtime, and modify them before opening the service.

Developers can create custom behaviors by using IServiceBehavior and IEndpointBehavior.
 
  For More Info Please Visit: WCF Resources Page  

No comments:

Post a Comment

Search This Blog