Looking for PowerObjects? Don’t worry, you’re in the right place! We’ve been part of HCL for several years, and we’ve now taken the final step in our acquisition journey: moving our website to the HCL domain. Nothing else is changing – we are still fanatically focused on Microsoft Business Applications!

PowerObjects Blog 

for Microsoft Business Applications

|

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

Post Author: Joe D365 |

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:

crm2011sdkrootsamplecodecsclientsoaplogger

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");
[/sourcecode]

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

[sourcecode language="js"]
///

/// This method connects to the Organization service.
///

/// Contains server connection information. //
public void Run(ServerConnection.Configuration serverConfig)
{
try
{

// 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.
_serviceProxy.EnableProxyTypes();

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");
slos.RetrieveMultiple(query);

}

}

}

// Catch any service fault exceptions that Microsoft Dynamics CRM throws.
catch (FaultException)
{
// You can handle an exception here or pass it back to the calling method.
throw;
}
}
//

[/sourcecode]

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.

SOAPLogger

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

SOAPLogger

Navigate to the folder

crm2011sdkrootsamplecodecsclientsoaploggersoaploggerbinDebug

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"]
HTTP REQUEST
--------------------------------------------------





false





lastname
Equal

Smith



And


false
contact



0
0

false

false




--------------------------------------------------
[/sourcecode]

With the aid of an XMLHttpWebRequest, you can now utilize this XML to get the information you want from CRM.

Psssst....If this post makes your head spin, reach out to us...we can help. PowerObjects provides Microsoft Dynamics CRM Service, Support, Education, and Add-Ons.

Happy CRM’ing!

Joe CRM
By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

3 comments on “Microsoft Dynamics CRM SOAP Logger – A tool that can greatly simplify writing HTTP Requests”

    1. Thanks for sharing! If you know and like LINQ that is an excellent method of getting it translated into fetchxml. Thanks!!

PowerObjects Recommends