Introduction
Have you ever had to develop a CRM 3.0 callout? If so, you know how time consuming and inefficient the debugging process can be.
This article will show you how to debug via Visual Studio, the way it was meant to be done.
Background
I had to find an alternative to debugging a CRM 3.0 callout, given that the business logic for one of my projects started getting unmanageable and errors where getting hard to find.
Using the code
This is as simple as it gets. Essentially, I am calling a Web Service at every callout method. Before calling the Web Service, I have to serialize the complex objects that CRM uses. I used a combination of a Web Service I wrote and the callout, to ease the development and debugging. Essentially, on every event, the callout executes a Web Service method that accepts the same parameters.
- Create a Web Service. Ideally, it should be hosted as a virtual directory within the CRM 3.0 website.
- Override a method in the callout file. For the purpose of this tutorial, I will use the
PostCreate method.
- The
PostCreate method accepts the following parameters:
Microsoft.Crm.Callout.CalloutUserContext userContext
Microsoft.Crm.Callout.CalloutEntityContext entityContext
string postImageEntityXml
It is a real pain to transfer complex classes such as the userContext via a Web Service, so I decided to serialize each class using the xmlSerializer and transfer every parameter to my Web Service as a string.
Before we continue, we will need the Web Service.
The Web Service is as simple as it gets. You will need a WebMethod named PostCreate that accepts the same number of parameters. On this end, every parameter is a string.
- Deserialize the string objects back into their original type (I will show you the code later.)
- Compile the projects and add the Web Service to the callout.
- In each callout method, you will need to call the Web Serivce before the base method is called.
Download the file included in this article and you are ready to go.
Instructions for getting up and running
- Extract the zip to your system.
- Copy the webservice folder to your inetpub/wwwroot or alternatively wherever you want to host it.
- Copy the callout code into Visual Studio.
- Make the necessary configs such as setting the Web Service URL, currently set at http://localhost/CalloutWebservice/SimboliqWebservice.asmx.
- Set the Web Service URL for the CRM in the callout base.
- The actual running and debugging depends on your configuration. I develop on a Virtual PC 2007 image using Windows Server 2003 as the guest OS and Visual Studio 2003 installed on the VPC.
At anytime, please feel free to visit my blog: http://mymscrm3.blogspot.com/.