developer.com
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




See the Winners!


Linked Data Planet Conference & Expo


Developer Jobs

Be a Commerce Partner
GPS
Best Price
KVM Switches
Shop Online
KVM Switch over IP
Online Education
Phone Cards
Promos and Premiums
Car Donations
Imprinted Promotions
Promote Your Website
Calling Cards
Disney World Tickets
Computer Hardware

 


Download these IBM resources today!
e-Kit: IBM Rational Systems Development Solution
With systems teams under so much pressure to develop products faster, reduce production costs, and react to changing business needs quickly, communication and collaboration seem to get lost. Now, theres a way to improve product quality and communication.

Webcast: Asset Reuse Strategies for Success--Innovate Don't Duplicate!
Searching for, identifying, updating, using and deploying software assets can be a difficult challenge.

eKit: Rational Build Forge Express
Access valuable resources to help you increase staff productivity, compress development cycles and deliver better software, fast.

Download: IBM Data Studio v1.1
Effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life.

eKit: Rational Asset Manager
Learn how to do more with your reusable assets, learn how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse.
Developer News -
SaaS Tool Offers Custom Database Development    May 9, 2008
Microsoft’s Automated Agent: Can We Talk?    May 7, 2008
Borland Finally Sells CodeGear    May 7, 2008
Red Hat Heads For The JON 2.0    May 7, 2008
Free Tech Newsletter -

Project Management Guide: Developing a Web Site. Best Practices, Tips and Strategies. Download Exclusive eBook Now.

Integrating Your Web Site into Microsoft CRM
By Jason Mauss

Go to page: 1  2  Next  

One of the challenging things about being CTO for a small company is that you have no choice but to wear many different hats and solve a smattering of problems that you wouldn't normally deal with as CTO of a larger organization. The benefits that this brings—besides giving you more control—is the opportunity to learn about tools and technologies in greater depth than you normally would. Recently, this has been the case for me with Microsoft's CRM software.

