tutorial: order fulfillmentdownload.microsoft.com/download/c/2/0/c20a979a-f… · web viewthis...

121
Contents Tutorial: Order Fulfillment...........................................7 Prerequisites........................................................7 In This Section......................................................7 Lesson 1: Create an RFID Process......................................8 In This Section......................................................8 Step 1: Create an RFID Process by Using RFID Manager..................9 Prerequisites........................................................9 Overview of This Step................................................9 Procedures...........................................................9 Comments............................................................10 Next Steps..........................................................10 Step 2: Test the RFID Process by Using RfidClientConsole.............11 Prerequisites.......................................................11 Overview of This Step...............................................11 Procedures..........................................................12 Comments............................................................15 Next Steps..........................................................15 Lesson 2: Create a Custom Event Handler and Add It to the Process....15 In This Section.....................................................15 Step 1: Create a Custom Event Handler................................16 Prerequisites.......................................................16 Overview of This Step...............................................16 Procedures..........................................................16 Comments............................................................22 Next Steps..........................................................23 Step 2: Modify the Process to Use the Custom Event Handler...........23 Prerequisites.......................................................23 Overview of This Step...............................................23 Procedures..........................................................24 Comments............................................................25 Next Steps..........................................................25 Step 3: Test the Process.............................................26 Prerequisites.......................................................26

Upload: others

Post on 15-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

ContentsTutorial: Order Fulfillment...............................................................................................................7

Prerequisites............................................................................................................................... 7In This Section............................................................................................................................. 7

Lesson 1: Create an RFID Process................................................................................................8In This Section............................................................................................................................. 8

Step 1: Create an RFID Process by Using RFID Manager.............................................................9Prerequisites............................................................................................................................... 9Overview of This Step................................................................................................................. 9Procedures.................................................................................................................................. 9Comments................................................................................................................................. 10Next Steps................................................................................................................................. 10

Step 2: Test the RFID Process by Using RfidClientConsole.........................................................11Prerequisites.............................................................................................................................. 11Overview of This Step................................................................................................................11Procedures................................................................................................................................ 12Comments................................................................................................................................. 15Next Steps................................................................................................................................. 15

Lesson 2: Create a Custom Event Handler and Add It to the Process..........................................15In This Section........................................................................................................................... 15

Step 1: Create a Custom Event Handler.......................................................................................16Prerequisites............................................................................................................................. 16Overview of This Step...............................................................................................................16Procedures................................................................................................................................ 16Comments................................................................................................................................. 22Next Steps................................................................................................................................. 23

Step 2: Modify the Process to Use the Custom Event Handler.....................................................23Prerequisites............................................................................................................................. 23Overview of This Step...............................................................................................................23Procedures................................................................................................................................ 24Comments................................................................................................................................. 25Next Steps................................................................................................................................. 25

Step 3: Test the Process...............................................................................................................26Prerequisites............................................................................................................................. 26Overview of This Step...............................................................................................................26

Page 2: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Procedures................................................................................................................................ 26Comments................................................................................................................................. 28Next Steps................................................................................................................................. 28

Lesson 3: Add the RuleEnginePolicyExecutor Event Handler to the Process...............................28In This Section........................................................................................................................... 29

Step 1: Create a Sample Database..............................................................................................29Prerequisites............................................................................................................................. 29Overview of This Step...............................................................................................................29Procedures................................................................................................................................ 30Next Steps................................................................................................................................. 30

Step 2: Create a Business Rule Engine (BRE) Policy...................................................................31Prerequisites............................................................................................................................. 32Overview of This Step...............................................................................................................32Procedures................................................................................................................................ 32Comments................................................................................................................................. 34Next Steps................................................................................................................................. 34

Step 3: Configure the RFID Process to Use the BRE Policy.........................................................35Prerequisites............................................................................................................................. 35Overview of This Step...............................................................................................................35Procedures................................................................................................................................ 36Comments................................................................................................................................. 38Next Steps................................................................................................................................. 38

Step 4: Test the Process...............................................................................................................38Prerequisites............................................................................................................................. 38Overview of This Step...............................................................................................................38Procedures................................................................................................................................ 39Comments................................................................................................................................. 41Next Steps................................................................................................................................. 42

Lesson 4: Create and Use a Device Provider...............................................................................42In This Lesson........................................................................................................................... 42

Step 1: Create a Skeleton Provider by Using the Provider Template............................................42Prerequisites............................................................................................................................. 43Overview of This Step...............................................................................................................43Procedures................................................................................................................................ 43Next Steps................................................................................................................................. 44

Step 2: Start the Provider..............................................................................................................44Prerequisites............................................................................................................................. 44Overview of This Step...............................................................................................................44

Page 3: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Procedures................................................................................................................................ 45Next Steps................................................................................................................................. 46

Step 3: Add an RFID Device and View Its Properties...................................................................46Prerequisites............................................................................................................................. 47Overview of This Step...............................................................................................................47Procedures................................................................................................................................ 47Next Steps................................................................................................................................. 51

Step 4: Test the Process...............................................................................................................51Prerequisites............................................................................................................................. 51Overview of This Step...............................................................................................................51Procedures................................................................................................................................ 52Next Steps................................................................................................................................. 55

Lesson 5: Use the RFID Management API...................................................................................55In This Section........................................................................................................................... 55

Step 1: Remove a Process, a Device, and a Device Provider from BizTalk RFID........................56Prerequisites............................................................................................................................. 56Overview of This Step...............................................................................................................56Procedures................................................................................................................................ 57Next Steps................................................................................................................................. 62

Step 2: Add a Process, a Device, and a Device Provider to BizTalk RFID....................................62Prerequisites............................................................................................................................. 62Overview of This Step...............................................................................................................63Procedures................................................................................................................................ 63Next Steps................................................................................................................................. 68

Step 3: Test the Process...............................................................................................................68Prerequisites............................................................................................................................. 68Overview of This Step...............................................................................................................68Procedures................................................................................................................................ 69Next Steps................................................................................................................................. 70

Lesson 6: Use the RfidClientConsole Utility..................................................................................70In This Section........................................................................................................................... 71

Step 1: Remove a Process, a Device, and a Device Provider from BizTalk RFID........................71Prerequisites............................................................................................................................. 71Overview of This Step...............................................................................................................71Procedures................................................................................................................................ 72Next Steps................................................................................................................................. 74

Step 2: Add a Process, a Device, and a Device Provider to BizTalk RFID....................................74

Page 4: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Prerequisites............................................................................................................................. 74Overview of This Step...............................................................................................................74Procedures................................................................................................................................ 75Next Steps................................................................................................................................. 77

Step 3: Test the Process...............................................................................................................77Prerequisites............................................................................................................................. 77Overview of This Step...............................................................................................................77Procedures................................................................................................................................ 78Next Steps................................................................................................................................. 79

Lesson 7: Create and Use a Device Simulator.............................................................................79In This Section........................................................................................................................... 79

Step 1: Create a Device Translator...............................................................................................80Prerequisites............................................................................................................................. 80Overview of This Step...............................................................................................................80Procedures................................................................................................................................ 81Comments................................................................................................................................. 84Next Steps................................................................................................................................. 85

Step 2: Modify the Provider to Use the Simulator.........................................................................85Prerequisites............................................................................................................................. 85Overview of This Step...............................................................................................................86Procedures................................................................................................................................ 86Comments................................................................................................................................. 90Next Steps................................................................................................................................. 90

Step 3: Run the Device Simulator.................................................................................................90Prerequisites............................................................................................................................. 90Overview of This Step...............................................................................................................90Procedures................................................................................................................................ 91Next Steps................................................................................................................................. 92

Step 4: Test the Process...............................................................................................................93Prerequisites............................................................................................................................. 93Overview of This Step...............................................................................................................93Procedures................................................................................................................................ 93Next Steps................................................................................................................................. 95

Lesson 8: Print a Tag....................................................................................................................95In This Section........................................................................................................................... 95

Step 1: Modify the Translator to Support Printing a Tag................................................................96Prerequisites............................................................................................................................. 97Overview of This Step...............................................................................................................98

Page 5: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Procedures................................................................................................................................ 98Comments................................................................................................................................. 99Next Steps............................................................................................................................... 100

Step 2: Modify the Provider to Support Printing a Tag................................................................100Prerequisites........................................................................................................................... 101Overview of This Step.............................................................................................................101Procedures.............................................................................................................................. 101Comments............................................................................................................................... 102Next Steps............................................................................................................................... 102

Step 3: Test the Process.............................................................................................................102Prerequisites........................................................................................................................... 102Overview of This Step.............................................................................................................103Procedures.............................................................................................................................. 104Next Steps............................................................................................................................... 108

Copyright.................................................................................................................................... 108

Page 6: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Tutorial: Order FulfillmentThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order Fulfillment Scenario [RFID11] in an incremental fashion (lesson-by-lesson). At the end of each lesson, you can test the solution to verify that it works correctly. You will develop a solution for the shipping station and then develop a solution for the commissioning station.

PrerequisitesBefore you perform the steps in this tutorial, review the Understanding BizTalk RFID [RFID11] section of this documentation for a high-level overview of all the features of BizTalk RFID.

In This Section

Lesson Description

Lesson 1: Create an RFID Process In this lesson, you create an RFID process named TutorialProcess by using RFID Manager. The process contains a logical device and a SqlServerSink event handler.

Lesson 2: Create a Custom Event Handler and Add It to the Process

In this lesson, you create a custom event handler named MyEventHandler that generates an advance shipment notice (ASN) message, and add the event handler to the RFID process.

Lesson 3: Add the RuleEnginePolicyExecutor Event Handler to the Process

In this lesson, you create a Business Rule Engine (BRE) policy to match the purchase order numbers, and add a RuleEnginePolicyExecutor component to the process to invoke the BRE policy.

Lesson 4: Create and Use a Device Provider In this lesson, you create a device provider named TutorialProvider, add a device named TutorialDevice, and bind the logical device in the process to the device.

Lesson 5: Use the RFID Management API In this lesson, you create two .NET console applications by using the RFID Management API. The first application removes the TutorialProcess, the TutorialDevice, and the

7

Page 7: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Lesson Description

TutorialProvider from BizTalk RFID. The second application adds the TutorialProvider, the TutorialDevice, and the TutorialProcess to BizTalk RFID.

Lesson 6: Use the RfidClientConsole Utility In this lesson, you create two command files that use the RfidClientConsole utility. The first file removes the TutorialProcess, the TutorialDevice, and the TutorialProvider from BizTalk RFID. The second file adds the TutorialProvider, the TutorialDevice, and the TutorialProcess to BizTalk RFID.

Lesson 7: Create and Use a Device Simulator In this lesson, you create a device simulator for the TutorialDevice, modify the TutorialProvider to use the simulator, run the simulator, and test the process by having the device simulator generate tag-read event messages.

Lesson 8: Print a Tag In this lesson, you modify the TutorialProvider and the device simulator to support printing a tag, and test the printing of a tag from a .NET console application.

Lesson 1: Create an RFID ProcessIn this lesson you use RFID Manager to create an RFID process named TutorialProcess, which contains a logical device and a SqlServerSink event handler. When the process receives a tag-read event, the SqlServerSink event handler stores the tag information in the RFIDsink database.

In This Section Step 1: Create an RFID Process by Using RFID Manager

Step 2: Test the RFID Process by Using RfidClientConsole

8

Page 8: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Step 1: Create an RFID Process by Using RFID ManagerIn this step, you use RFID Manager to perform the following tasks:

Create an RFID process named TutorialProcess.

Add a logical device, shippingreader, to the process.

Add a SqlServerSink event handler to the process.

Start the TutorialProcess process.

Prerequisites BizTalk RFID must be installed and running.

The Microsoft.Rfid.OobComponents event handler assembly must be registered with BizTalk RFID. See Registering Microsoft.Rfid.OobComponents Assembly with BizTalk RFID for more details.

Overview of This StepYou perform the following procedure in this step.

Procedure Description

To create the TutorialProcess process by using RFID Manager

This procedure has instructions to create a BizTalk RFID process named TutorialProcess with a logical device and a SqlServerSink event handler.

ProceduresTo create the TutorialProcess process by using RFID Manager

1. Click Start, point to Programs, point to Microsoft BizTalk RFID, and then click RFID Manager.

2. In RFID Manager, expand RFID Services Administration, and then expand your machine name.

3. Right-click Processes, and then click New Process.

4. For Process Name, type TutorialProcess, and then click OK.

The Bind Wizard opens.

9

Page 9: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

5. On the Introduction page, click Next. 6. On the Logical Devices page, click New.

7. In the Logical Device Name window, for Name, type shippingreader, and then click OK.

8. On the Logical Devices page, click Next. 9. On the Components page, click New Component. 10. From the List of available components, select SqlServerSink, and then click Add.

Note If you do not see SqlServerSink in the list, you may not have registered the Microsoft.Rfid.OobComponents assembly with BizTalk RFID. See Registering Microsoft.Rfid.OobComponents Assembly with BizTalk RFID for more details.

11. For Instance Name, type MySqlSink, and then click OK.

12. In the Add Component dialog box, click Close.

13. On the Components page, click Next. 14. Select Start the Process when I click Finish.

15. Click Finish.

CommentsThe following comments apply to this step:

A process is a high-level object that combines various entities such as logical devices and event handlers.

The Binding Wizard enables you to create two types of bindings: device bindings and component bindings. Device bindings enable a process to declare a set of devices from which to receive events. Device bindings are declared through logical devices. Component bindings represent the configuration of the parameters for components in a process. A component is a module that is located in the process pipeline. Components receive and process events such as tag-reads.

By default the value of the Tag Processing Mode for a process is set to Transactional. For more details on tag processing modes, see Transaction Model [RFID11].

The Microsoft.Rfid.OobComponents assembly contains two event handlers, SqlServerSink and RuleEnginePolicyExecutor.

Next StepsNow that you have completed Step 1 in this lesson, perform Step 2: Test the RFID Process by Using RfidClientConsole, which gives you step-by-step instructions to test TutorialProcess by using RFID Manager.

10

Page 10: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Step 2: Test the RFID Process by Using RfidClientConsoleIn this step, you use the RfidClientConsole utility to test the TutorialProcess process you created in the previous step.

Prerequisites You must complete Step 1: Create an RFID Process by Using RFID Manager before

performing this step.

The procedures in this step assume that you are using a folder named rfidtutorial that contains a subfolder named testfiles on your C drive. If you use any other drive or folder names, use those names in the appropriate places when performing the procedures.

Overview of This StepYou perform the following procedures in this step.

Procedure Description

To create a sample tag-read event XML file This procedure has instructions to create an XML file that contains information about a sample tag-read event. The structure of the XML content in the file is the structure that the RfidClientConsole utility expects for a tag-read event in XML format.

To test TutorialProcess by using the RfidClientConsole utility

This procedure has instructions to test the RFID process, TutorialProcess, by using the RfidClientConsole utility and the sample tag-read event XML file.

To verify that the process received the event This procedure has instructions to verify that TutorialProcess received the event posted by the RfidClientConsole utility.

To verify that the SqlServerSink event handler executed

This procedure has instructions to verify that the SqlServerSink event handler in the event handler pipeline of TutorialProcess executed successfully upon receiving the tag-read event.

11

Page 11: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

ProceduresTo create a sample tag-read event XML file

1. Click Start, and then click Run.

2. Type Notepad, and then click OK.

3. Copy the following XML text into Notepad:

<RfidEventBase xmlns:i="http://www.w3.org/2001/XMLSchema-instance"

i:type="TagReadEvent"

xmlns="http://schemas.datacontract.org/2004/07/Microsoft.SensorServices.Rfid

">

<m_lockObject />

<vendorSpecificData

xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.IO.SensorServices

.Rfid.Client">

<d2p1:dictionary

xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">

<d3p1:KeyValueOfstringanyType>

<d3p1:Key>ItemID</d3p1:Key>

<d3p1:Value

xmlns:d5p1="http://www.w3.org/2001/XMLSchema"

i:type="d5p1:string">1234</d3p1:Value>

</d3p1:KeyValueOfstringanyType>

<d3p1:KeyValueOfstringanyType>

<d3p1:Key>PONumber</d3p1:Key>

<d3p1:Value

xmlns:d5p1="http://www.w3.org/2001/XMLSchema"

i:type="d5p1:string">PO123456</d3p1:Value>

</d3p1:KeyValueOfstringanyType>

</d2p1:dictionary>

</vendorSpecificData>

12

Page 12: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

<m_deviceName>MyDevice</m_deviceName>

<m_sourceName>Antenna 1</m_sourceName>

<m_time>2007-06-22T11:37:10.5218784+05:30</m_time>

<data>QgBpAHoAVABhAGwAawAgAFIARgBJAEQA</data>

<dataSelector

xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.IO.SensorServices

.Rfid.Client">

<d2p1:dataSelector>123</d2p1:dataSelector>

</dataSelector>

<id>AQEBAQ==</id>

<numberingSystemIdentifier i:nil="true" />

<type

xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.IO.SensorServices

.Rfid.Client">

<d2p1:description>EPC Class 0

tag</d2p1:description>

<d2p1:enumValue>1</d2p1:enumValue>

</type>

</RfidEventBase>

4. In Notepad, click File, and then click Save.

5. For File name, type TREvent1.xml. 6. Verify that the folder, c:\rfidtutorial\testfiles, exists on your hard disk. If the folder does not

exist, create it before performing the next step.

7. Browse to the c:\rfidtutorial\testfiles folder, and then click Save to save the TREvent1.xml file in that folder.

To test TutorialProcess by using the RfidClientConsole utility

1. Click Start, and then click Run.

2. Type cmd, and then click OK to open a command prompt window.

Note On Windows Vista® computers, if the User Access Control feature is turned on, click Start, point to Programs, point to Accessories, right-click Command Prompt, and then click Run As Administrator to run the command prompt with administrator privileges.

3. Switch to the c:\rfidtutorial\testfiles folder, and then execute the following command from the command prompt:

13

Page 13: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

rfidclientconsole.exe AddEventToProcessPipeline TutorialProcess TREvent1.xml shippingreader

Note The AddEventToProcessPipeline command posts a tag-read event based on the XML content in the input file to a process.

Note You can view the help for the RfidClientConsole utility by executing the rfidclientconsole /h command. To view more details about using a specific command, execute rfidclientconsole /h <command name>.

To verify that the process received the event

1. In RFID Manager, right-click TutorialProcess, and then click View Tags.

2. In the View Tags - TutorialProcess dialog box, click Refresh to refresh the list, and verify that the tag you posted appears in the list.

3. Click Close to close the View Tags dialog box.

To verify that the SqlServerSink event handler executed

1. Click Start, point to Programs, point to Microsoft SQL Server, and then click SQL Server Management Studio.

2. Enter the appropriate credentials, and then click Connect if you see the Connect to Server dialog box.

3. In the Object Explorer window, expand Databases, and confirm that the RFIDsink database exists.

4. Click RFIDsink, and then click New Query on the toolbar.

Note The SqlServerSink event handler creates the RFIDsink database when the component is invoked for the first time and if the database does not exist on the computer.

5. Type and execute the following query in the query editor:

select * from tagevents where processname='TutorialProcess' order by

sinktime desc

Note The sink time is the date-time stamp at which the process receives the event. The tag time is the date-time stamp in the input XML file.

6. Confirm that the tag you posted to the process appears in the result list.

Note

14

Page 14: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

The value of the tag ID in the XML file is "AQEBAQ==", which is a base64 string representation of the hex2 value "0x01010101". Therefore, look for a tag event with tag ID 0x01010101 in the result list.

CommentsThe following comments apply to this step:

The AddEventToProcessPipeline method or the Send Tags dialog box posts a tag-read event directly to the process pipeline. The event is a simulated tag-read event, and there is no physical device or device simulator involved in this scenario.

