In the 'How to create a fabric task' I described how you can annotate your existing .NET classes with fabric attributes to create fabric applications. So what I wanted to do here is walk you through how you could create a .NET client application to call your fabric applications.
Appistry enables calling fabric applications from a client .NET application via a thin API. What this API provides is a mechanism by which the client can identify the fabric to connect to, and which application you want to execute in a synchronous or asynchronous way.
There are basically three parts to every fabric client application. The first part instantiates the Fabric object with the fabric's address. The second part of the application creates a fabric request and loads any data that the fabric application will need. And the last part of the application retrieves the results.
The calls to create the Fabric and FabricRequest objects are fairly straight forward. Within the FabricRequest call I am passing in the name of the fabric application 'Hello_App' along with the specific application process flow 'CS_Process' that I want to call.
Fabric fabric = new Fabric("239.255.0.1", 31000, Encryption.NONE);FabricRequest request = new FabricRequest("Hello_App","CS_Process");The loading of the data and retrieving of the results via the FabricRequest object probably need some additional explanation.
request["MyProperty"] = 1;
request["in_arg"] = "World";
The FabricRequest object is sent with every request that sent to a fabric. Within this object you can load any of the properties or arguments that your .NET assembly will need to execute. These name value pairs need to exactly match up with the names used with in your classes properties and arguments. Since the property in my example Class1 was 'MyProperty', I need to use the exact same name in my FabricRequest object. The same goes for the Hello method argument of 'in_arg'. It's important to note that the value associated to each of these name values can be any native or custom user defined data types, including user defined serializable objects.
The Execute method on the Fabric object invokes a synchronous request to the fabric. (verses the Submit method which is asynchronous)
fabric.Execute(request); // Synchronous invocation
Once the Execute has completed, the results can be gathered from the same FabricRequest object that was used by your fabric application. You just need to reference the FabricRequest entry for the return data you are interested in, which here is 'Hello_Return'.
Console.WriteLine(String.Format("{0}", request["Hello_Return"]));
The only other thing I would point out here, is that the Execute and Submit methods both throw exceptions should there be a problem. Typical exceptions include things like -
- Fabric not found, if your fabric address is incorrect.
- Process does not exist, if your process flow is not found.
- Property type mismatch, if your request datatypes don't match your classes datatypes.
- Property Key Missing, if you don't have a required name value in your request object.
Below is the complete listing.
using System; using System.Collections.Generic; using System.Text; using Appistry.FabricAPI;namespace Fabric_Client_Sync1 { class Fabric_Client_Sync1 { static void Main(string[] args) { Fabric fabric = new Fabric("239.255.0.78", 31000, Encryption.NONE); FabricRequest request = new FabricRequest("Hello_App", "CS_Process"); try { //Put the request[""] values being sent to your task/process flow here request["MyPropert"] = 100; request["in_arg"] = "Hello World"; fabric.Execute(request); // Synchronous invocation //Retrieve your results here Console.WriteLine(String.Format("{0}", request["Hello_Return"])); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { request.Dispose(); } Console.WriteLine("All done, press any key to continue.."); Console.ReadKey(); } } }








Post new comment