Microsoft Dynamics CRM SOAP Logger – A tool that can greatly simplify writing HTTP Requests

JoeCRM says, "Microsoft Dynamics CRM SOAP Logger makes me happy!"

Writing a fetch can be time consuming and aggravating, even if you know what you’re doing.  The common niceties that developers have come to enjoy, like IntelliSense for instance, don’t exist.  Writing queries becomes trial and error and can greatly increase the time it takes to finish your project.

Fortunately, the CRM 2011 SDK comes with an application that allows you to write your queries in Visual Studio and capture the format of the fetch.  This application, SOAP Logger, lives in a less than obvious location:


Note that there are three regions in the code:

Microsoft Dynamics CRM SOAP logger

(If you don’t see this view, you can use Ctrl+M Ctrl+O to contract your code)

The only area we’ll need to modify is the region CodeToCapture.  Here you’ll be able to write a query expression and the application will log the request.  For now, let’s focus on the query and we’ll come back to what is captured later.

Inside the CodeToCapture region, let’s do a simple query to retrieve all Contacts whose last name is “Smith”.  In order to do this, we’d write a query like the following:

[sourcecode language="js"]var query = new QueryExpression("contact");
query.Criteria.AddCondition("lastname", ConditionOperator.Equal, "Smith");

For context, this is where the query is placed in the method:

[sourcecode language="js"]
/// <summary>
/// This method connects to the Organization service.
/// </summary>
/// <param name="serverConfig">Contains server connection information.</param>
public void Run(ServerConnection.Configuration serverConfig)

// Connect to the Organization service.
// The using statement assures that the service proxy will be properly disposed.
using (_serviceProxy = ServerConnection.GetOrganizationProxy(serverConfig))
// This statement is required to enable early-bound type support.

IOrganizationService service = (IOrganizationService)_serviceProxy;

using (StreamWriter output = new StreamWriter("output.txt"))

SoapLoggerOrganizationService slos = new SoapLoggerOrganizationService(serverConfig.OrganizationUri, service, output);

//Add the code you want to test here:
// You must use the SoapLoggerOrganizationService 'slos' proxy rather than the IOrganizationService proxy you would normally use.
var query = new QueryExpression("contact");
query.Criteria.AddCondition("lastname", ConditionOperator.Equal, "Smith");




// Catch any service fault exceptions that Microsoft Dynamics CRM throws.
catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>)
// You can handle an exception here or pass it back to the calling method.


Now, we just run the application from Visual Studio.  A large amount of data has been redacted here, but the values you provide should be somewhat obvious for you.


After choosing your organization, the program will end and you can press the Enter key to exit.


Navigate to the folder


You should see a file called output.txt, the content of which should include the HTTP Request and Response.  The request for our query looks like the following:

[sourcecode language="plain"]
<s:Envelope >reach out to us...we can help. PowerObjects provides Microsoft Dynamics CRM Service, Support, Education, and Add-Ons.

Happy CRM’ing!