Creative Minds

Because we all have one

.NET Integration Series: Create a OBA to share your LOB data using Visual Studio 2k8 Office Tools and ADO.NET Data Services

When developing web applications, most of the time the business data remains only accessible via the web browser. Some times that is not enough. Not everyone uses the browser as the main tool for their work. Many use office tools, for instance, to write business contracts in Word or keep track of budgets and stocks on Excel.

When this happens, it is fundamental that these applications can connect with a central repository where all the business data is located and consume it without leaving the application.

Creating a Office Business Application (OBA) to share your Line of Business (LOB) Data is extremely easy, and can enhance the user experience greatly.

For this demo let’s assume that we work in a large online shopping company. In the shopping portal, on each product page, the user was the possibility to email, thru a easy web form, the customer support to enquiry about the product.

This feature is heavily use by the customers. What happens is that, when a support team member receives the email, he was to access the intranet portal to gain more details about the product to more accurate answer the customer.

After a brief talk with the support team manager, we realized that the main working tool they use is Outlook, since all enquiries are send via email by the web form.

“We can improve this process!” we think out loud. “Since the email subject identifies the product ID, why not have Outlook show the product details?”, we ask. “That would be just great!” says the manager. (I’m getting a little bit esquizofrenic talking to myself…)

NOTE: This is demo code. No validation and performance was took in account.

So, what we need is to, when the customer support team member selects an email, our Outlook add-in will look the subject for the product ID, and if found, show a new region on the email message window detailing the product.

Since the LOB data is on a central repository, we need to develop first a service to fetch the data. For this task we will use the ADO.NET Data Services.

Simply put, ADO.NET Data Services let us expose our data as a RSS feed.

In Visual Studio 2008 create a new web application, and add a new Linq to Sql Class item:

Lets drag some tables from the store database to the L2S designer. We will end up with the following model:

Now lets add a new ADO.NET Data Service:

After adding our Data Service, we need to let him know which data context to use, in this case, our L2S OnlineStore.dbml. What we need to do is in the generic DataService class tell it to use the OnlineStoreDataContext, and next tell which entities we can use, in our case all (“*”) and set the usage rights, that in our case, we only need to read the data:

To test our service, just browse it:

As you can see we have easily exposed our data thru a service.

With this done, is now time to build our client, in our case, a Outlook add-in.

Lets start by creating a new Outlook add-in project:

The next step is to create the actual region that will be shown when we select a email message in Outlook. So, lets add a new Outlook Form Region:

The Outlook Form Region wizard starts. The first step lets us design a new region or import a Outlook form storage file. We will choose the first one: Design a new form region.

The next step let us choose which type of region do we want to create. To simplify the process of the support team, we will choose the “Adjoining”:

Next we are asked for the name of our region, and when should this region be shown. Since we only want this while we are reading the email, choose only “Reading Pane”:

Finally we just need to define which message class will trigger the display. In our case the “Mail Message”, which should be selected by default.

Clicking finish will make the designer show our new email region, which is a empty windows form user control.

Finally we will start coding something :)

Since we only want to show our region when the subject has a specific pattern, we will need to code this logic. So, hit F7 to go to the code-behind of our region.

Let’s first create a regEx to match our subject pattern:

Next, in the “ProductDetailsRegionFactory_FormRegionInitializing” event, we will add the code logic to see if we show or not our region:

Since we have some logic implemented we can test it to see if it works. Just select the Outlook add-in project and hit F5. The Outlook window will be showed to you. If any email message subject matches our pattern, our region will be shown:

Nice..it works! (has if we had any doubts… :P )

Now that we have coded when the region is shown, we need to add the service reference so we can display the product details.

Just right-click on the OBAOutlookAddIn project, select “Add Service Reference…”, click “Discover”, rename the namespace to “AcmeServices” and click “OK”.

In the designer of our region let’s add three labels:

Next, on the code behind, in the “ProductDetailsRegion_FormRegionShowing” event, lets add the product details logic:

That’s it! If we run our project we will have our product details showed to us:

 

Has we can see, sharing LOB data with Microsoft Office is easy and fast, allowing you to create full integrated applications using the latest Microsoft technology.

Download Code

 Digg  Facebook  StumbleUpon  Technorati  Deli.cio.us 

Tagged as , , , , , , + Categorized as Development

Leave a Reply