Microsoft.Practices.SmartClient.DisconnectedAgent
Microsoft.Practices.SmartClient.EnterpriseLibrary
Initializing the Request Manager
- Invoke any of the two overloads of the static method Initialize.
// for default database that specified in the Data Access Application Block configuration.RequestManager requestManager = DatabaseRequestManagerIntializer.Initialize();
OR
RequestManager requestManager = DatabaseRequestManagerIntializer.Initialize("databaseName"); - To full control over the objects used to initialize the request manager, manually construct the objects and call the Initialize method
- EndpointCatalogFactory catalogFactory = new EndpointCatalogFactory("Endpoints");
catalog = catalogFactory.CreateCatalog();
SmartClientDatabase requestQueueDb = new
SmartClientDatabase(ConfigurationManager.ConnectionStrings["QueueConnectionString"].ConnectionString);
DatabaseRequestQueue requestQueue = new DatabaseRequestQueue(requestQueueDb, "RequestsQueue");
SmartClientDatabase deadLetterQueueDb = new SmartClientDatabase(ConfigurationManager.ConnectionStrings["QueueConnectionString"].ConnectionString);
DatabaseRequestQueue deadLetterQueue = new
DatabaseRequestQueue(deadLetterQueueDb, "DeadLetterQueue");
ConnectionMonitorAdapter adapter = new ConnectionMonitorAdapter(ConnectionMonitorFactory.CreateFromConfiguration());
RequestManager manager = RequestManager.Instance;
manager.Initialize(requestQueue, deadLetterQueue, adapter, catalog);
Creating a Simple Request
Request req = new Request();specify the online proxy type for the request. The proxy class is the one that Visual Studio generates when you add a Web reference to your project.
req.MethodName = "DeliveryRouteUpdate";
req.Endpoint = "MyWebServiceHost";
req.OnlineProxyType = typeof(MyWebServiceProxy);specify the behavior of the request
behavior.ProxyFactoryType = typeof(WebServiceProxyFactory);other OfflineBehavior properties are Tag, MaxRetries, Stamps
Adding Parameters to a Request
int customerCode = 1234;Handling Callbacks for a Request
string comment = "New value for comment";
req.CallParameters = CallParameters.ToArray(customerCode, comment);
req.Behavior.ReturnCallbackmethod that takes references to the Request, an Object array for the parameters (arguments) you submitted to the service, and an Object for any value returned by the Web service.
= new CommandCallback(typeof(MyDisconnectedServiceAgentCallbackClass),
"MyReturnCallbackMethod");
req.Behavior.ExceptionCallback
= new CommandCallback(typeof(MyDisconnectedServiceAgentCallbackClass),
"MyExceptionCallbackMethod");
public void MyReturnCallbackMethod(Request req, Object[] qParams,
Object result)
{
MessageBox.Show("Request succeeded. Return value is: "
+ result.ToString());
}
public OnExceptionAction MyExceptionCallbackMethod(Request req,
Exception ex)
{
MessageBox.Show("Your request failed with error: " + ex.Message);
return OnExceptionAction.Dismiss;
}
Adding a Request to a Queue
requestManager.RequestQueue.Enqueue(req);Removing a Request from a Queue
requestManager.DeadLetterQueue.Remove(req)Accessing Requests in a Queue
IRequestQueue theQueue = requestManager.RequestQueue;
// or:
IRequestQueue theQueue = requestManager.DeadLetterQueue;
// Count the number of requests in the queue.
Int32 queueCount = theQueue.GetCount();
// Get a reference to the next request in the queue.
Request nextRequest = theQueue.GetNextRequest();
// Get all the requests in the queue.
IEnumerable>Request> requests = theQueue.GetRequests();
// Get single request iterator by request ID.
Request requestById = theQueue.GetRequest(requestId);
// Get all the requests that have a specified Tag property value.
IEnumerable>Request> requestsByTag = theQueue.GetRequests("SalesOrder");
// Get all the requests that have a specified "stamps" value
// that is greater than or equal to a specified numerical value.
IEnumerable>Request> requestsByPrice = theQueue.GetRequests(5);
To remove a request from the queue, pass a reference to that request to the Remove method of the queue.
theQueue.Remove(req);Dispatching a Single Request Immediately
requestManager.RequestQueue.Enqueue(req);Dispatching All Pending Requests
requestManager.DispatchRequest(req);
requestManager.DispatchAllPendingRequests();Dispatching Specific Pending Requests
requestManager.DispatchPendingRequestsByTag("Sales Order");Starting and Stopping the Dispatcher Service
if (requestManager.Running)
{
reqManager.StopAutomaticDispatch();
OR
reqManager.StartAutomaticDispatch();
}
Conclustion
RequestManager requestManager = DatabaseRequestManagrerInitializer.Initialize();
Request req = new Request();
req.MethodName = "DeliveryRouteUpdate";
req.EndPoint = "MyWebServiceHost";
req.OnlineProxyType = typeof(MyWebServiceProxy);
behavior.ProxyFactoryType = typeof(WebServiceProxyFactory);
int customerCode =1234;
string comment = "New value for cooment";
req. Callparametars=CallParameters.ToArray(customerCode,Comment);
requestManager.RequestQueue.Enqueue(req);
requestManager.DispatchRequest(req);
No comments:
Post a Comment