Image

Chapter 8 detailed how to communicate with BizTalk RFID by using BizTalk Server as the integration broker. Often, it is unnecessary to have orchestrations and ports sitting between BizTalk RFID and external applications, and the purpose of this chapter is to illustrate how to effectively implement more direct patterns of communication. This chapter uses two primary discussions to illustrate how to interact directly with BizTalk RFID throughout the enterprise. The first discussion centers on SQL Server Reporting Services, and making the BizTalk RFID SQL data accessible to external platforms and applications. The second discussion centers around calling BizTalk RFID from a SharePoint 2007 web part. By reading these discussions and working through the exercises, you will come to understand how to interact with BizTalk RFID across networks and platforms, and you should be able to apply this understanding to whatever distributed application model is needed.

Key ideas that will be introduced are the following:

  • Querying BizTalk RFID databases and making the information available in SQL Server Reporting Services
  • Building basic reports in Reporting Services
  • Calling BizTalk RFID from machines across different network configurations
  • Interacting with BizTalk RFID from a SharePoint 2007 web part
  • Deciding when to use a custom web service vs. the BizTalk RFID web service proxy assemblies

Integrating with SQL Server Reporting Services

The purpose of this section is to outline how data within BizTalk RFID’s databases can be made available to end users with SQL Server Reporting Services. There are a wide variety of metrics and data that would be useful to display in web-based reports and dashboards. This section will illustrate a subset of these by concentrating on devices and related TagRead events held in two databases: RFIDSTORE and rfidsink. The discussion will center on how to extract relevant data from these two databases and display it in web-based reports. The key ideas that will be introduced are as follows:

  • Creating several stored procedures to query devices and related tag events
  • Creating several Reporting Services reports that call the stored procedures and display the returned data

The architecture of this section is shown in Figure 9-1. It shows the databases, the two stored procedures, and the Reporting Services reports, which are rendered as ASPX pages.

Image

Figure 9-1. SQL Server report architecture

Querying the BizTalk RFID Databases

The databases that lie beneath BizTalk RFID are relatively simple. Much of the information that defines devices and events is stored in XML strings within ntext fields. There are a number of preexisting stored procedures that provide certain data. In many cases, however, custom queries will need to be written to access the desired information. The discussions in this section will outline how to access information in the XML and how to create certain metrics across multiple databases.

Querying Devices and Related Events

The first stored procedure that will be outlined (shown in Listing 9-1) concerns retrieving all tag events related to devices. This procedure will demonstrate how to work with the device information stored in XML and retrieve data from both databases. It includes a single input parameter, vchDeviceStatus, which will determine what devices to return based on their connection status. You begin the procedure by placing all of the device information into a temporary table, converting the runtimeDeviceInfo field from ntext to XML in the process. This allows for easy access to the connection status information in the next portion of the procedure, which returns the information from the two tables.

ImageNote The stored procedure shown in Listing 9-1 would be deployed on a custom database used primarily for reports in Reporting Services. It is not intended to be placed on any of the preexisting BizTalk RFID databases.

Listing 9-1. The Report Devices and Events Stored Procedure

