Microsoft CRM Caller ID Lookup for TrixBox

Following on from my last post where I discussed using LINQ to dip into a Microsoft Dynamics CRM database, here is a real-world application using similar techniques. This sample is an integration between TrixBox, an open-source IP Telephony system and Microsoft Dynamics CRM. It uses LINQ to SQL to look up the Calling Line Identity (CLID) of an incoming call in the CRM database and returns the name and company of the caller, which TrixBox then presents to the user on their telephone display and records in the call detail records. The code is implemented as an HTTP Handler (.ashx) file hosted on an ASP.Net web application. You can test all this in Visual Studio 2008, but my finished solution is hosted in IIS6 on my Windows Small Business Server.
Assumptions
- This is designed to work with TrixBox CE 2.6, configured to work in the UK
- TrixBox presents CLID in the format you would dial a national number. For the number (01234) 567890 TrixBox presents the caller ID as 01234567890.
- Phone numbers are stored in canonical format within my Microsoft CRM implementation. The number above would be stored as +44 (1234) 567890 - if yours are stored differently you'll have to modify the code, but I suggest you always store your phone numbers in canonical form within Outlook and CRM.
There are really 4 parts to this project.
- Creating the solution and implementing the HTTP Handler.
- Receiving the CLID from TrixBox and getting it into Canonical Form
- Querying the CRM database using LINQ and formatting the result string
- Configuring TrixBox to use our solution.
I'm going to present the steps as separate blog posts. This is part 1.
Part 1 - Creating the Solution
- In visual Studio 2008, create a new project (not a web site). In the New Project dialog, select the Web project type and ASP.NET Web Application template. Ensure you are targetting .NET Framework 3.5 and name your solution.
- Right-click the project and select Properties..., on the Application tab, set the default namespace to TiGra.TrixBox and the assembly name to TiGra.TrixBox.CallerIDLookup. Switch to the Settings tab and add the following application settings (click the image for a full-size view if you can't make it out). Substitute values that make sense for you in LocalCountryCode and LocalAreaCode, AreaCodeDigits and NumberCodeDigits. We'll revisit the connection string later.
- Right click on the project, click Add New Item... and select Generic Handler. Name it Lookup.ashx, as shown below. A generic handler is sort of like a code-behind file without any content page. There is no predefined content to display and the output is generated by the underlying code. When you double-click the ashx file in visual studio, you will not see any HTML but will be taken directly to the C# code-behind file. This enables us to write code that looks at the URL that was used to access the handler, get the query string from it and generate the response string directly in C# code. The default template supplied with Visual Studio generates the string "Hello world".
- Let's just make it a bit easier to test things as we go along. You'll notice that Visual Studio created a Default.aspx page and this is what will be displayed when we run the project. So open up the Default.aspx page in HTML view and set the body as follows:
<body>
<form id="form1" runat="server">
<div>
<a href="Lookup.ashx?CLID=01443208678">Lookup 01443 208678</a>
</div>
</form>
</body>
- You can now run the project and it should build with no errors. You'll notice the ASP.NET Development Web Server pop up in the task bar and your Default.aspx page should open in a browser window. If you get warnings about debugging, select OK to enable debugging. When you click on the hyperlink on the default page, you'll should see the "Hello world" response.
The solution so far is attached to this post if you want a quick-start or just want to check your results.