In a real-world scenario, a tag-reader device sends a message to the device provider when an item with a tag comes within its range, and the provider raises an event for the event processing engine to process. You can also write a device simulator that simulates a real device, and have the simulator send a message to the provider, which in turn raises a tag-read event.

In the order fulfillment scenario, a reader at the shipping station raises a tag-read event for an RFID process when an item is going out the dock door to the distribution center.

Next StepsNow that you have completed this step, perform the steps in Lesson 2: Create a Custom Event Handler and Add It to the Process.

Lesson 2: Create a Custom Event Handler and Add It to the ProcessIn Lesson 1: Create an RFID Process, you created the TutorialProcess process with a logical device and a SqlServerSink event handler. In this lesson, you create a custom event handler that generates an advance shipment notice (ASN) message to be sent to the distribution center, and add the custom event handler to the event handler pipeline.

Note In the Order Fulfillment Scenario [RFID11], the ASN is generated at the shipping station when the item goes out at the dock door, and the ASN is sent to the distribution center.

In This Section Step 1: Create a Custom Event Handler

Step 2: Modify the Process to Use the Custom Event Handler

15

Page 15: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Step 3: Test the Process

Step 1: Create a Custom Event HandlerIn this step, you create a custom event handler that generates an advance shipping notice (ASN) message in XML format.

Prerequisites You must complete Lesson 1: Create an RFID Process before performing this step.

You must have Microsoft Visual Studio® installed on your computer.

Overview of This StepYou perform the following procedures in this step.

Procedure Description

To create an event handler class This procedure has instructions to create a custom event handler class that derives from the RfidEventHandlerBase class.

To implement the GetEventHandlerMetadata method

This procedure has instructions to implement the GetEventHandlerMetadata method to support parameters for the event handler.

To implement the Init method This procedure has instructions to implement the Init method to support initialization of the event handler.

To implement the ProcessTagReadEvent method

This procedure has instructions to implement the ProcessTagReadEvent method to support processing an event.

To build the event handler assembly This procedure has instructions to build the event handler assembly (myeventhandler.dll).

ProceduresTo create an event handler class

1. Click Start, point to Programs, point to Microsoft Visual Studio, and then click

16

Page 16: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Microsoft Visual Studio.

2. In Visual Studio, click File, point to New, and then click Project. 3. In Project Types, select Visual C#.

4. In Visual Studio Installed Templates, select Class Library.

5. For Location, type c:\rfidtutorial.6. For Name, type MyEventHandler.7. Clear the Create directory for solution option.

8. Click OK to close the New Project dialog box.

9. In the Solution Explorer window, right-click Class1.cs, and then click Rename.

10. Type MyEventHandler.cs, and then press ENTER.

11. Confirm that the name of the class is changed from Class1 to MyEventHandler in the editor.

12. In the Solution Explorer window, right-click References, and then click Add Reference.

13. Click the Browse tab.

14. Navigate to the bin subdirectory of the BizTalk RFID installation directory.

15. Select Microsoft.Rfid.Design.dll, and then click OK.

16. Repeat instructions 11 and 12 to add references to the Microsoft.Rfid.SpiSdk and Microsoft.Rfid.util assemblies.

Note You can also multiple-select the assemblies by pressing CTRL and the assembly names.

17. If the MyEventHandler.cs file is not open in the editor, double-click MyEventHandler.cs in the Solution Explorer window to open it.

18. Add the following statements at the beginning of the file after the existing using statements:

using Microsoft.SensorServices.Rfid;

using Microsoft.SensorServices.Rfid.Utilities;

19. Modify the MyEventHandler class to derive from the RfidEventHandlerBase class:

public class MyEventHandler : RfidEventHandlerBase

To implement the GetEventHandlerMetadata method

1. Add a public static method named GetEventHandlerMetadata to the MyEventHandler class as shown in the following code fragment:

public static RfidEventHandlerMetadata GetEventHandlerMetadata(bool

vendorextensionalso)

{

17

Page 17: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

}

Note A custom event handler class must implement a public static method named GetEventHandlerMetadata to support configuration of an event handler. The signature of the method must be the same as the one shown in the preceding code fragment. RFID Manager invokes this method to obtain metadata about the event handlers and populate the property grid.

2. Add the following code to the GetEventHandlerMetadata method to support two parameters—LogRequirement and ASNOutputFolder. When LogRequirement is set to true, the event handler logs information to the process log file. The event handler generates an advance shipment notice (ASN) to the ASNOutputFolder folder.

RfidEventHandlerMetadata metadata;

Dictionary<string, RfidEventHandlerParameterMetadata> parameters

= new Dictionary<string, RfidEventHandlerParameterMetadata>();

parameters.Add("LogRequirement", new

RfidEventHandlerParameterMetadata(typeof(bool), "Logging Required", true,

false));

parameters.Add("ASNOutputFolder", new

RfidEventHandlerParameterMetadata(typeof(string), "Advance Shipping Notice

Output Folder", null, true));

metadata = new RfidEventHandlerMetadata("MyEventHandler",

parameters);

return metadata;

Note The RfidEventHandlerMetadata object in the preceding code maps the name of the event handler to a parameter dictionary. The parameter dictionary in the preceding code contains two keys—LogRequirement and ASNOutputFolder. The values for these keys in the dictionary are parameter metadata describing the type of the parameter, default value for the parameter, and so on.

To implement the Init method

1. Right-click RfidEventHandlerBase in the editor, and then click Implement Abstract Class. You should see the Init method added to the MyEventHandler class.

public override void Init(Dictionary<string, object> parameters,

RfidProcessContext container)

{

throw new Exception("The method or operation is not implemented.");

18

Page 18: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

}

2. Remove the statement that throws an exception from the Init method.

public override void Init(Dictionary<string, object> parameters,

RfidProcessContext container)

{

}

Note You should use the Init method to initialize an event handler. In this scenario, you could use the Init method to extract the values for the LogRequirement and ASNOutputFolder parameters that are set at design time by using RFID Manager.

3. Add two private member variables to the class to hold the values of the LogRequirement and ASNOutputFolder parameters of the event handler as shown in the following code:

private bool logRequired;

private string ASNOutputFolder;

4. Add the following code to the Init method to initialize these member variables with the values of the parameters LogRequirement and ASNOutputFolder.

if (parameters == null)

return;

if (parameters.ContainsKey("LogRequirement"))

logRequired = (bool)parameters["LogRequirement"];

if (parameters.ContainsKey("ASNOutputFolder"))

ASNOutputFolder = (string)parameters["ASNOutputFolder"];

Note The first parameter that BizTalk RFID passes to the Init method is a dictionary of parameters to the event handler and their values.

5. Based on the value of the LogRequirement parameter, you may want to initialize a logger object that you can use to log information to the process log file. Add the following method and declare two variables as shown in the following code fragment to support logging:

private Level logLevel;

private static ILogger myLogger;

6. Add a method named InitializeLog as shown in the following code fragment:

internal void InitializeLog(RfidProcessContext container)

{

if (myLogger != null)

19

Page 19: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

return;

string loggerName = this.GetType().Name;

myLogger = RfidProcessContext.GetLogger(loggerName);

//inherit log level from the process

myLogger.CurrentLevel =

RfidProcessContext.GetLogger(container.ProcessName).CurrentLevel;

logLevel = myLogger.CurrentLevel;

myLogger.Info("starting logging for {0}", loggerName);

}

Note An event handler should use the logger object returned by the GetLogger method of the RfidProcessContext object to log any information. This causes all the information logged by any event handler in the same process to be in one log file.

Note An event handler should use the logging level configured by the user to determine the type of information to log to its log file. The preceding code uses the logging level of the process.

7. Add a statement to invoke the InitializeLog method from the Init method as shown in the following code fragment:

if (logRequired)

InitializeLog(container);

Note BizTalk RFID passes the RfidProcessContext object as a second parameter to the Init method. The Init method then passes the RfidProcessContext object to the InitializeLog method as a parameter.

To implement the ProcessTagReadEvent method

1. Add an event handler method to the class as shown in the following code fragment:

[RfidEventHandlerMethod]

public TagReadEvent ProcessTagReadEvent(TagReadEvent tagReadEvent)

{

}

Note An event handler method must be annotated with the RfidEventHandlerMethod attribute.

20

Page 20: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Note The ProcessTagReadEvent method in the preceding code takes a TagReadEvent as an input parameter, processes it, and returns a TagReadEvent as an output parameter for the next event handler in the event handler pipeline to process the event.

2. Add the following code to the ProcessTagReadEvent code to generate an advance shipment notice (ASN) message:

if (logRequired) myLogger.Log(String.Format("At the beginning of the

ProcessTagReadEvent method. Event is: {0}", tagReadEvent), logLevel);

try

{

//Generate ASN, and drop it to the output folder

XmlDocument doc = new XmlDocument();

string PONum =

(string)tagReadEvent.VendorSpecificData["PONumber"];

string ItemID =

(string)tagReadEvent.VendorSpecificData["ItemID"];

string ASNXml = "<ASN><PONumber>" + PONum +

"</PONumber><ItemID>" + ItemID + "</ItemID><ShippedDate>" +

DateTime.Now.ToString() + "</ShippedDate></ASN>";

doc.LoadXml(ASNXml);

doc.Save(ASNOutputFolder + "\\ASN_" +

System.Guid.NewGuid().ToString() + ".xml");

}

catch (Exception ex)

{

if (logRequired) myLogger.Log(String.Format("exception {0}",

ex), Level.Error);

}

if (logRequired) myLogger.Log(String.Format("At the end of the

ProcessTagReadEvent method. Event is: {0}", tagReadEvent), logLevel);

return tagReadEvent;

Note

21

Page 21: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

The preceding code uses the values of ItemID and PONumber in the vendor-specific data of the tag-read event posted to the process to generate an advance shipment notice (ASN) message.

3. Add the following statement at the beginning of the file after the existing using statements:

using System.Xml;

4. Add another event handler method that takes an array of RfidEventBase as a parameter, and add the code to the method as shown in the following code fragment:

[RfidEventHandlerMethod]

public TagReadEvent ProcessTagReadEvent(RfidEventBase[] tagReadEvents)

{

TagReadEvent tagReadEvent = (TagReadEvent) tagReadEvents[0];

return ProcessTagReadEvent(tagReadEvent);

}

Note   In the later steps, you will be using a RuleEnginePolicyExecutor event handler ahead of this component in the event handler pipeline. The output type of the RuleEnginePolicyExecutor must match the input type of at least one of the event handlers of this class. That is the reason why you are creating this method that takes an array of RfidEventBase objects as a parameter.

To build the event handler assembly

1. In the Solution Explorer window, right-click MyEventHandler, and then click Build.

2. Resolve any build errors by verifying the code in your event handler against the code in the instructions of this step.

Note In the next step, you will copy the myeventhandler.dll assembly to the processes\TutorialProcess\bin directory in your BizTalk RFID installation directory so that you can use the event handler in the TutorialProcess process.

CommentsThe following comments apply to this step:

The name of an event handler method can be any valid method name. This custom event handler uses the name HandleTagReadEvent to make its function obvious.

When you deploy an event handler, you can also initiate a custom installation action that is required for the event handler to function. For example, deploying a custom event handler might create a Microsoft SQL Server® database or a table within a database to store the data

22

Page 22: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

needed by the event handler. To deploy an event handler, you call the Deploy method. Likewise, to remove an event handler, you call the Undeploy method. For more information, see Event Handler Deployment [RFID11].

The Event Handler Template sample ships with a Visual Studio template that you can use to create an event handler. To develop an event handler component using the template, you need to create a new project using the template and implement the methods in the RfidEventHandlerBase class. For more information, see the readme document shipped with the Event Handler Template sample.

Next StepsNow that you have completed this step, perform Step 2: Modify the Process to Use the Custom Event Handler, which gives you step-by-step instructions for configuring the process to use the custom event handler you created in this step.

Step 2: Modify the Process to Use the Custom Event HandlerIn this step you register the custom event handler, MyEventHandler, with BizTalk RFID, and then configure the process to use MyEventHandler.

Prerequisites You must complete Step 1: Create a Custom Event Handler before performing this step.

You must create a directory named Output in the C:\RfidTutorial folder, and then create a folder named ASN in the Output folder.

Overview of This StepYou perform the following procedures in this step.

Procedure Description

To register the custom event handler with BizTalk RFID

This procedure has instructions to register the MyEventHandler assembly with BizTalk RFID.

To configure the RFID process to use the custom event handler

This procedure has instructions to configure TutorialProcess to use MyEventHandler, and to specify values for parameters of MyEventHandler.

23

Page 23: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

ProceduresTo register the custom event handler with BizTalk RFID

1. In RFID Manager, expand Processes, and then click TutorialProcess.

2. Right-click TutorialProcess, and then click Stop.

3. Right-click TutorialProcess, and then click Edit. The Browse tab in the right pane becomes active.

4. Right-click Component Bindings, and then click Add New Component. 5. In the Add Component dialog box, for Type of component to register, select the

Private option.

Note Components are of two types: public and private. Public components are registered once in BizTalk RFID, and instances can be created for use across any process. Public components are placed in the global assembly cache (GAC). Private components must be registered with BizTalk RFID every time a new process needs an instance of the component. Private components are placed in the processes\bin folder located in the BizTalk RFID installation folder.

6. Click Register. 7. In the Register Private Components dialog box, click Add.

8. Browse and select MyEventHandler.dll, and then click Open.

9. In the Register Private Component dialog box, click OK to close the dialog box.

10. Confirm that you see the MyEventHandler event handler in the List of available components. Do not close the Add Component dialog box yet.

To configure the RFID process to use the custom event handler

1. In the List of available components, select MyEventHandler, and then click Add.

2. In the Add Component Instance dialog box, for Instance name, type ASNEventHandler.

3. Confirm that the value of the LogRequirement parameter is set to True.

4. For the ASNOutputFolder parameter, type C:\rfidtutorial\output\asn.

Note You must make sure that the ASN folder exists. If the folder does not exist, create it before performing the next instruction.

5. Click OK to close the Add Component Instance dialog box.

6. Select ASNEventHandler, and then click Move Up to move the component up in the order ahead of the MySqlSink event handler in Instances of components in current process pipeline.

24

Page 24: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

7. Click Close to close the Add Component dialog box.

8. In the left pane, right-click TutorialProcess, and then click Validate to validate the changes you have made.

9. In the Validate Process message box, click OK.

10. Right-click TutorialProcess, and then click Start to start the process.

CommentsThe following comments apply to this step:

If you have the MySqlSink event handler ahead of ASNEventHandler in the event handler pipeline for the process, you get the following error message when validating the process. This is because the event handler method in the SqlServerSink event handler does not return anything (returns void). Hence, any event handlers placed after the SqlServerSink event handler become unreachable.

The process has a component that is not reachable. None of its event handler

methods will ever get called. There is no path for system type starting from a

logical device that reaches this event handler. One common reason for this

happening is that there are event handlers but no logical devices in the

process. The event handler is <EventHandlerDefinition

xmlns:i="http://www.w3.org/2001/XMLSchema-instance"

xmlns="http://schemas.datacontract.org/2004/07/Microsoft.SensorServices.Rfid.Des

ign">

<componentName>ASNEventHandler</componentName>

<eventHandlerInfo>

<assembly>TestEH</assembly>

<className>TestEH.MyEventHandler</className>

<description>MyEventHandler</description>

</eventHandlerInfo>

</EventHandlerDefinition>. Verify if this event handler is properly positioned

in the process pipeline

Next StepsNow that you have completed this step, perform Step 3: Test the Process, which gives you step-by-step instructions to test TutorialProcess.

25

Page 25: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Step 3: Test the ProcessIn this step, you use the RfidClientConsole utility to test the TutorialProcess process.

Prerequisites You must complete Step 2: Modify the Process to Use the Custom Event Handler before

performing this step.

Overview of This StepYou perform the following procedures in this step.

Procedure Description

To test TutorialProcess by using the RfidClientConsole utility

This procedure has instructions to test the RFID process, TutorialProcess, by using the RfidClientConsole utility and the sample tag-read event XML file.

To verify that the process received the event This procedure has instructions to verify that the TutorialProcess process received the event posted by the RfidClientConsole utility.

To verify that MyEventHandler executed This procedure has instructions to verify that the MyEventHandler component executed successfully.

To verify that the SqlServerSink event handler executed

This procedure has instructions to verify that the SqlServerSink event handler in the event handler pipeline of TutorialProcess executed successfully upon receiving the tag-read event.

ProceduresTo test TutorialProcess by using the RfidClientConsole utility

1. Click Start, and then click Run.

2. Type cmd, and then click OK to open a command prompt window.

Note On Windows Vista computers, if the User Access Control feature is turned on, click Start, point to Programs, point to Accessories, right-click Command

26

Page 26: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Prompt, and then click Run As Administrator to run the command prompt with administrator privileges.

3. Switch to the c:\rfidtutorial\testfiles folder, and then execute the following command from the command prompt:

rfidclientconsole.exe AddEventToProcessPipeline TutorialProcess TREvent1.xml shippingreader

Note The AddEventToProcessPipeline command posts a tag-read event based on the XML content in the input file to a process.

Note You can view the help for the RfidClientConsole utility by executing the rfidclientconsole /h command. To view more details about using a specific command, execute rfidclientconsole /h <command name>.

To verify that the process received the event

1. In RFID Manager, right-click TutorialProcess, and then click View Tags.

2. In the View Tags - TutorialProcess dialog box, click Refresh to refresh the list, and verify that the tag you posted appears in the list.

3. Click Close to close the View Tags dialog box.

To verify that MyEventHandler executed

In Windows® Explorer, navigate to the c:\rfidtutorial\output\asn folder, and verify that a file with prefix ASN_ is generated.

To verify that the SqlServerSink event handler executed

1. Click Start, point to Programs, point to Microsoft SQL Server, and then click SQL Server Management Studio.

2. Enter the appropriate credentials, and then click Connect if you see the Connect to Server dialog box.

3. In the Object Explorer window, expand Databases, and confirm that the RFIDsink database exists.

4. Click RFIDsink, and then click New Query on the toolbar.

Note The SqlServerSink event handler creates the RFIDsink database when the component is invoked for the first time and if the database does not exist on the computer.

5. Type and execute the following query in the query editor.

27

Page 27: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

select * from tagevents where processname='TutorialProcess' order by

sinktime desc

Note The sink time is the date-time stamp at which the process receives the event. The tag time is the date-time stamp in the input XML file.

6. Confirm that you see the tag you posted to the process displayed in the result list. It is the top-most item in the result list with the latest timestamp for sinktime.

Note The value of the tag ID in the XML file is "AQEBAQ==", which is a base64 string representation of the hex2 value "0x01010101". Therefore, look for a tag event with tag ID 0x01010101 in the result list.

CommentsThe following comments apply to this step:

The AddEventToProcessPipeline method or the Send Tags dialog box posts a tag-read event directly to the process pipeline. The event is a simulated tag-read event, and there is no physical device or device simulator involved in this scenario.

In a real-world scenario, a tag reader device sends a message to the device provider when an item with a tag comes within its range, and the provider raises an event for the event processing engine to process. You can also write a device simulator that simulates a real device, and have the simulator send a message to the provider, which in turn raises a tag-read event.

In the order fulfillment scenario, a reader at the shipping station raises a tag-read event for an RFID process when an item is going out the dock door to the distribution center, and the RFID process generates and sends an ASN message to distribution center.

Next StepsNow that you have completed this step, perform the steps in Lesson 3: Add the RuleEnginePolicyExecutor Event Handler to the Process.

Lesson 3: Add the RuleEnginePolicyExecutor Event Handler to the ProcessIn the previous lessons, you did the following:

28

Page 28: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Created the TutorialProcess process, added a logical device, and added a SqlServerSink event handler in Lesson 1: Create an RFID Process.

Added a custom event handler of type MyEventHandler in Lesson 2: Create a Custom Event Handler and Add It to the Process.

In this lesson, you add a RuleEnginePolicyExecutor event handler ahead of other event handlers to invoke a policy named VerifyPO. The VerifyPO policy verifies if the purchase order (PO) number in the tag-read event matches the PO number for the tag in the RFIDTutorial database. If the PO numbers are not the same, the policy terminates the event handler pipeline. In this case, the other event handlers—MyEventHandler and SqlServerSink—are not executed. If the PO numbers are the same, the MyEventHandler and SqlServerSink event handlers are executed.

In This Section Step 1: Create a Sample Database

Step 2: Create a Business Rule Engine (BRE) Policy

Step 3: Configure the RFID Process to Use the BRE Policy

Step 4: Test the Process

Step 1: Create a Sample DatabaseIn this step, you use SQL Server Management Studio to create a sample database that you will use in the next step to create a Business Rule Engine (BRE) policy.

Prerequisites You must complete Lesson 2: Create a Custom Event Handler and Add It to the Process

before performing this step.

SQL Server 2005 SP2 or 2008 must be installed on your computer.

Overview of This StepYou perform the following procedure in this step.

Procedure Description

To create the RFIDTutorial database This procedure has instructions to create the RFIDTutorial database, which will be used later by a BRE policy.

29

Page 29: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

ProceduresTo create the RFIDTutorial database

1. Click Start, point to Programs, point to Microsoft SQL Server, and then click SQL Server Management Studio.

2. Enter the appropriate credentials, and then click Connect in the Connect to Server dialog box.

3. In the Object Explorer window, expand your computer name.

4. Right-click Databases, and then click New Database.

5. For Database name, type RFIDTutorial, and then click OK.

6. On the menu bar, click File, point to New, and then click Query with Current Connection.

7. Copy the following SQL text into the query window, and then press F5 to execute the query:

USE [RFIDTutorial]

GO

CREATE TABLE [dbo].[TagPO](

[TagID] [nvarchar](50) NOT NULL,

[PONumber] [nvarchar](50) NOT NULL,

CONSTRAINT [PK_TagPO] PRIMARY KEY CLUSTERED

(

[TagID] ASC

)ON [PRIMARY]

) ON [PRIMARY]

INSERT INTO [TagPO] VALUES ('0x01010101','PO123456')

INSERT INTO [TagPO] VALUES ('0x01010102','PO654321')

Note The TagPO table maps a tag identifier to the purchase order number of the purchase order to which the tagged item belongs.

8. Confirm that the TagPO table is created with two records by using SQL Server Management Studio. Resolve any error messages before you proceed to the next step.

Next StepsNow that you have completed this step, perform Step 2: Create a Business Rule Engine (BRE) Policy, which gives you step-by-step instructions for creating a BRE policy.

30

Page 30: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Step 2: Create a Business Rule Engine (BRE) PolicyIn this step you create a BRE policy that logs an error message and terminates the event processing pipeline if the purchase order (PO) number in the tag information does not match the PO number in the database for a tag. The following code fragment is pseudocode for the BRE policy:

IF (IdInTagInfo IS EQUAL TO IdInDatabase) //If ID found in the DB

AND if (PONumberInTagInfo IS NOT EQUAL TO PONumberInDatabase)

THEN Log a message that says "PO numbers do not match"

AND Teminate the event handler pipeline

At the end of this step, you will have a policy that looks like the following code fragment:

IF RfidRuleEngineContext.get_TagIdAsHex == RFIDTutorial.TagPO.TagID

AND NOT (String.Equals(

Convert.ToString(RfidRuleEngineContext.GetVendorSpecificData("PONumber"),

RFIDTutorial.TagPO.PONumber)

THEN RfidRuleEngineContext.LogMessage("PO numbers do not match",

RfidRuleEngineContext.get_TagIdAsHex)

AND RfidRuleEngineContext.set_ShouldTerminatePipeline(True);

When the rule is invoked, the rule engine performs the following select statement based on the Tag ID value in the RfidRuleEngineContext object, and retrieves the record containing the PONumber value from the TagPO table.

select * from TagPO where TagID = RfidRuleEngineContext.get_TagIdAsHex

Then the rule engine performs the following actions (mainly to execute the second operand for the AND operation):

1. Invokes the GetVendorSpecificData method on the RfidRuleEngineContext class and receives the returned PONumber value as a System.Object.

2. Invokes the Convert.ToString method to convert the returned Object to a String.

3. Invokes the String.Equals method to compare the String obtained from the previous action with the PONumber value string from the result list.

4. Performs a NOT operation on the result of the String.Equals method.

If the PO numbers match, the result of the NOT operation is false, and the actions in the rule are not executed. If the PO numbers do not match, the result of the NOT operation is true, the actions in the rule are executed, and the event handler pipeline is terminated.

31

Page 31: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Prerequisites The BRE components of BizTalk Server 2009 must be installed on your computer.

You must complete Step 1: Create a Sample Database before performing this step.

Visual Studio must be installed on your computer.

Overview of This StepYou perform the following procedure in this step.

Procedure Description

To create a BRE policy This procedure has instructions to create the VerifyPO policy.

ProceduresTo create a BRE policy

1. Add the StaticSupport registry key, and set it to 1 as described in Invoking Static Members of a Class.

Note You will use the ToString static method of the System.Convert class in a business rule. If you set the StaticSupport registry key to 1, you do not need to assert an instance of the Convert class to execute the business rule. If the key does not exist on your computer or the key is set to 0, the rule engine requires you to assert an instance of the Convert class to execute the business rule.

2. Click Start, point to Programs, point to BizTalk Server 2009, and then click Business Rule Composer.

3. In the Policy Explorer window, right-click Policies, and then click Add New Policy.

4. For the policy name, type VerifyPO, and then press ENTER.

5. In VerifyPO, right-click Version 1.0 (not saved), and then click Add New Rule.

6. For the rule name, type Match, and then press ENTER.

7. In the IF pane, right-click Conditions, and then click Add logical AND.

8. Right-click AND, point to Predicates, and then click Equal. 9. In the Facts Explorer window, click the .NET Classes tab.

10. Right-click .NET Assemblies, and then click Browse.

11. Click Microsoft.Rfid.OobComponents, and then click OK.

32

Page 32: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

12. Expand RfidRuleEngineContext, and then drag get_TagIdAsHex to argument1 in the IF pane.

13. In the Facts Explorer window, click the Databases tab.

14. Right-click Servers, and then click Browse.

15. In the Connect to SQL Server dialog box, click OK after verifying the credentials.

16. Expand RFIDTutorial, and then expand TagPO.

17. In the IF pane, drag TagID to argument2. The BRE policy should look like the following pseudocode:

IF RfidRuleEngineContext.get_TagIdAsHex == RFIDTutorial.TagPO.TagID

18. Right-click AND, and then click Add logical NOT.

19. In the Facts Explorer window, click the .NET Classes tab.

20. Right-click .NET Assemblies, and then click Browse.

21. Click mscorlib, and then click OK.

22. In the Facts Explorer window, expand mscorlib, and then expand String.

23. In the IF pane, drag Equals(String a, String b) to NOT.

24. Expand Convert, and then drag the ToString(Object value) method to replace a in the IF pane.

25. On the .NET Classes tab, expand Microsoft.Rfid.OobComponents, and then expand RfidRuleEngineContext.

26. In the IF pane, drag GetVendorSpecificData(String key) to argument1.

27. In the IF pane, type PONumber for the string.

28. In the Facts Explorer window, click the Databases tab.

29. Expand RFIDTutorial, and then expand TagPO.

30. In the IF pane, drag PONumber to replace b. The BRE policy should look like the following pseudocode:

IF RfidRuleEngineContext.get_TagIdAsHex == RFIDTutorial.TagPO.TagID

AND NOT (String.Equals(

Convert.ToString(RfidRuleEngineContext.GetVendorSpecificData("PONumber"),

RFIDTutorial.TagPO.PONumber)

31. In the Facts Explorer window, click the .NET Classes tab, expand Microsoft.Rfid.OobComponents, and then expand RfidRuleEngineContext.

32. In the THEN pane, drag LogMessage(String message, Object argument) to Actions.

33. In the THEN pane, click message, type PO numbers do not match, and then press ENTER.

34. On the .NET Classes tab, drag get_TagIdAsHex to argument in the THEN pane.

33

Page 33: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

35. In the THEN pane, drag set_ShouldTerminatePipeline(Boolean value) to Actions.

36. In the THEN pane, click value, select True from the drop-down list, and then press ENTER. The BRE policy should look like the following pseudocode:

IF RfidRuleEngineContext.get_TagIdAsHex == RFIDTutorial.TagPO.TagID

AND NOT (String.Equals(

Convert.ToString(RfidRuleEngineContext.GetVendorSpecificData("PONumber"),

RFIDTutorial.TagPO.PONumber)

THEN RfidRuleEngineContext.LogMessage("PO numbers do not match",

RfidRuleEngineContext.get_TagIdAsHex)

AND RfidRuleEngineContext.set_ShouldTerminatePipeline(True);

37. In the Policy Explorer window, in VerifyPO, right-click Version 1.0 (unsaved), and then click Save.

38. Right-click Version 1.0, and then click Publish.

39. Right-click Version 1.0, and then click Deploy.

Comments The scenario that the VerifyPO policy implements is called the Filtering scenario because the

policy filters tag events based on whether the PO numbers match. If the PO numbers do not match, the event hander pipeline is terminated. Therefore, any event handler in the pipeline that follows the RuleEnginePolicyExecutor event handler does not execute.

You can also use a BRE policy to augment tag information with additional information before forwarding the event to the next event handler in the event handler pipeline. For more information about how you can use BRE policies in filtering and augmenting scenarios, see Walkthroughs for Creating and Using Policies in RFID Processes.

Next StepsNow that you have completed this step, perform Step 3: Configure the RFID Process to Use the BRE Policy, which gives you step-by-step instructions to configure the TutorialProcess process to use the VerifyPO policy.

34

Page 34: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Step 3: Configure the RFID Process to Use the BRE PolicyIn this step you configure the TutorialProcess process to use the VerifyPO policy you created in the preceding step.

Prerequisites You must complete Step 2: Create a Business Rule Engine (BRE) Policy before performing

this step.

The Microsoft.Rfid.OobComponents event handler assembly must be registered with BizTalk RFID. See Registering Microsoft.Rfid.OobComponents Assembly with BizTalk RFID for more details.

Overview of This StepYou perform the following procedures in this step.

Procedure Description

To give the worker process account access to the RFIDTutorial database

This procedure has instructions to give the identity under which the event handler is running access to the RFIDTutorial database.

Important The user account under which the RFID process runs needs to have access permission to any database the BRE policy refers to. On Windows XP and Windows Vista computers, the RFID process runs in the RfidServices.exe process. The identity for this process is RfidSvcAcc by default. On Windows Server® 2003 computers, the RFID process runs in a worker process (w3wp.exe) hosted in IIS. The identity for worker processes and RfidServices.exe is RfidWorkerProcessAcc by default.

35

Page 35: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Procedure Description

The identity can be specified during the configuration of BizTalk RFID.

To configure the RFID process to use the VerifyPO policy

This procedure has instructions to configure TutorialProcess to use the RuleEnginePolicyExecutor event handler to execute the VerifyPO policy.

ProceduresTo give the worker process account access to the RFIDTutorial database

1. In SQL Server Enterprise Manager, expand RFIDTutorial, and then expand Security.

2. Right-click Users, and then click New User. 3. For User name, type RFID Service Account. 4. For Login name, type <your computer name>\RfidSvcAcc (for Windows XP and

Windows Vista) or <your computer name>\RfidWorkerProcessAcc (for Windows Server 2003).

5. For Schemas owned by this user, select db_owner.6. For Database role membership, select db_owner. 7. Click OK to close the Database User - New dialog box.

To configure the RFID process to use the BRE policy

1. In RFID Manager, right-click TutorialProcess, and then click Stop.

Note If the Stop menu item is disabled, the process may not have been running. Therefore, you can skip this step.

2. Right-click TutorialProcess, and then click Edit. 3. In the right pane, on the Browse tab, right-click Component Bindings, and then click

Add New Component. 4. In the List of available components, click RuleEnginePolicyExecutor, and then click

Add.

5. For Instance name, type MyBREInst.6. Click Configure next to Rules Configuration, and then click the ellipsis (…) button.

7. For Policy Name, select VerifyPO.

8. Click Database Facts to switch to the Database Facts view.

36

Page 36: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

9. Type the following values in the Database Facts view:

Property Value

Connection String Data Source=(local);Initial Catalog="RFIDTutorial";Integrated Security=SSPI

Table Name TagPO

Dataset Name RFIDTutorial

10. Click Add.

11. Click OK to close the Properties dialog box.

12. Click OK to close the Add Component Instance dialog box.

13. In Instances of components in the current process pipeline, click MyBREInst, and then click Move Up twice so that MyBREInst is the first component in the event processing pipeline.

Note The order in which you add the components is important, because the event handlers process the events in the order that you added the components. In this scenario, the TutorialProcess generates an advance shipment notice (ASN) message, and stores the tag information in the RFIDsink database only if the purchase order (PO) numbers in the tag-read event information and the RFIDTutorial database match. If the PO numbers do not match, the process terminates the event handler pipeline, and the MyEventHandler and SqlServerSink event handlers are not executed.

14. Click Close to close the Add Component dialog box.

15. In the left pane, right-click TutorialProcess, and then click Validate.

16. In the Validate Process message box, click OK.

17. In RFID Manager, in the left pane, right-click TutorialProcess, and then click Start.

Note If the RuleEnginePolicyExecutor component throws an exception because the component could not connect to the RFIDTutorial database, you probably forgot to perform the instructions in the "To give the service account access to the RFIDTutorial database" procedure.

37

Page 37: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Comments The RuleEnginePolicyExecutor component contains two overloaded event handler

methods named PostEventToRuleEngine and PostEventsToRuleEngine. Both the methods return an array of RfidEventBase objects. The process has event handlers of types: RuleEnginePolicyExecutor, MyEventHandler, and SqlServerSink. If the return type of the RuleEnginePolicyExecutor event handler does not match the input type of any of the event handlers in the custom event handler, the validation of the process fails and you cannot start the process. That is why you had to create an event handler method that takes an array of RfidEventBase objects as an input parameter in the custom event handler.

Next StepsNow that you have completed this step, perform Step 4: Test the Process, which gives you step-by-step instructions to test the process after adding the RuleEnginePolicyExecutor component.

Step 4: Test the ProcessIn this step, you use the RfidClientConsole utility to test the TutorialProcess process. You post two tag-read events to the process with the first tag-read having the correct PO number and the second tag-read having the incorrect PO number. The VerifyPO BRE policy does not execute any actions for the first tag-read event because the PO number is correct, but the policy executes the following actions for the second tag-read event because the PO number is incorrect:

Logs a message similar to the following message in the process log:

13| Info|070207 11:54:08|PO numbers do not match|[BREPolicyExecutor]

Terminates the event handler pipeline so that the MyEventHandler and SqlServerSink event handlers are not executed.

Prerequisites You must complete Step 3: Configure the RFID Process to Use the BRE Policy before

performing this step.

Overview of This StepYou perform the following procedures in this step.

38

Page 38: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Procedure Description

To test TutorialProcess by using the RfidClientConsole utility

This procedure has instructions to test the RFID process, TutorialProcess, by using the RfidClientConsole utility and the sample tag-read event XML file.

To verify that the process received the event This procedure has instructions to verify that the TutorialProcess process received the event posted by the RfidClientConsole utility.

To verify that the VerifyPO policy executed This procedure has instructions to verify that the Business Rule Engine (BRE) policy executed.

To verify that MyEventHandler executed This procedure has instructions to verify that the MyEventHandler component executed successfully.

To verify that the SqlServerSink event handler executed

This procedure has instructions to verify that the SqlServerSink event handler in the event handler pipeline of TutorialProcess executed successfully upon receiving the tag-read event.

ProceduresTo test TutorialProcess by using the RfidClientConsole utility

1. Click Start, and then click Run.

2. Type cmd, and then click OK to open a command prompt window.

Note On Windows Vista computers, if the User Access Control feature is turned on, click Start, point to Programs, point to Accessories, right-click Command Prompt, and then click Run As Administrator to run the command prompt with administrator privileges.

3. Switch to the c:\rfidtutorial\testfiles folder, and then execute the following command from the command prompt:

Copy TREvent1.xml TREvent2.xml4. Open TREvent2.xml in Notepad, and change the value of the PONumber element to

PO654321.

5. Close Notepad.

6. In the command prompt window, execute the following command:

39

Page 39: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

rfidclientconsole.exe AddEventToProcessPipeline TutorialProcess TREvent1.xml shippingreader

Note The value of the tag ID in the TREvent1.xml file is "AQEBAQ==", which is a base64 string representation of the hex2 value "01010101", and the value of the PONumber field is PO123456.

7. In the command prompt window, execute the following command:

rfidclientconsole.exe AddEventToProcessPipeline TutorialProcess TREvent2.xml shippingreader

Note The value of the tag ID in the TREvent2.xml file is "AQEBAQ==", which is a base64 string representation of the hex2 value "01010101", and the value of the PONumber field is PO654321, which is incorrect.

To verify that the process received the event

1. In RFID Manager, right-click TutorialProcess, and then click View Tags.

2. In the View Tags - TutorialProcess dialog box, click Refresh to refresh the list, and verify that the two tags you posted appear in the list.

3. Click Close to close the View Tags dialog box.

To verify that the BRE policy executed

1. In Windows Explorer, navigate to the Processes\TutorialProcess subfolder in the BizTalk RFID installation directory.

2. Open the RFIDTutorial.log file in Notepad.

3. Confirm that you see an entry similar to the following entry:

13| Info|070207 11:54:08|PO numbers do not match|[BREPolicyExecutor]

Note The VerifyPO policy logs this message when the PO numbers do not match. The second tag you posted has the incorrect PO number. Hence, the condition in the Match rule of the VerifyPO policy evaluates to true, and the actions are executed.

To verify that MyEventHandler executed

1. In Windows Explorer, navigate to the c:\rfidtutorial\output\asn folder, and verify that only one file with prefix ASN_ is generated.

2. Open the file in Notepad, and confirm that the value of the PONumber field is PO123456.

3. Close Notepad.

40

Page 40: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

To verify that the SqlServerSink event handler executed

1. Click Start, point to Programs, point to Microsoft SQL Server, and then click SQL Server Management Studio.

2. Enter the appropriate credentials, and then click Connect if you see the Connect to Server dialog box.

3. In the Object Explorer window, expand Databases, and confirm that the RFIDsink database exists.

4. Click RFIDsink, and then click New Query on the toolbar.

Note The SqlServerSink event handler creates the RFIDsink database when the component is invoked for the first time and if the database does not exist on the computer.

5. Type and execute the following query in the query editor.

select * from tagevents where processname='TutorialProcess' order by

sinktime desc

Note The sink time is the date-time stamp at which the process receives the event. The tag time is the date-time stamp in the input XML file.

6. Confirm that you see only one tag with identifier 01010101 displayed in the result list with the latest date-time stamp for sinktime.

CommentsThe following comments apply to this step:

The AddEventToProcessPipeline method or the Send Tags dialog box posts a tag-read event directly to the process pipeline. The event is a simulated tag-read event, and there is no physical device or device simulator involved in this scenario.

In a real-world scenario, a tag reader device sends a message to the device provider when an item with a tag comes within its range, and the provider raises an event for the event processing engine to process. You can also write a device simulator that simulates a real device, and have the simulator send a message to the provider, which in turn raises a tag-read event.

Set the logging mode to verbose to debug any issues.

In the order fulfillment scenario, a reader at the shipping station raises a tag-read event for an RFID process when an item is going out the dock door to the distribution center, and the RFID process generates and sends an ASN message to distribution center if the PO number in the Cases Tagged database match the PO number in the tag-read event.

41

Page 41: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Next StepsNow that you have completed this step, perform the steps in Lesson 4: Create and Use a Device Provider.

Lesson 4: Create and Use a Device ProviderIn the previous lessons, you did the following:

Created the TutorialProcess process, added a logical device, and added a SqlServerSink event handler in Lesson 1: Create an RFID Process.

Added a custom event handler of type MyEventHandler in Lesson 2: Create a Custom Event Handler and Add It to the Process.

Added a RuleEnginePolicyExecutor event handler in Lesson 3: Add the RuleEnginePolicyExecutor Event Handler to the Process.

In this lesson, you create a device provider named TutorialProvider, add a device named TutorialDevice to BizTalk RFID, and bind the logical device in TutorialProcess to TutorialDevice. The TutorialProvider provider also simulates the device, and the provider generates two tag-read events automatically.

In This Lesson Step 1: Create a Skeleton Provider by Using the Provider Template

Step 2: Start the Provider

Step 3: Add an RFID Device and View Its Properties

Step 4: Test the Process

Step 1: Create a Skeleton Provider by Using the Provider TemplateProvider Template is a MicrosoftVisual C# sample that ships with a Visual Studio template that can be used to write Device Service Provider Interface (DSPI) device providers. You can download the sample from the BizTalk Server 2006 R2 Code Samples Web site (http://go.microsoft.com/fwlink/?LinkId=83460)

To write a DSPI device provider by using the provider template, you need to create a new Visual Studio project using the template and implement the methods in the classes that derive

42

Page 42: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

from the T:Microsoft.SensorServices.Rfid.Dspi.DeviceProvider and T:Microsoft.SensorServices.Rfid.Dspi.PhysicalDeviceProxy classes.

In this step, you create a Visual Studio project by using the provider template, but you do not add any code.

Prerequisites You must download the Provider Template sample to your computer.

Overview of This StepYou perform the following procedures in this step.

Procedure Description

To create a skeleton provider by using the provider template

This procedure has instructions to create a skeleton provider by using the Visual Studio template that ships with the Provider Template sample.

To verify that the TutorialProvider provider is successfully registered

This procedure has instructions to verify that the TutorialProvider provider is registered successfully by using RFID Manager.

ProceduresTo create a skeleton provider by using the provider template

1. Copy the DSPI Provider Template.zip file that ships with the Provider Template sample to the Visual Studio templates folder.

The default location of the Visual Studio templates folder is C:\Documents and Settings\<User Name>\My Documents\Visual Studio <version number>\Templates\ProjectTemplates\Visual C#. You need to place the .zip file in the Visual Studio templates folder exactly as it is (that is, without decompressing it). Visual Studio expects the templates to be in the .zip format.

2. Click Start, point to All Programs, point to Visual Studio, and then click Visual Studio.

3. On the menu bar, click File, point to New, and then click Project. 4. In the Project types list, click Visual C#.

5. In the Templates list, in My Templates, click DSPI Provider Template.

6. For Location, type c:\rfidtutorial.

43

Page 43: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

7. For Name, type TutorialProvider, and then click OK.

8. In Solution Explorer, right-click TutorialProvider, and then click Build.

The project template is set up so that after the build, the provider DLL is automatically copied to the provider folder and the provider is registered with the server. Thus simply building the empty project by using the supplied template results in your provider being registered with BizTalk RFID. See the pre-build and post-build commands for the project to understand how this works.

To verify that the TutorialProvider provider is successfully registered

1. Click Start, point to All Programs, click Microsoft BizTalk RFID, and then click RFID Manager. If you had RFID Manager open before building the Visual Studio project, press F5 to refresh the list of providers.

2. Expand RFID Services Administration, expand <Machine Name>, and then click Device Providers.

3. Verify that you see TutorialProvider in the list of Device Providers, and that the status of the provider is Registered.

Next StepsNow that you have completed step 1, perform Step 2: Start the Provider, which gives you step-by-step instructions for adding code to the TutorialDeviceProvider class that derives from the T:Microsoft.SensorServices.Rfid.Dspi.DeviceProvider class, and for starting the provider.

Step 2: Start the ProviderIn the previous step, you created a Visual Studio project by using the provider template. In this step you add code to implement the Init method of the TutorialDeviceProvider class. RFID Manager invokes the Init method when you start the TutorialProvider provider. Note that the GetProviderMetadata method contains the default implementation, and you may want to change the implementation based on your requirements.

Prerequisites You must complete Step 1: Create a Skeleton Provider by Using the Provider Template

before performing this step.

Overview of This StepYou perform the following procedures in this step.

44

Page 44: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Procedure Description

To test the TutorialProvider provider before implementing the Init method

This procedure has instructions to test the TutorialProvider provider before modifying the Init method to contain code instead of throwing an exception.

To implement the Init method of the TutorialDeviceProvider class

This procedure has instructions to add code to the Init method.

To test the TutorialProvider provider after implementing the Init method

This procedure has instructions to test the TutorialProvider provider after adding code to the Init method.

ProceduresTo test the TutorialProvider provider before implementing the Init method

1. In RFID Manager, in the list of Device Providers, right-click TutorialProvider, and then click Start. You should see a message box that says "Provider TutorialProvider encountered error. The method or operation is not implemented. Resolve the issue that is causing the error, and then retry the operation". You get this error message because the TutorialDeviceProvider class does not implement the Init method.

2. In the message box, click OK.

To implement the Init method of the TutorialDeviceProvider class

1. In Visual Studio, in Solution Explorer, double-click MyDeviceProvider.cs.

2. Add the following statement at the beginning of the file after the existing using statements:

using Microsoft.SensorServices.Rfid.Utilities;

3. Add a private member variable logger of type ILogger to the TutorialDeviceProvider class:

private ILogger logger;

4. Expand the region titled provider lifecycle and factory method in the source editor.

5. Delete the throw statement in the Init method.

6. Add the following code to the Init method:

//use the logger object passed as a parameter to log information.

this.logger = providerContext.Logger;

45

Page 45: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

logger.Info("In the Init function of the provider");

Note The default location for the provider log file is %RFIDDATADIR%\Providers\TutorialProvider, and the name of the log file is TutorialProvider.log.

7. Delete the throw statement from the Shutdown method.

8. Expand the region titled metadata support. 9. Review the code in the GetProviderMetadata method.

10. Update the code in the GetProviderMetadata method with information relevant to your organization. This instruction is optional.

11. Right-click TutorialProvider, and then click Build.

To test the TutorialProvider provider after implementing the Init method

1. In RFID Manager, click DeviceProviders in the left pane if any other node is selected.

2. Press F5 to refresh the view.

3. Verify that the value of the status field is set to Started - OK for TutorialProvider.

Note The post-build command of the project starts the provider automatically when you build the project. It failed the previous time because the Init method was not implemented.

4. Navigate to the %RFIDDATADIR%\Providers\TutorialProvider directory, and open the TutorialProvider.log file in Notepad.

5. Verify that you see the message that the Init method logs in the log file.

Next StepsNow that you have completed this step, perform Step 3: Add an RFID Device and View Its Properties, which gives you step-by-step instructions for adding code to implement a few methods of the MyPhysicalDeviceProxy class that derives from the T:Microsoft.SensorServices.Rfid.Dspi.PhysicalDeviceProxy class.

Step 3: Add an RFID Device and View Its PropertiesIn the previous step, you added code for the Init method of the MyDeviceProvider class. In this step, you add code to implement a few methods of the MyPhysicalDeviceProxy class. These methods are called when you add a device that uses the TutorialProvider provider and view properties of the device.

46

Page 46: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Prerequisites You must complete Step 2: Start the Provider before performing this step.

Overview of This StepYou perform the following procedures in this step.

Procedure Description

To add a device that uses the TutorialProvider provider

This procedure has instructions to add a device named TutorialDevice that uses the TutorialProvider provider.

To view properties of the TutorialDevice device This procedure has instructions to view properties of the TutorialDevice device.

To implement methods of the PhysicalDeviceProxy class

This procedure has instructions to implement methods of the PhysicalDeviceProxy class to support viewing properties of the device in RFID Manager.

ProceduresTo add a device that uses the TutorialProvider provider

1. In RFID Manager, right-click Devices, and then click New Device.

2. On the Introduction page, click Next.3. On the Provider page, select TutorialProvider from the Available Providers, and then

click Next.4. On the Connection page, verify that you see only TCP in the drop-down list of protocols.

You see only TCP in the drop-down list of protocols because TCP is the only protocol supported by the TutorialProvider provider. See the GetProviderMetadata implementation of the MyDeviceProvider class to confirm this.

5. On the Connection page, type TutorialDevice for the name.

6. Type 127.0.0.1 for Name or IP Address, type 8888 for the port, and then click Next. 7. On the Add Devices to a Group page, click Next. 8. On the Authentication page, click Next. 9. On the Unsuccessful page, verify that the connection to the device failed. The

connection to the device failed because the MyPhysicalDeviceProxy class does not implement the methods that RFID Manager invokes.

47

Page 47: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

10. For Name, type TutorialDevice, and then click Next. 11. On the Completion page, click Finish.

To view properties of the TutorialDevice device

1. In RFID Manager, right-click TutorialDevice, and then click Properties.

You should see a message box that says "A connection could not be established to the device. To view the last known properties of the device or to modify the connection information, click OK". Viewing the properties of the device failed because the MyPhysicalDeviceProxy class does not implement the methods that RFID Manager invokes.

2. In the message box, click OK.

3. In the TutorialDevice Device Properties dialog box, click Cancel. Now you will implement the methods required to establish a connection to TutorialDevice.

To implement methods of the PhysicalDeviceProxy class

1. In Visual Studio, in Solution Explorer, double-click MyDeviceProvider.cs if it is not already open in the source editor.

2. Expand the region titled provider lifecycle and factory methods if it is not already expanded.

3. Verify that the GetDevice method creates and returns an object of the MyProviderDeviceProxy class.

4. In Solution Explorer, double-click MyPhysicalDeviceProxy.cs.

5. Expand #region internal implementation.

6. Add a private member variable named connectionInformation of type ConnectionInformation as shown in the following statement:

private ConnectionInformation connectionInformation;

7. Remove the existing throw statement from the constructor.

8. Add the following statement to the MyPhysicalDeviceProxy constructor:

this.connectionInformation = connectionInformation;

9. Expand the region titled connection management. 10. Remove throw statements from all the methods in this region (SetupConnection,

IsConnectionAlive, and Close).

11. Add the following statement to the IsConnectionAlive method:

return true;

Note You can add code to the SetupConnection method to set up a connection to

48

Page 48: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

your device, to the Close method to close the connection to your device, and to the IsConnectionAlive method to ping the device to see if the connection is still alive.

12. Expand the region titled device metadata.

13. Delete the throw statement from the Get method of the DeviceInformation property.

14. Add the following code to the Get method of the DeviceInformation property:

//use the connectionInformation that was saved off in the constructor

DeviceInformation info = new DeviceInformation("1",

this.connectionInformation, null);

return info;

15. In Solution Explorer, right-click TutorialProvider, and then click Build.

16. In RFID Manager, right-click TutorialDevice, and then click Properties.

You should see a message box that says "The properties of the device could not be retrieved”.

Note The methods that you have implemented so far allow a connection to the device to succeed. Now you will implement the methods to allow clients to get information about properties.

17. Delete the throw statement from the GetPropertyMetadata method.

18. Add the following code to the GetPropertyMetadata method:

//todo: Return metadata for the properties supported by your device instead

//of returning an empty dictionary

Dictionary<PropertyKey, RfidDevicePropertyMetadata> result = new

Dictionary<PropertyKey, RfidDevicePropertyMetadata>();

return result;

19. Expand the region titled commands and notifications.

20. Add the following code to the SendMessage method that takes two parameters (sourceName and command):

ResponseEventArgs response = new ResponseEventArgs(command);

switch (command.GetType().Name)

{

case "GetCurrentPropertyProfileCommand":

{

GetCurrentPropertyProfileCommand cmd = command as

GetCurrentPropertyProfileCommand;

PropertyProfile pp;

49

Page 49: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

if (sourceName == null)

{

//todo: get the actual properties from the device

pp = new PropertyProfile();

}

else

{

//todo: get the actual properties from the source specified

pp = new PropertyProfile();

}

cmd.Response = new GetCurrentPropertyProfileResponse(pp);

break;

}

default:

{

response = new ResponseEventArgs(command, new

CommandError(ErrorCode.FunctionUnsupported, "not supported", "notsup"));

break;

}

}

CmdResponseEvent(this, response);

21. Add the following code to the SendMessage method that takes only one parameter:

SendMessage(null, command);

22. Expand the region titled device metadata.

23. Delete the throw statement from the GetSources method.

24. Add the following code to the GetSources method:

//todo: return the actual sources / antennas present in the device

Dictionary<string, PropertyProfile> result = new Dictionary<string,

PropertyProfile>();

return result;

25. In Solution Explorer, right-click TutorialProvider, and then click Build.

26. In RFID Manager, right-click TutorialDevice, and then click Properties. You should be able to see the TutorialDevice Device Properties dialog box without any error messages.

50

Page 50: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Next StepsNow that you have completed this step, perform Step 4: Test the Process, which gives you step-by-step instructions for testing the TutorialProvider provider by using an RFID process.

Step 4: Test the ProcessIn this step, you add code to handle the TagReadEvent event, create a test RFID process, and use RFID Manager to send tags to the process.

Prerequisites You must complete the steps in Step 3: Add an RFID Device and View Its Properties before

performing this step.

Overview of This StepYou perform the following procedures in this step.

Procedure Description

To add code to support handling the TagReadEvent event

This procedure has instructions to add code to support handling the TagReadEvent event.

To modify TutorialProcess to use TutorialDevice

This procedure has instructions to modify the TutorialProcess process to use the TutorialDevice device.

To verify that the process received the event This procedure has instructions to verify that TutorialProcess received the events posted by the TutorialProvider provider.

To verify that the BRE policy executed This procedure has instructions to verify that the BRE policy executed.

To verify that MyEventHandler executed This procedure has instructions to verify that MyEventHandler executed.

To verify that the SqlServerSink event handler executed

This procedure has instructions to verify that the SqlServerSink event handler executed.

51

Page 51: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

ProceduresTo modify TutorialProcess to use TutorialDevice

1. Right-click TutorialProcess, and then click Bind.

2. On the Introduction page, click Next. 3. On the Logical Devices page, select the check box next to shippingreader, and then

click Next. 4. On the Devices and sources for shippingreader page, select the check box next to

TutorialDevice in the list of Devices and Groups, and then click Next. 5. On the Components page, click Next.6. On the Summary page, click Finish.

To add code to support handling the TagReadEvent event

1. In Visual Studio, in Solution Explorer, double-click MyPhysicalDeviceProxy.cs if the file is not already open in the source editor.

2. Add the following statement at the beginning of the file after the existing using statements:

using Microsoft.SensorServices.Rfid;

3. Add a method named handleTagReadEvent to the TutorialProviderDeviceProxy class as shown in the following code fragment:

#region handle events

void handleTagReadEvent(byte[] data, string ItemID, string PONumber, string

source, DateTime timestamp)

{

TagReadEvent ev = new TagReadEvent(data,

TagType.EpcClass1Gen2,

null, source, timestamp,

null, TagDataSelector.All);

ev.VendorSpecificData["PONumber"] = PONumber;

ev.VendorSpecificData["ItemID"] = ItemID;

Notification n = new Notification(ev);

NotificationEventArgs args = new NotificationEventArgs(n);

if (DeviceNotificationEvent != null)

{

52

Page 52: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

DeviceNotificationEvent(this, args);

}

}

#endregion //handle events

Note This method is invoked when the provider receives a tag-read event asynchronously. To notify the client of events other than responses to commands, implement DeviceNotificationEvent. The provider template that you used to develop the provider has already implemented DeviceNotificationEvent.

4. To test the HandleTagReadEvent method and to see tags in RFID Manager before hooking up your provider to get asynchronous tags from the physical device, you can temporarily add the following code to the SetupConnection method of the MyPhysicalDeviceProxy class to simulate asynchronous tag-read events. Double-click MyPhysicalDeviceProxy.cs in Solution Explorer, and copy the following code to the SetupConnection method:

//todo: Remove this temporary code after hooking up async tag

//notifications from the device to the provider.

WaitCallback cb =

delegate

{

//simulate async tag notification.

//Give the connection some time to get established

//before sending these mock tags over to the server.

Thread.Sleep(20000);

//tag-read event with right PO number

handleTagReadEvent(HexUtilities.HexDecode("0x01010101"),"1234",

"PO123456", "some location", DateTime.Now);

Thread.Sleep(20000);

//tag-read event with wrong PO number

handleTagReadEvent(HexUtilities.HexDecode("0x01010101"),"1234",

"PO564321", "some location", DateTime.Now); };

ThreadPool.QueueUserWorkItem(cb);

5. Add the following statement at the beginning of the file after the existing using statements:

using Microsoft.SensorServices.Rfid.Utilities;

using System.Threading;

53

Page 53: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

6. Right-click TutorialProvider, and then click Build.

To verify that the process received the event

1. In RFID Manager, right-click TutorialProcess, and then click View Tags.

2. In the View Tags - TutorialProcess dialog box, click Refresh to refresh the list, and verify that the tags that provider posts appear in the list.

3. Click Close to close the View Tags dialog box.

To verify that the BRE policy executed

1. In Windows Explorer, navigate to the Processes\TutorialProcess subfolder in the BizTalk RFID installation directory.

2. Open the RFIDTutorial.log file in Notepad.

3. Confirm that you see an entry similar to the following entry:

13| Info|070207 11:54:08|PO numbers do not match|[BREPolicyExecutor]

Note The VerifyPO policy logs this message when the PO numbers do not match. The second tag you posted has an incorrect PO number. Hence, the condition in the Match rule of the VerifyPO policy evaluates to true, and the actions are executed.

To verify that MyEventHandler executed

1. In Windows Explorer, navigate to the c:\rfidtutorial\output\asn folder, and verify that only one file with prefix ASN_ is generated.

2. Open the file in Notepad, and confirm that the value of the PONumber field is PO123456.

3. Close Notepad.

To verify that the SqlServerSink event handler executed

1. Click Start, point to Programs, point to Microsoft SQL Server, and then click SQL Server Management Studio.

2. Enter the appropriate credentials, and then click Connect if you see the Connect to Server dialog box.

3. In the Object Explorer window, expand Databases, and confirm that the RFIDsink database exists.

4. Click RFIDsink, and then click New Query on the toolbar.

Note The SqlServerSink event handler creates the RFIDsink database when the component is invoked for the first time and if the database does not exist on the

54

Page 54: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

computer.

5. Type and execute the following query in the query editor:

select * from tagevents where processname='TutorialProcess' order by

sinktime desc

Note The sink time is the date-time stamp at which the process receives the event. The tag time is the date-time stamp in the input XML file.

6. Confirm that you see only the tag with identifier 01010101 displayed in the result list.

Next StepsNow that you have completed this step, perform the steps in Lesson 5: Use the RFID Management API, which gives you step-by-step instructions to use the RfidClientConsole utility to clean up and install the TutorialProcess process, the TutorialProvider provider, and the TutorialDevice device.

Lesson 5: Use the RFID Management APIIn the previous lessons, you did the following:

Created the TutorialProcess process, added a logical device, and added a SqlServerSink event handler in Lesson 1: Create an RFID Process.

Added a custom event handler of type MyEventHandler in Lesson 2: Create a Custom Event Handler and Add It to the Process.

Added a RuleEnginePolicyExecutor event handler in Lesson 3: Add the RuleEnginePolicyExecutor Event Handler to the Process.

Created the TutorialProvider provider, added the TutorialDevice device, and bound the logical device in TutorialProcess to TutorialDevice in Lesson 4: Create and Use a Device Provider. The provider itself simulates the device, and raises two tag-read events for the process to handle.

In this lesson, you create two .NET console applications by using the RFID Management API. The first application removes the TutorialProcess process, removes the TutorialDevice device, and unregisters the TutorialProvider provider from BizTalk RFID. The second application registers TutorialProvider, adds TutorialDevice, and adds TutorialProcess to BizTalk RFID. In the last step, you test TutorialProcess to make sure it is installed successfully.

In This Section Step 1: Remove a Process, a Device, and a Device Provider from BizTalk RFID

Step 2: Add a Process, a Device, and a Device Provider to BizTalk RFID

55

Page 55: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Step 3: Test the Process

Step 1: Remove a Process, a Device, and a Device Provider from BizTalk RFIDBizTalk RFID ships with an assembly named Microsoft.Rfid.ManagementWebServiceProxies, which contains several Web service proxy classes, including the following proxy classes that a client application can use to communicate with BizTalk RFID. To use the proxy classes from your application, you need to add a reference to the Microsoft.Rfid.ManagementWebServiceProxies assembly.

Name Description

ServerManagerProxy Manages the BizTalk RFID server.

ProcessManagerProxy Manages the BizTalk RFID processes.

DeviceManagerProxy Manages the BizTalk RFID devices.

ProviderManagerProxy Manages the BizTalk RFID device providers.

BindingManagerProxy Manages the bindings of a BizTalk RFID process.

ComponentManagerProxy Manages the components in a BizTalk RFID process.

In this step, you create a Visual Studio solution, and add code to remove TutorialProcess, TutorialDevice, and TutorialProvider from BizTalk RFID.

Prerequisites You must complete Lesson 4: Create and Use a Device Provider before performing this step.

Overview of This StepYou perform the following procedures in this step.

56

Page 56: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Procedure Description

To create a Visual Studio solution This procedure has instructions to create a .NET console application by using Visual Studio.

To add code to remove a process, a device, and a device provider from BizTalk RFID

This procedure has instructions to add code to the Visual Studio solution to remove a process, a device, and a device provider from BizTalk RFID.

To test the console application This procedure has instructions to test the console application and verify the results in RFID Manager.

ProceduresTo create a Visual Studio solution

1. Click Start, point to Programs, point to Visual Studio, and then click Visual Studio.

2. Click File, point to New, and then click Project. 3. In Project Types, click Visual C#, and then in Visual Studio Installed Templates, click

Console Application.

4. For Location, specify c:\rfidtutorial. 5. For Name, type UninstallApp, and then click OK.

6. In the Solution Explorer window, right-click References and then click Add Reference.

7. Click the Browse tab.

8. Navigate to the bin subdirectory in the BizTalk RFID installation folder.

9. Multiple-select Microsoft.Rfid.Design.dll, Microsoft.Rfid.ManagementWebServiceProxies.dll, Microsoft.Rfid.OobComponents.dll, and Microsoft.Rfid.SpiSdk.dll by pressing CTRL and clicking each assembly name.

10. Click OK to add references to the assemblies named in step 9.

11. Add the following using statements at the beginning of the file after the existing using statements:

using System.IO;

using System.Collections.ObjectModel;

using Microsoft.SensorServices.Rfid.Management;

using Microsoft.SensorServices.Rfid.Runtime;

57

Page 57: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

using Microsoft.SensorServices.Rfid.Design;

using Microsoft.SensorServices.Rfid.Dspi;

using Microsoft.SensorServices.Rfid.ProcessComponents;

To add code to remove a process, a device, and a device provider from BizTalk RFID

1. Add the following three static member variables to the Program class:

static string processName = "TutorialProcess";

static string deviceName = "TutorialDevice";

static string providerName = "TutorialProvider";

2. Add the following code to the Main function to remove the TutorialProcess process from BizTalk RFID:

//create a ProcessManagerProxy object

ProcessManagerProxy pmp = new ProcessManagerProxy();

//verify that the process exists

if (ProcessExists(pmp))

{

//get the process status

RfidProcessStatus[] rps = pmp.GetProcessStatus(new string[]

{ processName });

//if the process is running or paused

if ((rps.Length > 0) && ((rps[0].ExecutionState ==

ExecutionState.Started) || (rps[0].ExecutionState ==

ExecutionState.EventCollecting)))

{

Console.WriteLine("Stopping the process: " + processName);

pmp.StopProcess(processName, false);

Console.WriteLine("Verify that the process is stopped, and then

press <ENTER> to continue...");

Console.ReadLine();

}

Console.WriteLine("Deleting the process: " + processName);

pmp.DeleteProcess(processName);

Console.WriteLine("Verify that the process is deleted, and then press

<ENTER> to continue...");

58

Page 58: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Console.ReadLine();

}

3. Add the ProcessExists static member function to the Program class as shown in the following code:

static bool ProcessExists(ProcessManagerProxy pmp)

{

// get all the names of processes registed with BizTalk RFID

string[] processes = pmp.GetAllProcesses();

foreach (string process in processes)

{

//see if the "TutorialProcess" exists

// if it does, return true

if (process.CompareTo(processName) == 0)

return true;

}

//if the process is not found in the list, return false

return false;

}

4. Add the following code to the Main function after the existing code to delete the TutorialDevice device from BizTalk RFID:

//create a DeviceManagerProxy object

DeviceManagerProxy dmp = new DeviceManagerProxy();

//verify if the TutorialDevice device exists

if (DeviceExists(dmp))

{

Console.WriteLine("Deleting the device: " + deviceName);

dmp.DeleteDevice("TutorialDevice");

Console.WriteLine("Verify that the device is deleted, and then press

<ENTER> to continue...");

Console.ReadLine();

}

5. Add the DeviceExists static member function to the Program class as shown in the following code:

static bool DeviceExists(DeviceManagerProxy dmp)

{

59

Page 59: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

//get device definitions for all the devices

DeviceDefinition[] dds = dmp.GetAllDevices();

foreach (DeviceDefinition dd in dds)

{

//if TutorialDevice is found, return true

if (dd.Name.CompareTo(deviceName) == 0)

return true;

}

//If TutorialDevice is not found, return false

return false;

}

6. Add the following code to the Main function after the existing code to stop and unregister the TutorialProvider provider:

//create a ProviderManagerProxy object

ProviderManagerProxy pdmp = new ProviderManagerProxy();

//get the status of the provider

ProviderStatus[] ps = pdmp.GetProviderStatus(new string[] { providerName

});

//if provider exists

if (ps[0] != null)

{

if ( ps[0].ProviderState == ProviderState.Running)

{

Console.WriteLine("Stopping the provider: " + providerName);

pdmp.StopProvider(providerName);

Console.WriteLine("Verify that the provider is stopped, and then

press <ENTER> to continue...");

Console.ReadLine();

}

Console.WriteLine("Unregistering the provider: " + providerName);

pdmp.UnregisterProvider(providerName);

Console.WriteLine("Verify that the provider is unregistered

(deleted), and then press <ENTER> to continue...");

Console.ReadLine();

60

Page 60: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

}

7. In the Solution Explorer window, right-click UninstallApp, and then click Build.

To test the UninstallApp solution

1. Press CTRL+F5 to execute the UninstallApp program. You should see the following output in the command prompt window:

Stopping the process TutorialProcess

Verify that the process is stopped, and then press <ENTER> to continue...

2. In RFID Manager, click Processes, and then verify that the TutorialProcess process is in the Stopped state. If the process is still in the Started state, press F5 to refresh the view, and verify again.

3. In the command prompt window, press ENTER to continue. You should see the following output:

Deleting the process: TutorialProcess

Verify that the process is deleted, and then press <ENTER> to continue...

4. In RFID Manager, verify that the TutorialProcess process is deleted. If you still see TutorialProcess, press F5 to refresh the view in RFID Manager, and verify again.

5. In the command prompt window, press ENTER to continue. You should see the following output in the command prompt window:

Deleting the device: TutorialDevice

Verify that the device is deleted, and then press <ENTER> to continue...

6. In RFID Manager, verify that the TutorialDevice device is deleted. If you still see TutorialDevice, press F5 to refresh the view in RFID Manager, and verify again.

7. In the command prompt window, press ENTER to continue. You should see the following output in the command prompt window:

Stopping the provider: TutorialProvider

Verify that the provider is stopped, and then press <ENTER> to continue...

8. In RFID Manager, click Device Providers in the left pane, and then verify that the TutorialProvider provider is in the Stopped state. If the provider is not in the Stopped state, press F5 to refresh the view in RFID Manager, and verify again.

9. In the command prompt window, press ENTER to continue. You should see the following output in the command prompt window:

Unregistering the provider: TutorialProvider

Verify that the provider is unregistered (deleted), and then press <ENTER>

to continue...

10. In RFID Manager, verify that the TutorialProvider provider is deleted. If you still see TutorialProvider, press F5 to refresh the view in RFID Manager, and verify again.

61

Page 61: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Next StepsNow that you have completed this step, perform Step 2: Add a Process, a Device, and a Device Provider to BizTalk RFID, which gives you step-by-step instructions to add a device, a provider, and a process.

Step 2: Add a Process, a Device, and a Device Provider to BizTalk RFIDBizTalk RFID ships with an assembly named Microsoft.Rfid.ManagementWebServiceProxies, which contains several Web service proxy classes, including the following proxy classes that a client application can use to communicate with BizTalk RFID. To use the proxy classes from your application, you need to add a reference to the Microsoft.Rfid.ManagementWebServiceProxies assembly.

Name Description

ServerManagerProxy Manages the BizTalk RFID server.

ProcessManagerProxy Manages the BizTalk RFID processes.

DeviceManagerProxy Manages the BizTalk RFID devices.

ProviderManagerProxy Manages the BizTalk RFID device providers.

BindingManagerProxy Manages the bindings of a BizTalk RFID process.

ComponentManagerProxy Manages the components in a BizTalk RFID process.

In this step, you create a Visual Studio solution, and add code to add TutorialProvider, TutorialDevice, and TutorialProcess to BizTalk RFID.

Prerequisites You must complete Step 1: Remove a Process, a Device, and a Device Provider from BizTalk

RFID before performing this step.

62

Page 62: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Overview of This StepYou perform the following procedures in this step.

Procedure Description

To create a Visual Studio solution This procedure has instructions to create a .NET console application by using Visual Studio.

To add code to add a device provider, a device, and a process to BizTalk RFID

This procedure has instructions to add code to the Visual Studio solution to add a device provider, a device, and a process to BizTalk RFID.

To test the console application This procedure has instructions to test the console application and verify the results in RFID Manager.

ProceduresTo create a Visual Studio solution

1. Click Start, point to Programs, point to Visual Studio, and then click Visual Studio.

2. Click File, point to New, and then click Project. 3. For Location, specify c:\rfidtutorial. 4. For Name, type InstallApp, and then click OK.

5. Right-click References and then click Add Reference.

6. Click the Browse tab.

7. Navigate to the bin subdirectory in the BizTalk RFID installation folder.

8. Multiple-select Microsoft.Rfid.Design.dll, Microsoft.Rfid.ManagementWebServiceProxies.dll, Microsoft.Rfid.OobComponents.dll, and Microsoft.Rfid.SpiSdk.dll by pressing CTRL and clicking each assembly name.

9. Click OK to add references to the assemblies named in step 8.

10. Add the following using statements at the beginning of the file after the existing using statements:

using System.IO;

using System.Collections.ObjectModel;

using Microsoft.SensorServices.Rfid.Management;

63

Page 63: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

using Microsoft.SensorServices.Rfid.Runtime;

using Microsoft.SensorServices.Rfid.Design;

using Microsoft.SensorServices.Rfid.Dspi;

using Microsoft.SensorServices.Rfid.ProcessComponents;

To add code to add a device provider, a device, and a process to BizTalk RFID

1. Add the following three static member variables to the Program class:

static string processName = "TutorialProcess";

static string deviceName = "TutorialDevice";

static string providerName = "TutorialProvider";

2. Add the following code to the Main function to register the TutorialProvider provider with BizTalk RFID:

ProviderManagerProxy pdmp = new ProviderManagerProxy();

Console.WriteLine("Registering the provider: " + providerName);

pdmp.RegisterProvider(providerName, providerName, null);

Console.WriteLine("Verify that the provider is registered, and then press

<ENTER> to continue");

Console.ReadLine();

3. Add the following code to the Main function after the existing code to copy TutorialProvider.dll to the appbase\bin subdirectory:

string appbaseProvider = pdmp.GetAppBaseForProvider(providerName);

File.Copy(@"C:\RFIDTutorial\TutorialProvider\obj\debug\

TutorialProvider.dll", appbaseProvider + "\\bin\\TutorialProvider.dll",

true);

Console.WriteLine("Copied the provider binary to its appbase\\bin

directory");

4. Add the following code to the Main function after the existing code to add the TutorialDevice device to BizTalk RFID:

DeviceManagerProxy dmp = new DeviceManagerProxy();

Console.WriteLine("Adding a device: " + deviceName);

TcpTransportSettings tts = new TcpTransportSettings("localhost", 8888);

ConnectionInformation ci = new ConnectionInformation(providerName, tts);

UserDeviceInformation udi = new UserDeviceInformation(ci, null);

DeviceDefinition dd = new DeviceDefinition(udi, "TutorialDevice", null);

dmp.AddDevice(dd, "RootDeviceGroup", true);

64

Page 64: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Console.WriteLine("Verify that the device is added, and then press <ENTER>

to continue");

Console.ReadLine();

5. Add the following code to the Main function after the existing code to add the TutorialProcess process to BizTalk RFID:

ProcessManagerProxy pmp = new ProcessManagerProxy();

Console.WriteLine("Creating a process: " + processName);

RfidProcess process = new RfidProcess();

process.Name = processName;

LogicalDevice mylogicaldevice = new LogicalDevice("shippingreader", "my

logical device");

process.LogicalSource.LogicalDeviceList.Add(mylogicaldevice);

//get OOb assembly name and class names

Type t1 = typeof(SqlServerSink);

string oobAsmName = t1.Assembly.FullName;

string sqlSinkClsName = t1.FullName;

Type t2 = typeof(RuleEnginePolicyExecutor);

string breClsName = t2.FullName;

//add devent handlers to the process

EventHandlerDefinition breEHD = new EventHandlerDefinition("MyBREInst",

oobAsmName, breClsName);

process.LogicalSource.ComponentList.Add(breEHD);

EventHandlerDefinition myEHD = new EventHandlerDefinition("ASNEventHandler",

"MyEventHandler", "MyEventHandler.MyEventHandler");

process.LogicalSource.ComponentList.Add(myEHD);

EventHandlerDefinition sqlSinkEHD = new EventHandlerDefinition("MySqlSink",

oobAsmName, sqlSinkClsName);

process.LogicalSource.ComponentList.Add(sqlSinkEHD);

string appbaseProcess = pmp.GetAppBaseForProcess(processName);

File.Copy(@"C:\RFIDTutorial\MyEventHandler\bin\Debug\MyEventHandler.dll",

appbaseProcess + "\\bin\\MyEventHandler.dll", true);

Console.WriteLine("Copied the custom event handler MyEventHandler binary to

its process app base\\bin directory");

65

Page 65: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

pmp.SaveProcess(process);

6. Add the following code to the Main function after the existing code to bind shippingreader (logical device) with TutorialDevice (physical device):

ProcessBinding processBinding = new ProcessBinding();

DeviceBinding deviceBinding = new DeviceBinding();

deviceBinding.DeviceList.Add("TutorialDevice");

processBinding.DeviceBindings.Add("shippingreader", deviceBinding);

7. Add the following code to the Main function after the existing code to specify component bindings for the RuleEnginePolicyExecutor component:

Dictionary<string, object> breSinkProperties = new Dictionary<string,

object>();

breSinkProperties[RuleEnginePolicyExecutor.PolicyName] = "VerifyPO";

Collection<FactBinding> l = new Collection<FactBinding>();

DataConnectionFactBinding d1 = new DataConnectionFactBinding("Data

Source=(local);Initial Catalog=\"RFIDTutorial\";Integrated Security=SSPI",

"TagPO", "RFIDTutorial", true);

l.Add(d1);

string xml = FactBinding.SerializeFactList(l);

breSinkProperties[RuleEnginePolicyExecutor.FactBindingsName] = xml;

processBinding.ComponentBindings.Add("MyBREInst", breSinkProperties);

8. Add the following code to the Main function after the existing code to specify component bindings for the MyEventHandler component:

Dictionary<string, object> myEHParams = new Dictionary<string, object>();

myEHParams["LogRequirement"] = true;

myEHParams["ASNOutputFolder"] = @"C:\RFIDTutorial\Output\ASN";

processBinding.ComponentBindings.Add("ASNEventHandler", myEHParams);

// We do not want to set any component binding parameters because

// we are ok with the default bindings in the SQLServerSink

9. Add the following code to the Main function after the existing code to save the bindings for the TutorialProcess process:

BindingManagerProxy bmp = new BindingManagerProxy();

bmp.SaveBinding(processName, processBinding);

Console.WriteLine("Verify that the TutorialProcess is created, and then

press <ENTER> to continue");

Console.ReadLine();

66

Page 66: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

10. Add the following code to the Main function after the existing code to start the TutorialProvider provider and the TutorialProcess process.

//Start device provider and start the process one after another

Console.WriteLine("Starting the provider: " + providerName + ", and starting

the process: " + processName);

pdmp.StartProvider(providerName);

pmp.StartProcess(processName);

Console.WriteLine("Verify that the TutorialProvider and TutorialProcess are

added, and then press <ENTER> to continue ");

Console.ReadLine();

11. In the Solution Explorer window, right-click InstallApp, and then click Build.

To test the InstallApp solution

1. Press CTRL+F5 to execute the InstallApp program. You should see the following output in the command prompt window:

Registering the provider: TutorialProvider

Verify that the provider is registered, and then press <ENTER> to continue

2. In RFID Manager, click Device Providers in the left pane, and then verify that the TutorialProvider provider is in the Registered state. If TutorialProvider does not appear in the list, press F5 to refresh the view, and verify again.

3. In the command prompt window, press ENTER to continue. You should see the following output:

Copied the provider binary to its appbase\bin directory

Adding a device: TutorialDevice

Verify that the device is added, and then press <ENTER> to continue

4. In RFID Manager, click Devices in the left pane, and then verify that TutorialDevice is in the list of Devices. If you do not see TutorialDevice in the list, press F5 to refresh the view in RFID Manager, and verify again.

5. In the command prompt window, press ENTER to continue. You should see the following output in the command prompt window:

Creating a process: POTestProcess

Copied the custom event handler MyEventHandler binary to its process app

base\bin directory

Verify that the TutorialProcess is created, and then press <ENTER> to

continue

6. In RFID Manager, click Processes in the left pane, and then verify that the TutorialProcess process is displayed in the list of Processes. If you do not see

67

Page 67: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

TutorialProcess in the list, press F5 to refresh the view in RFID Manager, and verify again.

7. In the command prompt window, press ENTER to continue. You should see the following output in the command prompt window:

Starting the provider: TutorialProvider, and starting the process:

POTestProcess

Verify that the TutorialProvider and TutorialProcess are added, and then

press <ENTER> to continue

8. In RFID Manager, click Device Providers in the left pane, and then verify that the TutorialProvider provider is in the Started state. If the provider is still in the Stopped state, press F5 to refresh the view, and verify again.

9. If RFID Manager, click Processes in the left pane, and then verify that the TutorialProcess process is in the Started state. If the process is still in the Stopped state, press F5 to refresh the view, and verify again.

10. In the command prompt window, press ENTER to end the InstallApp program.

11. Press any key to close the command prompt window.

Next StepsNow that you have completed this step, perform Step 3: Test the Process, which gives you step-by-step instructions to test the TutorialProcess process.

Step 3: Test the ProcessWhen TutorialProvider starts, it automatically posts two tag-read events to the TutorialProcess process. In this step, you will verify that the event handlers in TutorialProcess executed successfully.

Prerequisites You must complete Step 2: Add a Process, a Device, and a Device Provider to BizTalk RFID

before performing this step.

Overview of This StepYou perform the following procedures in this step.

Procedure Description

To verify that the BRE policy executed This procedure has instructions to verify that

68

Page 68: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Procedure Description

the BRE policy executed.

To verify that MyEventHandler executed This procedure has instructions to verify that MyEventHandler executed.

To verify that the SqlServerSink event handler executed

This procedure has instructions to verify that the SqlServerSink event handler executed.

ProceduresTo verify that the BRE policy executed

1. In Windows Explorer, navigate to the Processes\TutorialProcess subfolder in the BizTalk RFID installation directory.

2. Open the RFIDTutorial.log file in Notepad.

3. Confirm that you see an entry similar to the following entry:

13| Info|070207 11:54:08|PO numbers do not match|[BREPolicyExecutor]

Note The VerifyPO policy logs this message when the PO numbers do not match. The second tag you posted has an incorrect PO number. Hence, the condition in the Match rule of VerifyPO policy evaluates to true, and the actions are executed.

To verify that MyEventHandler executed

1. In Windows Explorer, navigate to the c:\rfidtutorial\output\asn folder, and verify that only one file with prefix ASN_ is generated.

2. Open the file in Notepad, and confirm that the value of the PONumber field is PO123456.

3. Close Notepad.

To verify that the SqlServerSink event handler executed

1. Click Start, point to Programs, point to Microsoft SQL Server, and then click SQL Server Management Studio.

2. Enter the appropriate credentials, and then click Connect if you see the Connect to Server dialog box.

3. In the Object Explorer window, expand Databases, and confirm that the RFIDsink database exists.

4. Click RFIDsink, and then click New Query on the toolbar.

Note

69

Page 69: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

The SqlServerSink event handler creates the RFIDsink database when the component is invoked for the first time and if the database does not exist on the computer.

5. Type and execute the following query in the query editor:

select * from tagevents where processname='TutorialProcess' order by

sinktime desc

Note The sink time is the date-time stamp at which the process receives the event. The tag time is the date-time stamp in the input XML file.

6. Confirm that you see only the tag with identifier 01010101 displayed in the result list.

Next StepsNow that you have completed this step, perform Lesson 6: Use the RfidClientConsole Utility, which has steps to use the RfidClientConsole utility to uninstall and install an RFID application.

Lesson 6: Use the RfidClientConsole UtilityIn the previous lessons, you did the following:

Created the TutorialProcess process, added a logical device, and added a SqlServerSink event handler in Lesson 1: Create an RFID Process.

Added a custom event handler of type MyEventHandler in Lesson 2: Create a Custom Event Handler and Add It to the Process.

Added a RuleEnginePolicyExecutor event handler in Lesson 3: Add the RuleEnginePolicyExecutor Event Handler to the Process.

Created the TutorialProvider provider, added the TutorialDevice device, and bound the logical device in TutorialProcess to TutorialDevice in Lesson 4: Create and Use a Device Provider. The provider itself simulates the device, and raises two tag-read events for the process to handle.

Created two .NET console applications that use the RFID Management API in Lesson 5: Use the RFID Management API. The first application uninstalls the RFID application. The second application installs the RFID application.

In this lesson, you create two command files that use the RfidClientConsole utility. The first file removes the TutorialProcess process, removes the TutorialDevice device, and unregisters the TutorialProvider provider from BizTalk RFID. The second file registers TutorialProvider, adds TutorialDevice, and adds TutorialProcess to BizTalk RFID. In the last step, you test TutorialProcess to make sure it is installed successfully.

70

Page 70: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

In This Section Step 1: Remove a Process, a Device, and a Device Provider from BizTalk RFID

Step 2: Add a Process, a Device, and a Device Provider to BizTalk RFID

Step 3: Test the Process

Step 1: Remove a Process, a Device, and a Device Provider from BizTalk RFIDBizTalk RFID provides the RFIDClientConsole command-line utility. RFIDClientConsole enables the RFID administrator to configure and monitor BizTalk RFID by using the command prompt. In this step, you use RfidClientConsole to remove a process, a device, and a device provider.

Prerequisites The TutorialProcess and TutorialProvider must be in Started state.

Overview of This StepYou perform the following procedures in this step.

Procedure Description

To create a command file with commands to remove a process, a device, and a device provider from BizTalk RFID

This procedure has instructions to create a command file with commands to remove a process, a device, and a device provider from BizTalk RFID.

To test the command file This procedure has instructions to test the console application and verify the results in RFID Manager.

71

Page 71: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

ProceduresTo create a command file with commands to remove a process, a device, and a device

provider from BizTalk RFID

1. Click Start, and then click Run.

2. Type notepad, and then click OK.

3. Click File, and then click Save.

4. Navigate to the c:\rfidtutorial folder, and then click the New Folder toolbar button to create a folder named UsingRfidClientConsole in that folder.

5. Double-click the UsingRfidClientConsole folder to open it.

6. For File name, type Cleanup.cmd.

7. Click Save to save the file and close the Save As dialog box.

8. Add the following statement to the cleanup.cmd file to stop the TutorialProcess process:

rfidclientconsole stopprocess TutorialProcess false

9. Add the following statement to the cleanup.cmd file to export all the process information to an XML file:

rfidclientconsole exportprocesses TutorialProcess C:\RFIDTutorial\

UsingRFIDClientConsole\TutorialProcess.xml

10. Add the following statement to the cleanup.cmd file to delete the TutorialProcess process:

rfidclientconsole deleteprocess TutorialProcess

11. Add the following statement to the cleanup.cmd file to export all the device information to an XML file:

rfidclientconsole exportdevices TutorialDevice C:\RFIDTutorial\

UsingRFIDClientConsole\TutorialDevice.xml

12. Add the following statement to the cleanup.cmd file to delete the TutorialDevice device:

rfidclientconsole deletedevice TutorialDevice

13. Add the following statement to the cleanup.cmd file to stop the TutorialProvider provider:

rfidclientconsole stopprovider TutorialProvider

14. Add the following statement to the cleanup.cmd file to unregister/delete the TutorialProvider provider:

rfidclientconsole unregisterprovider TutorialProvider

15. Click File, and then click Save to save the changes.

16. Click File, and then click Exit to exit Notepad.

To test the command file

1. In a command prompt window, switch to the c:\rfidtutorial\UsingRfidClientConsole folder.

72

Page 72: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

2. Type the following command and then press ENTER:

cleanup.cmd

3. Verify that you see output similar to the following output:

C:\RFIDTutorial\UsingRFIDClientConsole>cleanup

C:\RFIDTutorial\UsingRFIDClientConsole>rfidclientconsole stopprocess

TutorialProcess false

Command executed successfully

C:\RFIDTutorial\UsingRFIDClientConsole>rfidclientconsole exportprocesses

TutorialProcess C:\RFIDTut

orial\UsingRFIDClientConsole\TutorialProcess.xml

Command executed successfully

C:\RFIDTutorial\UsingRFIDClientConsole>rfidclientconsole deleteprocess

TutorialProcess

Command executed successfully

C:\RFIDTutorial\UsingRFIDClientConsole>rfidclientconsole exportdevices

TutorialDevice C:\RFIDTutorial \UsingRFIDClientConsole\TutorialDevice.xml

Command executed successfully

C:\RFIDTutorial\UsingRFIDClientConsole>rfidclientconsole deletedevice

TutorialDevice

Command executed successfully

C:\RFIDTutorial\UsingRFIDClientConsole>rfidclientconsole stopprovider

TutorialProvider

Command executed successfully

C:\RFIDTutorial\UsingRFIDClientConsole>rfidclientconsole unregisterprovider

TutorialProvider

Command executed successfully

4. Use RFID Manager to verify that TutorialProcess, TutorialProvider, and TutorialDevice are removed from BizTalk RFID. Press F5 to refresh the views in RFID

73

Page 73: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Manager to display the latest information.

Next StepsNow that you have completed this step, perform Step 2: Add a Process, a Device, and a Device Provider to BizTalk RFID, which gives you step-by-step instructions to create a file to add a process, a provider, and a device.

Step 2: Add a Process, a Device, and a Device Provider to BizTalk RFIDBizTalk RFID provides the RFIDClientConsole command-line utility. RFIDClientConsole enables the RFID administrator to configure and monitor BizTalk RFID by using the command prompt. In this step, you use the RfidClientConsole utility to add a device provider, a device, and a process.

Prerequisites You must complete Step 1: Remove a Process, a Device, and a Device Provider from BizTalk

RFID before performing this step.

Overview of This StepYou perform the following procedures in this step.

Procedure Description

To create a command file with commands to add a device provider, a device, and a process to BizTalk RFID

This procedure has instructions to create a command file with commands to add a device provider, a device, and a process to BizTalk RFID.

To test the command file This procedure has instructions to test the console application and verify the results in RFID Manager.

74

Page 74: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

ProceduresTo create a command file with commands to add a device provider, a device, and a

process to BizTalk RFID

1. Click Start, and then click Run.

2. Type notepad, and then click OK.

3. Click File, and then click Save.

4. Navigate to the c:\rfidtutorial\UsingRfidClientConsole folder.

5. For File name, type setup.cmd.

6. Click Save to save the file and close the Save As dialog box.

7. Add the following statement to the setup.cmd file to register the TutorialProvider provider with BizTalk RFID:

rfidclientconsole registerprovider TutorialProvider TutorialProvider

8. Add the following statement to the setup.cmd file to copy the provider binary file to the bin subdirectory of the provider appbase directory:

rfidclientconsole copyproviderfile TutorialProvider C:\RFIDTutorial\

TutorialProvider\obj\debug\TutorialProvider.dll

9. Add the following statement to the setup.cmd file to import the TutorialDevice device information from an XML file:

rfidclientconsole importdevices C:\RFIDTutorial\UsingRFIDClientConsole\

TutorialDevice.xml true true

10. Add the following statement to the setup.cmd file to import the TutorialProcess process information from an XML file:

rfidclientconsole importprocesses C:\RFIDTutorial\UsingRFIDClientConsole\

TutorialProcess.xml

11. Add the following statement to the setup.cmd file to start the TutorialProvider provider:

rfidclientconsole startprovider TutorialProvider

12. Add the following statement to the setup.cmd file to start the TutorialProcess process:

rfidclientconsole startprocess TutorialProcess

13. Click File, and then click Save to save the changes.

14. Click File, and then click Exit to exit Notepad.

To test the command file

1. In a command prompt window, switch to the c:\rfidtutorial\UsingRfidClientConsole folder.

2. Type the following command and then press ENTER.

setup.cmd

3. Verify that you see output similar to the following output:

75

Page 75: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

C:\RFIDTutorial\UsingRFIDClientConsole>setup

C:\RFIDTutorial\UsingRFIDClientConsole>rfidclientconsole registerprovider

TutorialProvider TutorialProvider

Command executed successfully

C:\RFIDTutorial\UsingRFIDClientConsole>rfidclientconsole copyproviderfile

TutorialProvider C:\RFIDTutor

ial\TutorialProvider\obj\debug\TutorialProvider.dll

Command executed successfully

C:\RFIDTutorial\UsingRFIDClientConsole>rfidclientconsole importdevices C:\

RFIDTutorial\Using

RFIDClientConsole\TutorialDevice.xml true true

TutorialDevice added!

The property profile for devices [TutorialDevice] could not be applied. This

can happen if the devices were

offline. For details, see the RFID service log files. Retry applying the

property profile for these de

vices again.

C:\RFIDTutorial\UsingRFIDClientConsole>rfidclientconsole importprocesses C:\

RFIDTutorial\Usi

ngRFIDClientConsole\TutorialProcess.xml

Command executed successfully

C:\RFIDTutorial\UsingRFIDClientConsole>rfidclientconsole startprovider

TutorialProvider

Command executed successfully

C:\RFIDTutorial\UsingRFIDClientConsole>rfidclientconsole startprocess

TutorialProcess

Command executed successfully

76

Page 76: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

4. Use RFID Manager to verify that TutorialProcess, TutorialProvider, and TutorialDevice are added to BizTalk RFID. Press F5 to refresh the views in RFID Manager to display the latest information.

Next StepsNow that you have completed this step, perform Step 3: Test the Process, which gives you step-by-step instructions to test the TutorialProcess process that you created by running the command file.

Step 3: Test the ProcessIn this step, you test the TutorialProcess process, and verify that the event handlers executed successfully. In the previous step, you restarted the provider, which generates two tag-read events for the TutorialProcess process to handle. The TutorialProcess process has three event handlers—RuleEnginePolicyExecutor, MyEventHandler, and SqlServerSink—in that order.

Prerequisites You must complete Step 2: Add a Process, a Device, and a Device Provider to BizTalk RFID

before performing this step.

Overview of This StepYou perform the following procedures in this step.

Procedure Description

To verify that the BRE policy executed This procedure has instructions to verify that the BRE policy executed.

To verify that MyEventHandler executed This procedure has instructions to verify that MyEventHandler executed.

To verify that the SqlServerSink event handler executed

This procedure has instructions to verify that the SqlServerSink event handler executed.

77

Page 77: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

ProceduresTo verify that the BRE policy executed

1. In Windows Explorer, navigate to the Processes\TutorialProcess subfolder in the BizTalk RFID installation directory.

2. Open the RFIDTutorial.log file in Notepad.

3. Confirm that you see an entry similar to the following entry:

13| Info|070207 11:54:08|PO numbers do not match|[BREPolicyExecutor]

Note The VerifyPO policy logs this message when the PO numbers do not match. The second tag you posted has an incorrect PO number. Hence, the condition in the Match rule of the VerifyPO policy evaluates to true, and the actions are executed.

To verify that MyEventHandler executed

1. In Windows Explorer, navigate to the c:\rfidtutorial\output\asn folder, and verify that only one file with prefix ASN_ is generated.

2. Open the file in Notepad, and confirm that the value of the PONumber field is PO123456.

3. Close Notepad.

To verify that the SqlServerSink event handler executed

1. Click Start, point to Programs, point to Microsoft SQL Server, and then click SQL Server Management Studio.

2. Enter the appropriate credentials, and then click Connect if you see the Connect to Server dialog box.

3. In the Object Explorer window, expand Databases, and confirm that the RFIDsink database exists.

4. Click RFIDsink, and then click New Query on the toolbar.

Note The SqlServerSink event handler creates the RFIDsink database when the component is invoked for the first time and if the database does not exist on the computer.

5. Type and execute the following query in the query editor:

select * from tagevents where processname='TutorialProcess' order by

sinktime desc

Note The sink time is the date-time stamp at which the process receives the event.

78

Page 78: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

The tag time is the date-time stamp in the input XML file.

6. Confirm that you see only the tag with identifier 01010101 displayed in the result list.

Next StepsNow that you have completed this step, perform the steps in Lesson 7: Create and Use a Device Simulator, which has instructions to use the RfidClientConsole utility to uninstall and install an RFID application.

Lesson 7: Create and Use a Device SimulatorIn the previous lessons, you did the following:

Created the TutorialProcess process, added a logical device, and added a SqlServerSink event handler in Lesson 1: Create an RFID Process.

Added a custom event handler of type MyEventHandler in Lesson 2: Create a Custom Event Handler and Add It to the Process.

Added a RuleEnginePolicyExecutor event handler in Lesson 3: Add the RuleEnginePolicyExecutor Event Handler to the Process.

Created the TutorialProvider provider, added the TutorialDevice device, and bound the logical device in TutorialProcess to TutorialDevice in Lesson 4: Create and Use a Device Provider. The provider itself simulates the device, and raises two tag-read events for the process to handle.

Created two .NET console applications that use the RFID Management API in Lesson 5: Use the RFID Management API. The first application uninstalls the RFID application. The second application installs the RFID application.

Created two command files that use the RfidClientConsole utility in Lesson 6: Use the RfidClientConsole Utility to uninstall and later install the RFID application.

In this lesson, you create a device simulator that simulates the TutorialDevice device by using the device simulator framework. The device simulator uses a translator component, TutorialDeviceTranslator, that you create in this lesson. The translator sends event messages in XML format to the provider through the simulator. In this lesson you modify the TutorialProvider source code to not raise events directly, but instead to connect to the simulator and receive the event XML messages from the simulator to post the tag-read event messages to the process.

In This Section Step 1: Create a Device Translator

Step 2: Modify the Provider to Use the Simulator

Step 3: Run the Device Simulator

79

Page 79: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Step 4: Test the Process

Step 1: Create a Device TranslatorThe device simulator framework exposes the Device Simulator Interface, which is an abstraction layer to communicate with vendor-specific device simulator plug-ins. A BizTalk RFID developer can use the classes in the Device Simulator Interface to develop device simulators for various devices, and use the device simulators instead of physical devices to test RFID business solutions or RFID device providers.

A device simulator consists of the following components:

Device simulator framework for managing the common functionality of all the RFID devices such as device properties, tag management, TCP connection management, read-filter management, and IO ports management.

Device translator for the device-specific functionality.

In this step, you create the TutorialDeviceTranslator device translator by using the device simulator framework. Later, in Step 3: Run the Device Simulator, you will create a configuration file for the TutorialDevice simulator to point to the TutorialDeviceTranslator translator, and then run devicesimulator.exe by specifying the configuration file as the parameter. All the device simulators use the devicesimulator.exe process, but with different configuration files pointing to different translators. The devicesimulator.exe file is a core component of the device simulator framework.

Prerequisites You must complete all the steps in Lesson 4: Create and Use a Device Provider or Lesson 5:

Use the RFID Management API or Lesson 6: Use the RfidClientConsole Utility before performing this step.

You must have Visual Studio installed on your computer.

Overview of This StepYou perform the following procedure in this step.

Procedure Description

To create a device translator This procedure has instructions to create a device translator that you can use to simulate a device.

80

Page 80: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

ProceduresTo create a device translator

1. Click Start, point to Programs, point to Visual Studio, and then click Visual Studio.

2. In Visual Studio, click File, and then click New.

3. In Project Types, click Visual C#, and then in Visual Studio Installed Templates, click Class Library.

4. For Location, type c:\rfidtutorial.5. For Name, type TutorialDeviceTranslator.6. Clear the Create directory for solution option.

7. Click OK to close the New Project dialog box.

8. In the Solution Explorer window, right-click Class1.cs, and then click Rename.

9. Type TutorialDeviceTranslator.cs, and then press ENTER.

10. Confirm that the name of the class is changed from Class1 to TutorialDeviceTranslator in the editor. If it is not changed automatically, change it manually.

11. In the Solution Explorer window, right-click References, and then click Add Reference.

12. Click the Browse tab.

13. Navigate to the bin subdirectory of the BizTalk RFID installation directory.

14. Multiple-select Microsoft.Rfid.SpiSdk.dll, Microsoft.Rfid.Util.dll and Microsoft.Rfid.Test.DSI.dll by pressing CTRL and clicking the items in the list, and then click OK.

15. If the TutorialDeviceTranslator.cs file is not open in the editor, double-click TutorialDeviceTranslator.cs in the Solution Explorer window to open it.

16. Add the following statements at the beginning of the file after the existing using statements:

using Microsoft.Rfid.Test.DeviceSimulator.Interface;

using Microsoft.SensorServices.Rfid;

using Microsoft.SensorServices.Rfid.Dspi;

using Microsoft.SensorServices.Rfid.Utilities;

using System.IO;

using System.Text;

using System.Xml;

17. Modify the class TutorialDeviceTranslator to derive from the

81

Page 81: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

T:Microsoft.Rfid.Test.DeviceSimulator.Interface.StandardDeviceTranslator class.

public class TutorialDeviceTranslator : StandardDeviceTranslator

Note A device translator class must derive from the T:Microsoft.Rfid.Test.DeviceSimulator.Interface.DeviceTranslator class or the T:Microsoft.Rfid.Test.DeviceSimulator.Interface.StandardDeviceTranslator class. The StandardDeviceTranslator class derives from the DeviceTranslator class, and does not declare the RaiseManagementEvent and RaiseDiscoveryEvent methods as abstract methods.

18. In the source editor, right-click StandardDeviceTranslator, and then click Implement Abstract Class.

19. Confirm that the Init, OpenConnection, CloseConnection, OnCommand, and RaiseNotificationEvent methods are added to the class.

20. Add a private member variable of type DeviceContext to the TutorialDeviceTranslator class.

private DeviceContext deviceContext;

21. Remove the throw statement from the Init method, and then add the following statement to the Init method:

this.deviceContext = deviceContext;

Note Use the Init method to initialize a device translator. In this case, you save the device context object passed as a parameter to the Init method in a member variable. The T:Microsoft.Rfid.Test.DeviceSimulator.Interface.DeviceContext object contains the callback context for the device translator. The DeviceContext class has member functions to log messages, send responses from translator to provider, and start and stop listening on TCP ports.

22. Remove the throw statement from the OpenConnection method, and add the following code to the OpenConnection method to have the simulator open a TCP connection for command-response exchange on the port specified in the TCP transport settings for the device in RFID Manager:

TcpTransportSettings tcpSettings = (TcpTransportSettings)transportSettings;

deviceContext.LogMessage(Level.Info, "Opening the connection");

deviceContext.StartListeningOn(tcpSettings);

23. Remove the throw statement from the CloseConnection method, and add the following code to the CloseConnection method to have the simulator close the established connection with the provider on a TCP port:

TcpTransportSettings tcpSettings = (TcpTransportSettings)transportSettings;

82

Page 82: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

deviceContext.LogMessage(Microsoft.SensorServices.Rfid.Utilities.Level.Info,

"Closing the connection");

deviceContext.StopListeningOn(tcpSettings);

24. Remove the throw statement from the RaiseNotificationEvent method that takes the TagReadEvent as a parameter, and add the following code to the method:

public override void

RaiseNotificationEvent(Microsoft.SensorServices.Rfid.TagReadEvent

tagReadEvent)

{

deviceContext.LogMessage(Microsoft.SensorServices.Rfid.Utilities.Level.Info,

"Raising notification TagReadEvent");

System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();

string strXML =

"<NotificationData><TagID>0x01010101</TagID><VendorData><ItemID>ITM1234</

ItemID><PONumber>PO123456</PONumber></VendorData></NotificationData>";

deviceContext.SendResponse(enc.GetBytes(strXML));

}

Note A device simulator configuration file contains the name of the device notification configuration file. The device notification configuration file contains settings such as number of events to be raised and interval between the events. Based on the configuration settings, a device simulator calls the RaiseNotificationEvent method of the translator it uses to receive a tag-read event message that the simulator forwards to the device provider. In this scenario, the TutorialProvider provider and TutorialDevice simulator use a custom XML protocol where the messages are in XML format.

25. In the Solution Explorer window, right-click TutorialDeviceTranslator, and then click Properties.

26. Click Build in the left pane if the Build view is not active.

27. Change the Output path from .\bin\debug to .\ so that the output file is created in the root directory of the project.

28. In the Solution Explorer window, right-click TutorialDeviceTranslator, and then click Build.

83

Page 83: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Comments The TutorialProvider provider currently generates two tag-read events automatically. Now

that you have developed the simulator, you need to have the provider not raise events; instead the provider should receive tag-read events from the simulator.

The syntax for running a device simulator by using a configuration file is:

devicesimulator.exe -c -f TutorialDeviceSimulatorConfig.xml The TutorialDeviceSimulatorConfig.xml file contains the name of the translator assembly,

which in this case is TutorialDeviceTranslator.dll. Here is a sample XML file:

<?xml version="1.0" encoding="utf-8" ?>

<profile>

<section name="NumberOfDevices">

<entry name="DeviceCount">1</entry>

</section>

<section name="DeviceInformation_1">

<entry name="DeviceName">TutorialDevice</entry>

<entry name="ConnectionType">TCPIP</entry>

<entry name="IpAddress">127.0.0.1</entry>

<entry name="PortNumber">8888</entry>

<entry name="ProviderId">TutorialProvider</entry>

<entry name="NotificationDataFile">TutorialDeviceNotificationConfig.xml</

entry>

<entry name="DeviceTranslatorAssemblyPath">TutorialDeviceTranslator.dll</

entry>

<entry name="DeviceTranslatorConfigFile"></entry>

</section>

</profile>

The following XML content is for a device notification configuration file, which contains information such as the number of times the RaiseNotificationEvent is invoked, and the interval between the invocations.

<?xml version="1.0" encoding="utf-8" ?>

<profile>

<section name="Notification">

<entry name="TimePeriod">10000</entry>

<entry name="Distribution">EXPONENTIAL</entry>

84

Page 84: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

<entry name="NotificationErrorRate">0</entry>

<entry name="WaitAfterNotification">1000</entry>

<entry name="InitialDelay">100</entry>

<entry name="Duplicate_Elimination_Time">0</entry>

<entry name="InfiniteNotification">FALSE</entry>

<entry name="ContinuousDataSection">0</entry>

<entry name="DiscreteDataSection">1</entry>

</section>

<section name="Discrete Data Section 1">

<entry name="NoOfData">1</entry>

<entry name="TagId">1234</entry>

<entry name="TagData">1234</entry>

<entry name="TagType">1</entry>

<entry name="TagSource">Antenna1</entry>

</section>

</profile>

Next StepsNow that you have completed this step, perform Step 2: Modify the Provider to Use the Simulator, which gives you step-by-step instructions to modify the provider code to use the simulator.

Step 2: Modify the Provider to Use the SimulatorIn this step, you modify the TutorialProvider source code to use the simulator. The TutorialProvider provider currently generates two tag-read events automatically. Now that you have developed the simulator, you need to have the provider not raise events; instead the provider should receive tag-read events from the simulator. The simulator sends event information in XML format to the provider, which in turn raises a tag-read event.

Prerequisites You must complete Step 1: Create a Device Translator before performing this step.

85

Page 85: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Overview of This StepYou perform the following procedure in this step.

Procedure Description

To modify the provider code to use the simulator

This procedure has instructions to modify the TutorialProvider source code to use a device simulator, and receive events from the simulated device instead of raising tag-read events itself.

ProceduresTo modify the provider code to use the simulator

1. Click Start, point to Programs, point to Visual Studio, and then click Visual Studio.

2. On the menu bar, click File, point to Open, and then click Project/Solution.

3. Navigate to the TutorialProvider folder in the RFIDTutorial folder, click TutorialProvider.sln, and then click Open.

4. In the Solution Explorer window, double-click MyPhysicalDeviceProxy.cs to open the file in the source editor.

5. Add the following private member variables to the MyPhysicalDeviceProxy class:

private TcpClient tcpClient;

private NetworkStream netStrm;

private Thread receiverThread;

private Byte[] bytes = new Byte[1024];

private AutoResetEvent receiveEvent;

6. Comment out all the existing code in the SetupConnection method that generates two tag-read events automatically.

7. Add the following code to the SetupConnection method to set up a connection to the device TutorialDevice:

TcpTransportSettings tcpSettings = connectionInformation.TransportSettings

as TcpTransportSettings;

if (tcpSettings != null)

{

//create a TCP client that connects to host and port specified

86

Page 86: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

//for TutorialDevice settings in RFID manager

tcpClient = new TcpClient(tcpSettings.Host, tcpSettings.Port);

tcpClient.NoDelay = true;

//get the network stream object

netStrm = tcpClient.GetStream();

//create a new thread that receives the information from simulator

receiverThread = new Thread(new ThreadStart(receive));

receiverThread.Name = "TCP_RECEIVER";

receiverThread.IsBackground = true;

//start the receiver thread

receiverThread.Start();

}

8. Add a method named receive as shown in the following code to receive information from the device:

private void receive()

{

//reset the receive event, which is set when the data is received

receiveEvent = new AutoResetEvent(false);

//using asynchronous receive to not to block the thread

AsyncCallback callback = new AsyncCallback(asyncReceive);

while (true)

{

//int byteCount = netStrm.Read(bytes, 0, bytes.Length);

logger.Info("MyPhysicalDeviceProxy: in receive() method");

if (netStrm == null)

logger.Info("MyPhysicalDeviceProxy: netStrm is null");

//begin reading

IAsyncResult result = netStrm.BeginRead(bytes, 0, bytes.Length,

callback, null);

//wait for the receive event to be set

int eventIndex = WaitHandle.WaitAny(new WaitHandle[1] { receiveEvent

}, 300000, false);

if (0 == eventIndex)

{

87

Page 87: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

//finish reading

int bytesRead = netStrm.EndRead(result);

if (bytesRead > 0)

{

System.Text.ASCIIEncoding enc= new

System.Text.ASCIIEncoding();

//get the xml string from the bytes

string str = enc.GetString(bytes);

str.Trim();

logger.Info("Here is the XML String provider got from

device");

logger.Info(str);

XmlDocument doc = new XmlDocument();

doc.LoadXml(str);

//get all the needed information

XmlNode notificationDataNode = doc.FirstChild;

XmlNode tagIDNode = notificationDataNode.FirstChild;

string tagID = tagIDNode.InnerText;

XmlNode vendorDataNode = notificationDataNode.LastChild;

XmlNode itemIDNode = vendorDataNode.FirstChild;

string ItemID = itemIDNode.InnerText;

XmlNode poNumberNode = vendorDataNode.LastChild;

string PONumber = poNumberNode.InnerText;

//call a private method with the data to raise an event

handleTagReadEvent(HexUtilities.HexDecode(tagID), ItemID,

PONumber, "some location", DateTime.Now);

}

}

}

}

9. Add a method named asyncReceive that sets the receiveEvent.

private void asyncReceive(IAsyncResult result)

{

logger.Info("MyPhysicalDeviceProxy: In asyncReceive method");

88

Page 88: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

receiveEvent.Set();

}

10. Add the following code to the Close method to clean up the objects created in the proxy:

logger.Info("MyPhysicalDeviceProxy: Cleaning up in the Close method");

receiverThread.Abort();

netStrm.Close();

tcpClient.Close();

11. Add a private member variable named logger of type ILogger to the MyPhysicalDeviceProxy class.

private ILogger logger;

12. Modify the constructor of the TutorialProviderDeviceProxy class to take an additional parameter of type ILogger, and initialize the logger variable as shown in the following code:

internal TutorialProviderDeviceProxy(ConnectionInformation

connectionInformation, ILogger logger)

{

this.connectionInformation = connectionInformation;

this.logger = logger;

}

13. Add the following using statements at the beginning of the MyPhysicalDeviceProxy.cs file after the existing using statements:

using System.Threading;

using System.Net.Sockets;

using System.Xml;

using System.Text;

14. In the Solution Explorer window, double-click MyDeviceProvider.cs to open the file in the editor.

15. Modify the GetDevice method to pass the logger member as a parameter to the constructor of the TutorialProviderDeviceProxy class as shown in the following code:

public override PhysicalDeviceProxy GetDevice(ConnectionInformation

connectionInformation)

{

return new TutorialProviderDeviceProxy(connectionInformation, logger);

}

16. In the Solution Explorer window, right-click TutorialProvider, and then click Build.

89

Page 89: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Comments To receive a command from an RFID client application, implement the SendMessage

method, and to send responses implement the cmdResponseEvent. The provider template that you used to develop the provider has already implemented the cmdResponseEvent. You will modify the SendMessage method to support printing tags in Lesson 8: Print a Tag.

To notify the client of events other than responses to commands, implement the DeviceNotificationEvent. The provider template that you used to develop the provider has already implemented the DeviceNotificationEvent.

Next StepsNow that you have completed this step, perform Step 3: Run the Device Simulator, which gives you step-by-step instructions to run the simulator and restart the provider to use the simulator.

Step 3: Run the Device SimulatorIn this step, you create a configuration file for the TutorialDevice simulator to point to the TutorialDeviceTranslator translator, and then run the devicesimulator.exe file by specifying the configuration file as the parameter. All the device simulators use the devicesimulator.exe process, but with different configuration files pointing to different device translators.

Prerequisites You must complete Step 2: Modify the Provider to Use the Simulator before performing this

step.

Overview of This StepYou perform the following procedure in this step.

Procedure Description

To start the simulator This procedure has instructions to start a device simulator by using devicesimulator.exe.

90

Page 90: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

ProceduresTo start the simulator

1. Click Start, and then click Run.

2. Type Notepad, and then click OK.

3. Copy the following XML content to Notepad:

<?xml version="1.0" encoding="utf-8" ?>

<profile>

<section name="NumberOfDevices">

<entry name="DeviceCount">1</entry>

</section>

<section name="DeviceInformation_1">

<entry name="DeviceName">TutorialDevice</entry>

<entry name="ConnectionType">TCPIP</entry>

<entry name="IpAddress">127.0.0.1</entry>

<entry name="PortNumber">8888</entry>

<entry name="ProviderId">TutorialProvider</entry>

<entry name="NotificationDataFile">TutorialDeviceNotificationConfig.xml</

entry>

<entry name="DeviceTranslatorAssemblyPath">TutorialDeviceTranslator.dll</

entry>

<entry name="DeviceTranslatorConfigFile"></entry>

</section>

</profile>

4. Click File, and then click Save.

5. For File name, type TutorialDeviceSimulatorConfig.xml.6. Navigate to the c:\rfidtutorial\TutorialDevicetranslator folder, and then click Save.

7. On the menu bar, click File, and then click New to create the notification configuration file.

8. Copy the following XML content to Notepad:

<?xml version="1.0" encoding="utf-8" ?>

<profile>

<section name="Notification">

<entry name="TimePeriod">10000</entry>

91

Page 91: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

<entry name="Distribution">EXPONENTIAL</entry>

<entry name="NotificationErrorRate">0</entry>

<entry name="WaitAfterNotification">1000</entry>

<entry name="InitialDelay">100</entry>

<entry name="Duplicate_Elimination_Time">0</entry>

<entry name="InfiniteNotification">FALSE</entry>

<entry name="ContinuousDataSection">0</entry>

<entry name="DiscreteDataSection">1</entry>

</section>

<section name="Discrete Data Section 1">

<entry name="NoOfData">1</entry>

<entry name="TagId">1234</entry>

<entry name="TagData">1234</entry>

<entry name="TagType">1</entry>

<entry name="TagSource">Antenna1</entry>

</section>

</profile>

9. Click File, and then click Save.

10. For File name, type TutorialDeviceNotificationConfig.xml. 11. Navigate to the c:\rfidtutorial\TutorialDevicetranslator folder, and then click Save.

12. On the menu bar, click File, and then click New.

13. Copy the following command statement to Notepad:

"%RFIDINSTALLDIR%\bin\devicesimulator.exe" -c -f

TutorialDeviceSimulatorConfig.xml

14. Click File, and then click Save.

15. For File name, type runTutorialDevicesimulator.cmd.

16. Click Save.

17. In Windows Explorer, browse to the c:\rfidtutorial\TutorialDevicetranslator folder, and then double-click runmydeviecsimulator.cmd to execute the command file.

Next StepsNow that you have completed this step, perform Step 4: Test the Process, which gives you step-by-step instructions to test the TutorialProcess process.

92

Page 92: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Step 4: Test the ProcessIn this step, you copy the updated provider binary file (TutorialProvider.dll) to the %RFIDDATADIR%\Providers\TutorialProvider\bin folder, restart the provider to use the simulator, and verify that the event handlers executed successfully.

The devicesimulator.exe file calls the RaiseNotificationEvent method of the translator only one time because there is only one tag in the discrete section of the notification configuration file. The RaiseNotificationEvent method returns an XML notification file that the translator forwards to the provider. The provider raises a tag-read event for the process to handle the event.

Prerequisites You must complete Step 3: Run the Device Simulator before performing this step.

Overview of This StepYou perform the following procedures in this step.

Procedure Description

To copy the updated provider file and restart the TutorialProvider provider

This procedure has instructions to copy the updated provider binary (.dll) file to the bin subdirectory of the provider appbase, and to restart the provider.

To verify that MyEventHandler executed This procedure has instructions to verify that MyEventHandler executed.

To verify that the SqlServerSink event handler executed

This procedure has instructions to verify that the SqlServerSink event handler executed.

ProceduresTo copy the updated provider file and restart the TutorialProvider provider

1. Click Start, and then click Run.

2. Type cmd, and then press OK.

Note On Windows Vista computers, if the User Access Control feature is turned on, click Start, point to Programs, point to Accessories, right-click Command Prompt, and then click Run As Administrator to run the command prompt with

93

Page 93: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

administrator privileges.

3. In the command-prompt window, type and execute the following command to stop the TutorialProvider provider:

rfidclientconsole.exe stopprovider TutorialProvider

4. In the command-prompt window, type and execute the following command to copy the updated provider file to the bin subdirectory of the provider appbase directory (%RFIDDATADIR%\Providers\TutorialProvider\bin):

rfidclientconsole.exe copyproviderfile TutorialProvider C:\RFIDTutorial\

TutorialProvider\obj\debug\TutorialProvider.dll

5. In the command-prompt window, type and execute the following command to start the provider:

rfidclientconsole.exe startprovider TutorialProvider

To verify that MyEventHandler executed

1. In Windows Explorer, navigate to the c:\rfidtutorial\output\asn folder, and verify that only one file with prefix ASN_ is generated.

2. Open the file in Notepad, and confirm that the value of the PONumber field is PO123456.

3. Close Notepad.

To verify that the SqlServerSink event handler executed

1. Click Start, point to Programs, point to Microsoft SQL Server, and then click SQL Server Management Studio.

2. Enter the appropriate credentials, and then click Connect if you see the Connect to Server dialog box.

3. In the Object Explorer window, expand Databases, and confirm that the RFIDsink database exists.

4. Click RFIDsink, and then click New Query on the toolbar.

Note The SqlServerSink event handler creates the RFIDsink database when the component is invoked for the first time and if the database does not exist on the computer.

5. Type and execute the following query in the query editor:

select * from tagevents where processname='TutorialProcess' order by

sinktime desc

Note The sink time is the date-time stamp at which the process receives the event. The tag time is the date-time stamp in the input XML file.

94

Page 94: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

6. Confirm that you see only the tag with identifier 01010101 displayed in the result list.

Next StepsNow that you completed this step, perform the steps in Lesson 8: Print a Tag, which has instructions to modify the TutorialProvider provider and TutorialDeviceTranslator translator code to support printing a tag.

Lesson 8: Print a TagIn the previous lessons, you did the following:

Created the TutorialProcess process, added a logical device, and added a SqlServerSink event handler in Lesson 1: Create an RFID Process.

Added a custom event handler of type MyEventHandler in Lesson 2: Create a Custom Event Handler and Add It to the Process.

Added a RuleEnginePolicyExecutor event handler in Lesson 3: Add the RuleEnginePolicyExecutor Event Handler to the Process.

Created the TutorialProvider provider, added the TutorialDevice device, and bound the logical device in TutorialProcess to TutorialDevice in Lesson 4: Create and Use a Device Provider. The provider itself simulates the device, and raises two tag-read events for the process to handle.

Created two .NET console applications that use the RFID Management API in Lesson 5: Use the RFID Management API. The first application uninstalls the RFID application. The second application installs the RFID application.

Created two command files that use the RfidClientConsole utility in Lesson 6: Use the RfidClientConsole Utility to uninstall and later install the RFID application.

Created a device simulator and modified the provider to use the simulator in Lesson 7: Create and Use a Device Simulator.

In this lesson, you modify the TutorialDeviceTranslator translator and TutorialProvider provider to support printing the tags. You also use a .NET console application to send a PrintTagCommand to the device simulator to generate two tag files. Then you use the RfidClientConsole utility to post the generated tag files to TutorialProcess to test the process.

In This Section Step 1: Modify the Translator to Support Printing a Tag

Step 2: Modify the Provider to Support Printing a Tag

Step 3: Test the Process

95

Page 95: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Step 1: Modify the Translator to Support Printing a TagTo support printing a tag from the TutorialDevice simulator, you add code to the OnCommand method of the TutorialDeviceTranslator class to recognize the print-tag request, generate a new tag, and print the tag (write the tag information to an XML file).

The TutorialProvider provider communicates with the TutorialDevice simulator by using a custom XML protocol. Here is a sample XML command message that the provider can send to the TutorialDevice simulator to print a tag:

<Command>

<Name>PrintTag</Name>

<TagID>AQEBAQ==</TagID>

<VendorData>

<ItemID>ITM1234</ItemID>

<PONumber>PO123456</PONumber>

</VendorData>

</Command>

The device simulator framework invokes the OnCommand method of the TutorialDeviceTranslator class to handle the command request. Therefore, you add code to the OnCommand method to process the request, and generate an XML output file containing the tag data. Here is the sample output file that the TutorialDevice simulator generates:

<RfidEventBase xmlns:i="http://www.w3.org/2001/XMLSchema-instance"

i:type="TagReadEvent"

xmlns="http://schemas.datacontract.org/2004/07/Microsoft.SensorServices.Rfid">

<m_lockObject />

<vendorSpecificData

xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.IO.SensorServices.Rfid.Client">

<d2p1:dictionary

xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">

<d3p1:KeyValueOfstringanyType>

<d3p1:Key>ItemID</d3p1:Key>

<d3p1:Value xmlns:d5p1="http://www.w3.org/2001/XMLSchema"

i:type="d5p1:string">

ITM1234

</d3p1:Value>

</d3p1:KeyValueOfstringanyType>

96

Page 96: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

<d3p1:KeyValueOfstringanyType>

<d3p1:Key>PONumber</d3p1:Key>

<d3p1:Value xmlns:d5p1="http://www.w3.org/2001/XMLSchema"

i:type="d5p1:string">

PO123456

</d3p1:Value>

</d3p1:KeyValueOfstringanyType>

</d2p1:dictionary>

</vendorSpecificData>

<m_deviceName>TutorialDevice</m_deviceName>

<m_sourceName>Antenna 1</m_sourceName>

<m_time>2007-05-02T11:37:10.5218784+05:30</m_time>

<data></data>

<dataSelector

xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.IO.SensorServices.Rfid.Client\"

>

<d2p1:dataSelector>123</d2p1:dataSelector>

</dataSelector>

<id>AQEBAQ==</id>

<numberingSystemIdentifier i:nil="true" />

<type

xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.IO.SensorServices.Rfid.Client">

<d2p1:description>EPC Class 0 tag</d2p1:description>

<d2p1:enumValue>1</d2p1:enumValue>

</type>

</RfidEventBase>

Later, you will use an output tag-read event XML file to test the process by using the AddEventToProcessPipeline command of the RfidClientConsole utility.

PrerequisitesYou must complete the steps in Lesson 7: Create and Use a Device Simulator before performing this step.

Overview of This StepYou perform the following procedures in this step.

97

Page 97: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Procedure Description

To stop the simulator This procedure has instructions to stop the simulator so that you can successfully build the project.

To modify the translator source code to print a tag

This procedure has instructions to modify the translator code to support printing a tag.

ProceduresTo stop the simulator

1. In the command-prompt window that runs the TutorialDevice simulator, press CTRL+C. You should see the following message in the command prompt window:

Terminate batch job (Y/N)?

2. Press Y, and then press ENTER to proceed with the termination of the simulator.

To modify the translator source code to print a tag

1. Open the TutorialDeviceTranslator solution in Visual Studio if it is not already open.

2. In the Solution Explorer window, double-click TutorialDeviceTranslator.cs to open the file in the source editor.

3. Remove the throw statement from the OnCommand method, and add the following code to the OnCommand method:

ASCIIEncoding enc = new ASCIIEncoding();

//get the command xml string from the argument data

string cmd = enc.GetString(commandArgs.Data);

//remove any trailing spaces in the command string

cmd.Trim();

//log messages that go into simulator log file

deviceContext.LogMessage(Level.Info, "Command received: " + cmd);

XmlDocument doc = new XmlDocument();

doc.LoadXml(cmd);

XmlNode commandNode = doc.FirstChild;

XmlNode nameNode = commandNode.FirstChild;

if (nameNode.InnerText.Equals("PrintTag"))

98

Page 98: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

{

XmlNode tagIDNode = nameNode.NextSibling;

String tagID = tagIDNode.InnerText;

XmlNode vendorDataNode = commandNode.LastChild;

XmlNode itemIDNode = vendorDataNode.FirstChild;

String ItemID = itemIDNode.InnerText;

XmlNode poNumberNode = vendorDataNode.LastChild;

String PONumber = poNumberNode.InnerText;

String strDateTime = DateTime.Now.ToString("s");

deviceContext.LogMessage(Level.Info, "Printing the tag");

//use the item id, po number, and tag id from the command xml data

TagReadEvent tre = new TagReadEvent(Convert.FromBase64String(tagID),

System.IO.SensorServices.Rfid.Client.TagType.EpcClass0, null, "Antenna1",

DateTime.Now, null, null);

tre.VendorSpecificData["ItemID"] = ItemID;

tre.VendorSpecificData["PONumber"] = PONumber;

tre.DeviceName = "TutorialDevice";

string strXMLPrint = RfidCommon.SerializeToXmlDataContract(tre,

typeof(RfidEventBase), true, true);

XmlDocument docPrint = new XmlDocument();

docPrint.LoadXml(strXMLPrint);

//write the tag information to an xml file with prefix tag_.

docPrint.Save("Tag_" + PONumber + "_" +

System.Guid.NewGuid().ToString() + ".xml");

deviceContext.LogMessage(Level.Info, "Tag printed");

}

4. In Solution Explorer, right-click TutorialDeviceTranslator, and then click Build.

Comments When you run the TutorialDevice simulator, the simulator creates a log file named

devicesimulator.log in the c:\rfidtutorial\TutorialDevicetranslator folder. The devicesimulator.log file contains messages you logged from the translator along with other messages.

99

Page 99: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

The device simulator log files are rotated. For more information about the log rotation feature, see Log Files with Troubleshooting Information.

To implement support for raising management and discovery events, you should modify the TutorialDeviceTranslator class to derive from the DeviceTranslator class instead of from the StandardDeviceTranslator class. The StandardDeviceTranslator class derives from the DeviceTranslator class, and does not declare the RaiseManagementNotification and RaiseDiscoveryEventNotification methods as abstract methods.

Next StepsNow that you have completed this step, perform Step 2: Modify the Provider to Support Printing a Tag, which gives you step-by-step instructions to modify the TutorialProvider provider to print tags.

Step 2: Modify the Provider to Support Printing a TagTo support printing a tag by using the TutorialProvider provider, you add code to the SendMessage method of the MyPhysicalDeviceProxy class to recognize the PrintTagCommand command, create an XML request for the simulator, and send the request to the simulator.

The TutorialProvider provider communicates with the TutorialDevice simulator by using a custom XML protocol. Here is a sample XML command message that the provider can send to the TutorialDevice simulator to print a tag:

<Command>

<Name>PrintTag</Name>

<TagID>AQEBAQ==</TagID>

<VendorData>

<ItemID>ITM1234</ItemID>

<PONumber>PO123456</PONumber>

</VendorData>

</Command>

100

Page 100: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

PrerequisitesYou must complete Step 1: Modify the Translator to Support Printing a Tag before performing this step.

Overview of This StepYou perform the following procedure in this step.

Procedure Description

To modify the provider code to support printing a tag

This procedure has instructions to modify the TutorialProvider source code to support printing a tag.

ProceduresTo modify the provider code to support printing a tag

1. Open the TutorialProvider.sln solution in Visual Studio if it is not already open.

2. In the Solution Explorer window, double-click MyPhysicalDeviceProxy.cs to open the file in the source editor.

3. Add the following case block to the Switch block in the SendMessage method before the default: statement:

case "PrintTagCommand":

{

PrintTagCommand cmd = command as PrintTagCommand;

cmd.Response = new PrintTagResponse();

byte[] TagIDPrint = cmd.PrintLabel.GetTagId();

string b64TagIDPrint = Convert.ToBase64String(TagIDPrint);

string ItemIDPrint = (string)

cmd.VendorDefinedParameters["ItemID"];

string PONumberPrint = (string)

cmd.VendorDefinedParameters["PONumber"];

string strXMLPrintCmd = "<Command><Name>PrintTag</Name><TagID>" +

b64TagIDPrint + "</TagID><VendorData><ItemID>" + ItemIDPrint +

"</ItemID><PONumber>" + PONumberPrint +

"</PONumber></VendorData></Command>";

101

Page 101: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

logger.Info("Print Command: " + strXMLPrintCmd);

ASCIIEncoding encPrint = new ASCIIEncoding();

byte[] bytesDataCmd = new Byte[1024];

bytesDataCmd = encPrint.GetBytes(strXMLPrintCmd);

logger.Info("Sending TCP data");

netStrm.Write(bytesDataCmd, 0, bytesDataCmd.Length);

netStrm.Flush();

logger.Info("Sent TCP data");

break;

}

4. In the Solution Explorer window, right-click TutorialProvider, and then click Build.

Comments The provider log file for TutorialProvider, which is typically stored at %RFIDDATADIR%\

Providers\TutorialProvider, contains the messages logged from the provider code along with other messages.

The process log files are rotated. For more information about the log rotation feature, see Log Files with Troubleshooting Information.

Next StepsNow that you have completed this step, perform Step 3: Test the Process, which gives you step-by-step instructions to test the TutorialProcess process.

Step 3: Test the ProcessIn this step, you use a .NET console application to send a print-tag request to the TutorialDevice simulator through the TutorialProvider provider. After the TutorialDevice simulator prints a tag, you use the RfidClientConsole utility to post the printed tags to TutorialProcess to test the process.

PrerequisitesYou must complete Step 2: Modify the Provider to Support Printing a Tag before performing this step.

102

Page 102: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Overview of This StepYou perform the following procedures in this step.

Procedure Description

To create a client application to test PrintTagCommand

This procedure has instructions to create a console application that uses the PrintTag method of the DeviceConnection class to send print-tag requests.

To run the TutorialDevice simulator This procedure has instructions to run the TutorialDevice simulator after the changes are made to support printing tags.

To copy the updated provider file and restart the TutorialProvider provider

This procedure has instructions to copy the latest TutorialProvider.dll file with the printing support code to the bin subdirectory of the provider appbase (%RFIDDATADIR%\Providers\TutorialProvider), and restart the TutorialProvider provider.

To restart the TutorialProcess process This procedure has instructions to restart the TutorialProcess process and enable the TutorialDevice device.

To print tags This procedure has instructions to run the client application that sends the Print Tag commands to the device.

To test TutorialProcess by using printed tags This procedure has instructions to use the RfidClientConsole utility to post the tags that were printed to the TutorialProcess process.

To verify that the BRE policy executed This procedure has instructions to verify that the VerifyPO BRE policy executed and the tag with an incorrect purchase order (PO) number is filtered.

To verify that MyEventHandler executed This procedure has instructions to verify that the MyEventHandler component executed and an advance shipment notice (ASN) file is generated.

To verify that the SqlServerSink event handler executed

This procedure has instructions to verify that the SqlServerSink event handler executed, and the tag with correct PO number is stored in

103

Page 103: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Procedure Description

tagevents table.

ProceduresTo create a client application to test PrintTagCommand

1. Click Start, point to Programs, point to Visual Studio, and then click Visual Studio.

2. On the menu bar, click File, point to Projects, and then click New.

3. In the list of Visual Studio Installed Templates, click Console Application.

4. Type c:\rfidtutorial for Location.

5. For Name, type PrintTagClient.6. Clear the Create directory for solution option, and then click OK.

7. In the Solution Explorer window, right-click References, and then click Add Reference.

8. Click the Browse tab.

9. Navigate to the %RFIDINSTALLDIR%\bin folder, multiple-select Microsoft.Rfid.Client.dll, Microsoft.Rfid.SpiSdk.dll, and Microsoft.Rfid.Util.dll by pressing CTRL and the DLL names, and then click OK.

10. Add the following using statements to the PrintTagClient.cs file at the beginning of the file after the existing using statements:

using System.IO.SensorServices.Rfid.Client;

using Microsoft.SensorServices.Rfid.Dspi;

using Microsoft.SensorServices.Rfid.Utilities;

using System.Xml;

11. Add the following code to the Main method to print two tags with IDs 0x01010101 and 0x01010102.

DeviceConnection cn = new DeviceConnection("TutorialDevice");

try

{

//open connection to the TutorialDevice device.

cn.Open();

ASCIIEncoding enc = new ASCIIEncoding();

//create a PrintLabel object with needed information

PrintLabel labelToPrint = new

PrintLabel(HexUtilities.HexDecode("0x01010101"), enc.GetBytes("Test Tag

104

Page 104: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Data"), null, null, null, LockTargets.Both);

//create vendor-defined parameters object

VendorDefinedParameters parameters = new

VendorDefinedParameters();

parameters.InputParameters = new VendorSpecificInformation();

//specify Item ID and the PO Number values

parameters.InputParameters["ItemID"] = "ITM1234";

parameters.InputParameters["PONumber"] = "PO123456";

cn.PrintTag("Antenna1", labelToPrint, 2, null, null,

parameters);

//print another tag with PO: PO654321

labelToPrint = new

PrintLabel(HexUtilities.HexDecode("0x01010101"), enc.GetBytes("Test Tag

Data"), null, null, null, LockTargets.Both);

parameters.InputParameters["ItemID"] = "ITM1234";

parameters.InputParameters["PONumber"] = "PO654321";

cn.PrintTag("Antenna1", labelToPrint, 2, null, null,

parameters);

}

catch (RfidException ex)

{

Console.WriteLine(ex.Message);

}

finally

{

cn.Close();

}

12. In Solution Explorer, right-click PrintTagClient, and then click Build to build the solution.

To run the TutorialDevice simulator

1. In Windows Explorer, navigate to the c:\rfidtutorial\TutorialDevicetranslator folder.

2. Double-click runTutorialDevicesimulator.cmd to run the command file, which runs the TutorialDevice simulator in a command-prompt window.

105

Page 105: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

To copy the updated provider file and restart the TutorialProvider provider

1. Click Start, and then click Run.

2. Type cmd, and then press OK.

3. In the command-prompt window, type and execute the following command to stop the provider:

rfidclientconsole.exe stopprovider TutorialProvider

4. In the command-prompt window, type and execute the following command to copy the updated provider file to the bin subdirectory of the provider appbase (%RFIDDATADIR%\Providers\TutorialProvider) directory:

rfidclientconsole.exe copyproviderfile TutorialProvider c:\rfidtutorial\

TutorialProvider\obj\debug\TutorialProvider.dll

5. In the command-prompt window, type and execute the following command to start the provider:

rfidclientconsole.exe startprovider TutorialProvider

To restart the TutorialProcess process

1. In RFID Manager, expand Processes, right-click TutorialProcess, and then click Restart. If Restart is disabled, click Start to start the process.

2. Click Devices in the left pane, and verify that the device is in the Open state. If the device is in the Disabled state, right-click TutorialDevice in the right pane, and then click Enable.

To print tags

1. In Visual Studio with the PrintTagClient solution open, press CTRL+F5 to start the PrintTagClient application.

2. Press any key in the command-prompt window to close the window.

3. In Windows Explorer, navigate to the C:\RFIDTutorial\TutorialDeviceTranslator folder, and verify that two XML files are created, one with prefix Tag_PO123456, and the other with prefix Tag_PO654321.

4. Rename the file with prefix Tag_PO123456 to TagReadEvent1.xml, and rename the file with prefix Tag_PO654321 to TagReadEvent2.xml.

To test TutorialProcess by using printed tags

1. Open Notepad. On Windows Vista computers, you may need to open Notepad with administrator privileges.

2. Copy the following command to Notepad to post the first tag-read event to TutorialProcess by using the RfidClientConsole utility:

"%RFIDINSTALLDIR%\bin\rfidclientconsole.exe" AddEventToProcessPipeline

106

Page 106: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

TutorialProcess TagReadEvent1.xml shippingreader3. Copy the following command to Notepad to post the second tag-read event to

TutorialProcess:

"%RFIDINSTALLDIR%\bin\rfidclientconsole.exe" AddEventToProcessPipeline TutorialProcess TagReadEvent2.xml shippingreader

4. On the menu bar, click File, and then click Save.

5. Navigate to the C:\RFIDTutorial\TutorialDeviceTranslator directory.

6. For File name, type test.cmd, and then click Save.

7. In Windows Explorer, navigate to the C:\RFIDTutorial\TutorialDeviceTranslator directory, and then double-click test.cmd to execute it.

To verify that the BRE policy executed

1. In Windows Explorer, navigate to the Processes\TutorialProcess subfolder in the BizTalk RFID installation directory.

2. Open the RFIDTutorial.log file in Notepad.

3. Confirm that you see an entry similar to the following entry:

13| Info|070207 11:54:08|PO numbers do not match|[BREPolicyExecutor]

Note Though you posted two tag-read events, you see only one message because only one of the tags has an incorrect PO number. The VerifyPO policy logs this message when the PO numbers do not match. The second tag you posted has an incorrect PO number. Hence, the condition in the Match rule of VerifyPO policy evaluates to true, and the actions are executed. The execution of the event handler pipeline terminates for the tag-read event without executing the event handlers (MyEventHandler, SqlServerSink) that follow the RuleEnginePolicyExecutor event handler.

To verify that MyEventHandler executed

1. In Windows Explorer, navigate to the c:\rfidtutorial\output\asn folder, and verify that only one file with prefix ASN_ is generated.

2. Open the file in Notepad, and confirm that the value of the PONumber field is PO123456.

3. Close Notepad.

To verify that the SqlServerSink event handler executed

1. Click Start, point to Programs, point to Microsoft SQL Server, and then click SQL Server Management Studio.

2. Enter the appropriate credentials, and then click Connect if you see the Connect to Server dialog box.

107

Page 107: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

3. In the Object Explorer window, expand Databases, and confirm that the RFIDsink database exists.

4. Click RFIDsink, and then click New Query on the toolbar.

Note The SqlServerSink event handler creates the RFIDsink database when the component is invoked for the first time and if the database does not exist on the computer.

5. Type and execute the following query in the query editor:

select * from tagevents where processname='TutorialProcess' order by

sinktime desc

Note The sink time is the date-time stamp at which the process receives the event. The tag time is the date-time stamp in the input XML file.

6. Confirm that you see only the tag with identifier 01010101 displayed in the result list.

Next StepsNow that you have successfully completed the tutorial, you may want to review the remaining part of the document, and modify the tutorial to test other features such as support for device discovery and management events.

CopyrightInformation in this document, including URL and other Internet Web site references, is subject to change without notice. Unless otherwise noted, the companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted in examples herein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation.

Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.

© 2009 Microsoft Corporation. All rights reserved.

108

Page 108: Tutorial: Order Fulfillmentdownload.microsoft.com/download/C/2/0/C20A979A-F… · Web viewThis tutorial shows you how to implement a Microsoft® BizTalk® RFID solution for the Order

Microsoft, BizTalk, SQL Server, Visual Studio, Windows, Windows Server, and Windows Vista are trademarks of the Microsoft group of companies.

All other trademarks are property of their respective owners.

109