-- =============================================
-- Sample Implementation:
-- EXEC spReportDevicesAndEvents 'ConnectionEstablished'
-- =============================================
CREATE PROCEDURE [dbo].[spReportDevicesAndEvents]
(
 @vchDeviceStatus varchar(50) = 'All'
)
AS
BEGIN
 -- loading into a temporary table allows for easy conversion
 -- from ntext to XML
 SELECT name, CAST(runtimeDeviceInfo as XML) As runtimeDeviceInfo
 INTO #temporary
 FROM RFIDSTORE.dbo.devices

 -- join the two databases together to get information
 SELECT d.name, t.sinktime
 FROM #temporary d
 LEFT JOIN rfidsink.dbo.TagEvents t ON t.DeviceName
 COLLATE DATABASE_DEFAULT = d.name COLLATE DATABASE_DEFAULT
 WHERE (@vchDeviceStatus = 'All' OR
  CAST(d.runtimeDeviceInfo.query(
   'declare namespace
 s="http://schemas.datacontract.org/2004/07/MS.Internal.Rfid.Service.Devices";
data(//s:m_connectionStatus)') As varchar(50)) = @vchDeviceStatus
  )
END

There are two important items to point out in this query: collation and the XML query. First, the RFIDSTORE and the rfidsink databases are, by default, created with different collation. Trying to join one table to another in a query will result in the error that states the following:


Cannot resolve the collation conflict between "SQL_Latin1_General_CP437_BIN"
and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.

Adding the COLLATE DATABASE DEFAULT directive will force both tables to temporarily adhere to the default collation of SQL Server, and will allow the query to execute without error.

Second, querying the XML to get the connection status can be a little challenging. As stated before, the runtimeDeviceInfo field is an XML string stored in an ntext field. Once the field is converted to an XML data type, the node that contains the connection status can be queried using XQuery. However, an extra level of complexity is added due to the namespace stored in the root element of the document (see Figure 9-2). This namespace must be declared in the XQuery statement to successfully retrieve the value of the connection status node; without the namespace declaration, no value will be returned.

Image

Figure 9-2. Example of the runtimeDeviceInfo XML

Querying Count Events by Device

The second stored procedure is very simple. There is nothing that needs to be pointed out about the procedure, beyond the code listing shown in Listing 9-2. The purpose of including this procedure in the discussion is to illustrate how a chart can be used in Reporting Services to display BizTalk RFID metrics in a visually appealing way.

Listing 9-2. spCountEventsByDevice

-- =============================================
-- Sample Implementation:
-- EXEC spCountEventsByDevice
-- =============================================
CREATE PROCEDURE [dbo].[spCountEventsByDevice]
AS
BEGIN
 SELECT DISTINCT DeviceName
  ,(SELECT COUNT(*)
    FROM rfidsink.dbo.TagEvents child
    WHERE child.DeviceName = parent.DeviceName) As EventCount
FROM rfidsink.dbo.TagEvents parent
END

Writing the SQL Server Reporting Services Reports

With the stored procedures defined, the accompanying web reports can now be created in Reporting Services. This section will walk through how to build a report for each of the procedures outlined in the previous section. Before looking at creating the reports, Exercise 9-1 will introduce you to creating a Reporting Services project, in case you’re unfamiliar. After the project has been created, you will add two individual reports to it.

Exercise 9-1. Creating a SQL Server Reporting Services Project

Creating the Report for Devices and Related Events

The first report interacts with the stored procedure defined in Listing 9-1. It will allow a user to determine what devices to query (those that are connected, disconnected, or both) through the use of a drop-down box, and will display a report similar to that shown in Figure 9-4. To show you how to get to this result, Exercise 9-2 will walk through connecting a new dynamic report with the stored procedure.

Image

Figure 9-4. The Dynamic Devices and Events report with the user-controlled drop-down

Exercise 9-2. Building the Dynamic Devices and Events Report

Creating the Count Events by Device Report

The goal of the Count Events by Device report is to show how to create a chart report that is tied to BizTalk RFID metrics. The steps to creating a chart are slightly different than they are with a standard report, and therefore need some additional explanation. It is also important to highlight that some information from BizTalk RFID is of greater value in a well-structured, visually appealing chart than it would be in a text-based presentation. The chart that will be created in Exercise 9-3 is shown in Figure 9-10.

Image

Figure 9-10. The Count Events by Device pie chart

Exercise 9-3. Building the Count Events by Device Pie Chart

Connecting to BizTalk RFID via Remote Machines

The discussion will now turn to an important digression: introducing how to connect from a remote machine to the BizTalk RFID server. There are a variety of methods of interaction with BizTalk RFID, the most common of which is through the use of the proxy web service assemblies. These assemblies can be referenced on any machine, regardless of where BizTalk RFID is hosted. To be able to connect to the RFID server, the user under which the code is executing must be a member of the RFID_USER group on the host machine. If a user without permissions tries to connect to BizTalk RFID, an error stating “The server has rejected the credentials” will be returned to the application, and an error similar to that shown in Figure 9-14 will be logged to the Windows Event Viewer on the host machine.

Image

Figure 9-14. An error indicating that the calling user is not a member of the RFID_USER group

ImageNote The default port that the BizTalk RFID web services operate under is 7891.

The solution to this issue is fairly simple when connecting to a host machine that is in the same domain (or a trusted domain) of the calling machine. All that must be done is to add the user to the RFID_USER group. There should be no issues in adding the user, as the user will be accessible to be added either via the local computer groups or Active Directory (see Figure 9-15).

Image

Figure 9-15. The RFID_USER group

For incidents where NTLM (NT LAN Manager) authentication needs to occur across machines on different domains, the easiest approach is to use the “Manage your Network Password” options on the user account that the process is running under. On Windows XP, you can do this by opening Control Panel and clicking User Accounts. A number of options are available for each user, one of which is to manage the network password. Set the password information for the domain/machine as appropriate.

However, if you’re trying to connect from a machine that is not on the network, these approaches won’t be an option. In some cases, impersonation could be used, but even that has limitations (such as over the Web). In cases where a distributed communication model is necessary and credentials can’t be standardized (such as across the Internet), it would be most appropriate to create a web service that brokers the communications between the BizTalk RFID host and the calling machines. Calling machines will be able to call the web service, and the only user that will need to be added to the RFID_USER group is the user under which the web service executes (e.g., ASP.NET).

The BizTalk proxy web services are extremely helpful, but are not appropriate for all situations. The next section covers connecting to BizTalk RFID using SharePoint 2007. It will illustrate how to connect using the web proxies, and, separately, how to use a web service to broker the calls. Once you understand both approaches, you will be able to determine when and how to use them in your own implementations.

ImageNote The BizTalk RFID proxy web service classes should only be used by applications that are on the same network as the BizTalk RFID service. Applications outside of the network should depend on a custom web service to expose the needed methods.

Integrating with SharePoint 2007

This section will give an overview of several paths to integrating BizTalk RFID–related information with SharePoint 2007. Administration of BizTalk RFID is generally done through the RFID Manager, which is fine for development, but is limiting in a production environment. Frequently, users who should not have access to the production BizTalk RFID server (where the RFID Manager and other client tools are installed) need the ability to view data and perform administrative tasks. There are several ways to solve this, but the most appropriate is to implement an enterprise-wide solution, which would allow controlled access within a known environment. SharePoint 2007 is being widely adopted and implemented as the enterprise portal of choice, enabling extensive permission handling, interoperability with existing applications and code bases, and rapid web-based application development and deployment, and therefore will be the focus of this section.

The exercises in this section are intended to aid you in understanding how BizTalk RFID can be made available to the wider organization. The text will look at how to interact with BizTalk RFID through a SharePoint web part. The rendered web part is very simple, displaying a drop-down list of available devices, but you should be able to extend the ideas behind this to enable any type of administration needed in a web part. Anything that can be handled through the BizTalk RFID web proxy classes can be made available to users in external applications.

As outlined in the earlier discussion about connecting to BizTalk RFID from remote machines, there are two possible approaches to take. The first is to connect directly to BizTalk RFID using the web service proxy assemblies. The second is to use an intermediary web service to enable the call. The BizTalk RFID web service proxy assemblies are useful when the calling system is on the same network as BizTalk RFID. These assemblies can be added to a project and called with little effort. The architecture and components related to this approach are illustrated in Figure 9-16, and will be implemented later in Exercise 9-5.

Image

Figure 9-16. SharePoint component architecture using BizTalk RFID proxy assemblies

In many cases, the calling application will not be on the same network as the BizTalk RFID service, or will not have permissions to interact directly with BizTalk RFID using the proxy assemblies. In cases such as this, it is more appropriate to use a custom web service to broker external requests (calling parties not on the network) from the internal systems (BizTalk RFID). The web service would reference the proxy assemblies and call the methods, exposing public web methods to the external clients. All permissions are handled by IIS, and a decoupled, easily maintainable solution is created. The architecture and components related to this approach are illustrated in Figure 9-17, and will be implemented later in Exercise 9-6.

Image

Figure 9-17. SharePoint component architecture using a custom web service

Developing the SharePoint Web Part Foundation

Before moving on to the details of how to implement the different approaches to calling BizTalk RFID, it will be useful to first put together the foundation by building the SharePoint web part. If you’re unfamiliar with SharePoint web part development, you’ll benefit greatly by looking at the steps needed to add a custom web part to a SharePoint site. Once the foundation of the web part has been laid out, it will be extended first to call the BizTalk RFID web service proxy assemblies directly, and second to call an intermediary web service.

Exercise 9-4 details the steps needed to create and deploy a web part to SharePoint 2007. This will form the base for the remaining SharePoint-related exercises in the section. The full code for the web part framework is shown in Listing 9-3. This code sets up a single configurable field to define the BizTalk RFID host IP, and creates all of the necessary methods to render data to the user interface.

Listing 9-3. SharePoint BizTalk RFID Administration Web Part

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint.WebPartPages;

namespace SharePointBizTalkRFIDWebParts
{
 public class AdministrativeFunctions :
 Microsoft.SharePoint.WebPartPages.WebPart
 {
  // default value of the variable. Overridden by configurable field.
  private String rfidProxyHost = "192.168.0.175";
  // user-configurable field declaration
  [WebBrowsable(true), Personalizable(PersonalizationScope.Shared),
  WebDisplayName("RFID Proxy Host Server"),
  SPWebCategoryName("Administrative Function Settings")]

  public String RFIDProxyHost
  {
   get { return rfidProxyHost; }
   set { rfidProxyHost = value; }
  }

  protected override void CreateChildControls()
  {
   base.CreateChildControls();

   // label to give name
   Label tableDescription = new Label();
   tableDescription.Text = "Devices Available: ";

   // add label to control for rendering
   this.Controls.Add(tableDescription);
  }

  protected override void RenderWebPart(HtmlTextWriter output)
  {
   base.RenderWebPart(output);
  }
 }
}

Exercise 9-4. Building and Deploying a Web Part

Extending the Web Part to Use the RFID Web Service Proxies

Now that the web part has been defined, it can be extended to call BizTalk RFID using the web service proxy assemblies. These assemblies can be added to the Visual Studio project and the methods can be called directly from the web part. The assemblies that need to be added are shown in Exercise 9-5. The code shown in Listing 9-4 contains a method that can be added to the web part code to return a list of devices that are available from BizTalk RFID.

Listing 9-4. The GetDevices Method

// returns a list of device names in a sorted ArrayList
public ArrayList GetDevices()
{
 ArrayList results = new ArrayList();
 DeviceManagerProxy proxy = new DeviceManagerProxy(rfidProxyHost);
 DeviceDefinition[] devices = proxy.GetAllDevices();

 for(int x=0; x<devices.Length; x++)
 {
  results.Add(devices[x].Name);
 }

 results.Sort();
 return results;
}

The GetDevices method can be called from CreateChildControls in the web part, and the results can be rendered in a drop-down. The code for this is shown in Listing 9-5.

Listing 9-5. The CreateChildControls Code to Call GetDevices

protected override void CreateChildControls()
{
 base.CreateChildControls();

 Label tableDescription = new Label();
 tableDescription.Text = "Devices Available: ";

 DropDownList deviceDropDown = new DropDownList();

 deviceDropDown.DataSource = GetDevices();
 deviceDropDown.DataBind();

 this.Controls.Add(tableDescription);
 this.Controls.Add(deviceDropDown);
}

Exercise 9-5. Using the BizTalk RFID Proxy Assemblies in a Web Part

Extending the Web Part to Use a Custom Web Service

With the assumption that the BizTalk RFID web service proxy classes are not an option for interacting with the host machine, the discussion will now turn to implementing an intermediary web service that will broker the calls. This allows all permissions to be handled by IIS, and the functionality of the RFID API to be available across distributed clients. This section will demonstrate how to create the web service and call the web service from the SharePoint web part created earlier in this chapter.

The code shown in Listing 9-6 is the complete code for the web service. It takes little more than referencing the BizTalk RFID assemblies and adding a web method to allow for the functionality needed. The steps in Exercise 9-6 outline how to call the web service from the SharePoint web part, instead of using the web service proxy assemblies.

Listing 9-6. The Intermediary Web Service

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections;
using Microsoft.SensorServices.Rfid.Management;
using Microsoft.SensorServices.Rfid.Runtime;
using System.IO.SensorServices.Rfid.Client;
using Microsoft.SensorServices.Rfid;
using Microsoft.SensorServices.Rfid.Design;
using Microsoft.SensorServices.Rfid.Dspi;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
 public Service () {}

 [WebMethod]
 public ArrayList GetDevices()
 {
  ArrayList results = new ArrayList();
  DeviceManagerProxy proxy = new DeviceManagerProxy("localhost");
  DeviceDefinition[] devices = proxy.GetAllDevices();

  for(int x=0; x<devices.Length; x++)
  {
   results.Add(devices[x].Name);
  }

  results.Sort();
  return results;
 }
}

Exercise 9-6. Calling a Custom RFID Web Service from the Web Part

Conclusion

There are numerous ways to integrate systems throughout the enterprise and across networks. The intent of this chapter was to introduce two core approaches that would illustrate many of these methods. While SharePoint 2007 is a popular portal, and will likely be used in a number of BizTalk RFID implementations, we hope that you’ll be able to extend the concepts to apply to your own situations. The most important concept to leave this chapter with is how to connect from remote systems to access the data needed. Some data is most easily accessed directly from SQL Server (especially in read-only types of implementations). Other information is better accessed via the BizTalk RFID API using the proxy assemblies (especially when enabling administrative read-write capabilities).

Remember that the initially obvious approach to integration is not always the most appropriate. Take time to think through the architecture and requirements, and make sure that the implementation being built today matches the short- and long-term needs of the solution at hand.

CASE STUDY: MONITORING INVENTORY THROUGH SHAREPOINT SERVER

Industry: Retail.

Overview: For one large retail music vendor, it was becoming apparent that CDs were being lost for a variety of reasons, including lost shipments from the warehouse, poor inventory management, and theft. By tagging each CD case with an RFID tag, inventory could be more closely monitored. The retailer then wanted to let specific retail outlets monitor their own merchandise. The data was being captured by BizTalk RFID and stored on a centralized server. The retailer moved to implement SharePoint 2007 to quickly deploy a solution that allowed different retailers access to view information that specifically related to them. This information included times of shipment, total number of items shipped, current expected inventory, and other appropriate metrics.

Results: The organization as a whole increased visibility into the entire inventory control process, and was better able to monitor what occurred during shipments. The different retail outlets were given far more insight into their expected inventory, and were better able to control costs around inventory management.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset