Self Hosting of DSPI Provider

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

Imagine you have a machine which should host some very simple RFID application, without of need to provide reliability, management and all those powerful staffs delivered with BizTalk Rfid. For example you decided to deploy BizTalk Rfid in the near future. For this reason it would be reasonable to build your application by using of already existing set of Bts-RFID API-s, because you want to be hardware independent. However you have to build a powerful host and flexible interface with ability to deal with any rfid reader and sensor. This requirement seems to be unsolvable in term of costs. To be honest, we are going to build a simple application (assumed above) with too many requirements.

Theoretically there is a way to solve this problem. The solution should be based on BizTalk Rfid API (because hardware independent and future oriented), but without of BizTalk Rfid (assumed above). This sounds almost funny, but it works. In this post I will show how I did it :)

The code below code which show self hosted BizTalk Rfid provider and device proxy, which is all you need in this scenario. To demonstrate how to do it, I used Daenet.FileWatcher provider, which I demonstrated with Andreas in Redmond and Barcelona last year.

  public static void StartSelfDspiHost()
 
{

            Daenet.Rfid.FileProvider.FileDeviceProvider p;
           
           
string provName = "Daenet.Rfid.FileProvider.FileDeviceProvider, Daenet.Rfid.FileProvider,
                                        Version=1.0.0.0, Culture=neutral,
                                        PublicKeyToken=612fc0aac28affb3"
;

           
string devName = "Daenet.Rfid.FileProvider.FilePhysicalDeviceProxy,
                                       Daenet.Rfid.FileProvider, 
                                       Version=1.0.0.0, Culture=neutral,
                                       PublicKeyToken=612fc0aac28affb3"
;

            Type devType = Type.GetType(devName);

            Type provType = Type.GetType(provName);

             // After I created the type instance of provider in this line I'm creating
             // the instance of the FileDeviceProvider provider,
             // which will host all devices of file watcher type.

             DeviceProvider provider =
             (DeviceProvider)provType.InvokeMember("_ctor"
             System.Reflection.BindingFlags.CreateInstance, 
             null, null, null); 

            // Now I'm creating the provider context class, which I do not really
            // need in this example.
            // This instance is just required while initializing the provider.

           
RfidProviderContext ctx = new RfidProviderContext(new Dictionary<string,object>()); 

            // Now I'm creating an empty property profile. In the productive environment, 
            // you will possible have to 
            // provide full set of properties, depending on provider you want to use.
            // The good thin is that most of providers I have seen almost do not have any properties.
            // Most hardware vendors decided to put all properties on device.
            // I'm not sure that this is the best solution for one DSPI,
            // but it simplifies self hosting.

           
PropertyProfile profile = new PropertyProfile();

             // And now, I'm starting the initialization of provider. 
            provider.Init(ctx, "my provider", profile);

           DeviceComplete[] deviceCompleteArray; 

            // This part of code loads oll device related properties. 
            // To do this I exported configured properties from one
            // some other machine running BizTalk-Rfid with installed
            // provider and device, which I use in this example.
            // In
this post I have described how to do it.
            
using (XmlReader reader = XmlReader.Create("c:\\temp\\dev01props.xml"))
           
{
                  
deviceCompleteArray =
                   (DeviceComplete[])RfidCommon.DeserializeFromXmlDataContract(
                   reader, typeof(DeviceComplete[])); 
           

            // Now, I have all I need to initialize device.
            // In my opinion, this part is most difficult,
            // because initialization of different device-proxies
            // could have different constructors,
            // and you have to be aware of.
           
// Another thing you have to take a care of, is providing
            // of the proper configuration.
            // This could be an issue, because
            // remember, we do not have BizTalk Rfid, which usually provide
            // powerful management mechanism.
           
PhysicalDeviceProxy deviceProxy =
            (PhysicalDeviceProxy)devType.InvokeMember("_ctor"
            System.Reflection.BindingFlags.CreateInstance, 
            
null, null, new object[] { "FileWatcherDev01", provider, 
            deviceCompleteArray[0].DeviceDefinition.DeviceInformation.ConnectionInformation});

            // After initialization of provider and device I'm ready  to send some command. 
            // In this case I'm going to read tags in Radio Field.
            // This may look strange for most developers, because they are familiar with other  
            // API-s like DeviceConnection. Such classes,
            // do nothing more than wrapping of native commands
            // (like GetTagsCommand) and dispatching them to the device proxy.
            //
Here you can find the full list of commands. 
            GetTagsCommand rfidCommand = new GetTagsCommand(null, TagDataSelector.All);

           
deviceProxy.SetupConnection(deviceCompleteArray[0].DeviceDefinition.AuthenticationInformation);

           deviceProxy.SendMessage(rfidCommand);      
        }

Here is the list of BizTalk Rfid assemblies which have to be referenced. These assemblies can be copied from machine which already have a BTS Rfid instance. After that reference the project containing the code above to all of these assemblies and all will run without of BizTalk Rfid at all.

image


[All content in this post is provided as-is with no warranty!]


Visit [
www.daenet.de]

 


Posted Mar 11 2008, 10:52 PM by Damir Dobric
Filed under:

Comments

Andreas Erben wrote re: Self Hosting of DSPI Provider
on 03-12-2008 2:33

The post refers to "costs". If the post means licensing cost, then there is not much saved since the rights to use the API requires at minimum a so-called "runtime license" which allows you to use BizTalk RFID in your own custom built software. You have to be an ISV though.

However it of course enables interesting scenarios.

developers.de is a .Net Community Blog powered by daenet GmbH.