(For those of you not using Microsoft's CRM software, you can find out all about it here.)

Our Process

At Knowledge Relay, we have been using Microsoft CRM for quite a while now (since its first release). Among other things, we use it to keep track of potential contacts (CRM Leads) that have registered with us on our Web site to download the software products we sell. Once we have a lead in the system, a sales person can make the decision when to convert the lead into a CRM Contact or CRM Customer based on other criteria (such as the lead downloading or purchasing our software). Despite achieving this customer-to-Web site tracking, we were not achieving the kind of efficiency and automation goals to make the product really simple and effective for our small sales staff to use. Sales persons were having to manually copy information out of e-mails generated by our Web site and paste that information into forms within the CRM system. Obviously, this is not a model of efficiency. So, we decided to look into the possibility of having our Web site automatically generate both leads and activities associated with those leads. Then, any sales person logging into CRM would see the items appear in their activity list.

Knowing that Microsoft CRM is an ASP.NET Web application powered by XML Web Services at the back-end, I had a hunch that either I'd need to call the appropriate Web Services from my code, or use the CRM API which, in turn, would call the appropriate Web Services. Because the latter is the approach I found used in the CRM SDK, I went with that. Now that I knew how to programmatically access the CRM, I set out to accomplish the following:

Web Site Action(s) CRM Action(s)
1. User Registration 1. CRM Lead Creation
2. CRM Activity referencing new Lead
2. User confirms e-mail/registration 1. CRM Activity referencing new Lead
3. User downloads a product 1. CRM Activity referencing new Lead
4. User requests a product demo 1. CRM Activity referencing new Lead

Developing the Solution

With my developer hat on, I went to the Class Library section of the CRM SDK Reference. The first page reads:

"This class library is a library of classes, interfaces, and enumerations that are included in the Microsoft CRM SDK. These are found in the Microsoft.Crm.Platform.Proxy.dll assembly. This library provides access to system functionality and is designed to be the foundation on which custom Microsoft CRM applications are built.

The Microsoft.Crm.Platform.Types.dll assembly contains the value types used to build XML strings for the APIs found in the proxy assembly."

Eureka! Okay, so I found the names of the two assemblies I need to reference to have access to the CRM system functionality. Now, all I need to do is go find these two assemblies. My first thought was to go look in the bin directory beneath the root of the CRM virtual directory where the CRM was installed on our server. I found many assemblies there, but neither of the two I was looking for. Strangely enough, it turns out that these two assemblies are not copied from the CRM disc as part of the installation process. To get them, you'll have to locate the wwwroot\bin directory on your installation CD. This wasn't mentioned anywhere that I could find in the CRM SDK Documentation, but the Microsoft.public.crm.developer newsgroup produced the answer without much trouble. Now that I had these two assemblies, I created a new ASP.NET project in Visual Studio.NET 2003 and referenced them from the /bin subdirectory of my project virtual directory.

In the small corner of the CRM I worked in (Leads and Activities), creating CRM objects generally followed the same pattern:

  1. Construct a string that points to the CRM platform server's virtual directory. For example, http://myservername/mscrmservices/. This directory should contain the .srf files that will be referenced in the URL property of various CRM objects. You'll see more about this in the code samples listed later.
  2. Create a Microsoft.Crm.Platform.Proxy.BizUser object and assign it the necessary credentials using a System.Net.CredentialCache object. Add credentials using the URI of the .srf files that the CRM Objects need access to.
  3. Use the BizUser.WhoAmI() method to return a Microsoft.Crm.Platform.Proxy.CUserAuth object that will contain the GUID representing the System User Id for the BizUser object. You'll need this GUID value to inject into the <owner> node of the XML text you submit to the CRMLead.Create() method.
  4. Construct an XML string that describes the CRM Object you want to create. The CRM SDK Documentation conveniently provides links to .xsd files that describe the XML schemas for the various CRM Objects.
  5. Optionally, you can capture the GUID value for the created CRMLead or CRMActivity object returned by their respective Create() methods. You may or may not need to store this GUID somewhere for later use.

The Code

The following code demonstrates the concept of creating CRMLead and CRMActivity objects. I've removed some of the code related to the custom requirements for our Web pages so the code can apply generally to any implementation.

Listing 1: Generate a CRMLead and CRMActivity upon user registration

public class ConfirmRegistration : System.Web.UI.Page
{
  private string FirstName;
   private string LastName;

   private string ServerName;
   private string VirtualDirectory;
   private string Dir;

   private string CRMLeadGUID;

   private Microsoft.Crm.Platform.Proxy.CRMLead Lead;
   private Microsoft.Crm.Platform.Proxy.CRMActivity Activity;
   private Microsoft.Crm.Platform.Proxy.CUserAuth UserAuth;
   private Microsoft.Crm.Platform.Proxy.BizUser bizUser;

   private void Page_Load(object sender, System.EventArgs e)
   {
      if(Request.QueryString["firstname"] != null)
      {
         FirstName = Request.QueryString["firstname"];
      }
      if(Request.QueryString["lastname"] != null)
      {
         LastName = Request.QueryString["lastname"];
      }

      ServerName = "MyServer";
      VirtualDirectory = "mscrmservices";
      Dir = http:// + ServerName + @"/" + VirtualDirectory + @"/";

      System.Net.CredentialCache MyCredentials =
         new System.Net.CredentialCache();

      System.Net.NetworkCredential MyNetCred =
         new System.Net.NetworkCredential(
         @"johndoe",
         @"somepassword",
         @"ourdomain.com");

      MyCredentials.Add
         (new Uri(Dir + "BizUser.srf"), "NTLM", MyNetCred);
      MyCredentials.Add
         (new Uri(Dir + "CRMLead.srf"), "NTLM", MyNetCred);
      MyCredentials.Add
         (new Uri(Dir + "CRMActivity.srf"), "NTLM", MyNetCred);

      //BizUser object
      bizUser = new Microsoft.Crm.Platform.Proxy.BizUser();
      bizUser.Credentials = MyCredentials;
      bizUser.Url = Dir + "BizUser.srf";

      //CRMLead object
      Lead = new Microsoft.Crm.Platform.Proxy.CRMLead();
      Lead.Credentials = MyCredentials;
      Lead.Url = Dir + "CRMLead.srf";

      try
      {
         UserAuth = bizUser.WhoAmI();

         String LeadXml = @"<lead>";
         LeadXml += @"<lastname>";
         LeadXml += LastName;
         LeadXml += @"</lastname>";
         LeadXml += @"<firstname>";
         LeadXml += FirstName;
         LeadXml += @"</lastname>";
         LeadXml += @"<ownerid type=""" +
            Microsoft.Crm.Platform.Types.ObjectType.otSystemUser.
                      ToString();
         LeadXml += @""">";
         LeadXml += UserAuth.UserId ;
         LeadXml += @"</ownerid>";
         LeadXml += @"</lead>";

         CRMLeadGUID = Lead.Create(UserAuth, LeadXml);
      }
      catch(System.Web.Services.Protocols.SoapException)
      {
         //error handling logic here
         throw;
      }
      catch(Exception)
      {
         //error handling logic here
         throw;
      }

      //Create the CRM Activity
      try
      {
         Activity = new CRMActivity();
         Activity.Credentials = MyCredentials;
         Activity.Url = Dir + "CRMActivity.srf";

         string ActivityXML = "<activity>";
         ActivityXML += @"<subject>Registration for";
         ActivityXML += FirstName + " " + LastName;
         ActivityXML += @"</subject>";
         ActivityXML += @"<description>";
         ActivityXML += "Here is the description";
         ActivityXML += @"</description>";
         ActivityXML += @"<activitytypecode>134";
         ActivityXML += @"</activitytypecode>";
         ActivityXML += @"<objecttypecode>4"; //4 = CRMLead
         ActivityXML += @"</objecttypecode>";
         ActivityXML += @"<objectid>" + CRMLeadGUID;
         ActivityXML += @"</objectid>";
         ActivityXML += @"<prioritycode>1";
         ActivityXML += @"</prioritycode>";
         ActivityXML += @"<scheduledstart>";
         ActivityXML += DateTime.Now.ToString("s",
            DateTimeFormatInfo.InvariantInfo);
         ActivityXML += @"<ownerid type=""" +
            Microsoft.Crm.Platform.Types.ObjectType.otSystemUser.
                      ToString();
         ActivityXML += @""">";
         ActivityXML += UserAuth.UserId + @"</ownerid>";
         ActivityXML += @"</activity>";

         //Create the "Activity Party" XML
         String ActPartyXml = @"<activityparties>";
         ActPartyXml += @"<activityparty><partyid>";
         ActPartyXml += CRMLeadGUID + @"</partyid>";
         ActPartyXml += @"<partyobjecttypecode>" +
            Microsoft.Crm.Platform.Types.ObjectType.otLead.ToString();
         ActPartyXml += @"</partyobjecttypecode>";
         ActPartyXml += @"<participationtypemask>" +
            Microsoft.Crm.Platform.Types.ACTIVITY_PARTY_TYPE.
                      ACTIVITY_PARTY_REGARDING.ToString();
         ActPartyXml += @"</participationtypemask>";
         ActPartyXml += @"</activityparty>";
         ActPartyXml += @"</activityparties>";

         //Create the Activity
         string CRMActivityGUID =
            Activity.Create(UserAuth, ActivityXML, ActPartyXML);
      }
      catch(System.Web.Services.Protocols.SoapException)
      {
         //error handling logic
         throw;
      }
      catch(Exception)
      {
         //error handling logic
         throw;
      }
   }
}

As you can very easily tell, the CRM API involves creating a lot of XML text to pass to the CRM Web Service end point.

Go to page: 1  2  Next  


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


Languages & Tools Archives

Five Trends for Application Development. Download Your Complimentary Report. Exclusive. Act Now.
Generate Complete .NET Web Apps in Minutes . Download Iron Speed Designer today.
Learn about expanding business opportunities for the reseller channel. Visit IT Channel Planet.
Developing Intelligent Communications? Visit the Avaya DevConnect Center on DevX.
Guide to Developing a Web Site. Best Practices, Tips and Strategies. Download Exclusive eBook Now.



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Microsoft Article: 7.0, Microsoft's Lucky Version?
Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Windows Server 2008
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES