Archive for January 7, 2016

Host a SSRS report which gets data from external Data Source – CRM on-premise

January 7, 2016 3 comments

We got a requirement to host a SSRS report in CRM, which gets data from external data source (i.e., Data Base from another SQL server).

CRM normally uses Shared Data Source when you upload any SSRS report which pulls data from CRM.

In our case we had to

  • Create a new Data Source
  • Override the CRM Shared Data Source with a new Data Source

Below are the steps.

Develop and Deploy Report in CRM

  • Design the report with Data Source connected to external Database.
  • Preview and make sure you are getting data properly.
  • Save the .rdl
  • Open CRM application
  • Create a new report and upload the .rdl
Upload SSRS Report To CRM

Upload SSRS Report To CRM

Configure the Report’s DB Connection

Now we got report in CRM and we need to point the report to Custom DataBase by following steps below

  • Connect to the SSRS server
  • Open the browser and type (http://servername/Reports) (You can also get URL from “Reporting Services Configuration Manager à Report Manager URL” tab)
Reporting Service Config Manager

Reporting Service Config Manager

  • In the Home page, click on ‘New Data Source’
Create New Data Source - 1

Create New Data Source – 1

  • Provide the Connection String and Credentials and Save
Create New Data Source - 2

Create New Data Source – 2

  • Go back to the report server home page.
  • Open the folder by name (YourCRMORG_MSCRM)
  • Go to ‘CustomeReports’ folder and select your report (Refer ‘Description’ column for Report Name)
  • Choose Manage from context menu
Create New Data Source - 3

Create New Data Source – 3

  • Choose ‘Data Sources’ tab and select newly created ‘Data Source’
Select the Data Source

Select the Data Source

  • Click on ‘Apply’
  • Close and re-run the report to get the changes.


Post XML over HTTP and capture the response – C#

January 7, 2016 1 comment

Recently we got a requirement to post the data from ‘CRM Plug-in’ to an external API and capture response.

External API was built as XML over HTTP (i.e., Its not a SOAP based and no WSDL).

In this approach we post the Request XML to a URL and in return we will get the Response.

Refer below test client with Request and Response XML’s.

Request XML

XML over HTTP - Request XML

XML over HTTP – Request XML

Response XML

XML over HTTP - Response

XML over HTTP – Response

C# Code:

  • In XML over HTTP we will post the Request XML to a URL and get the Response.
  • So the below C# function accepts URL and RequestXML as Parameters and return the Response.

public static XmlDocument SubmitXmlRequest(string apiUrl, string reqXml){
XmlDocument xmlResponse = null;
HttpWebResponse httpWebResponse = null;
Stream requestStream = null;
Stream responseStream = null;

// Create HttpWebRequest for the API URL.
var httpWebRequest = (HttpWebRequest)WebRequest.Create(apiUrl);

// Set HttpWebRequest properties
var bytes = System.Text.Encoding.ASCII.GetBytes(reqXml);
httpWebRequest.Method = “POST”;
httpWebRequest.ContentLength = bytes.Length;
httpWebRequest.ContentType = “text/xml; encoding=’utf-8′”;

//Get Stream object
requestStream = httpWebRequest.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);

// Post the Request.
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();

// If the submission is success, Status Code would be OK
if (httpWebResponse.StatusCode == HttpStatusCode.OK){
// Read response
responseStream = httpWebResponse.GetResponseStream();

if (responseStream != null){
var objXmlReader = new XmlTextReader(responseStream);

// Convert Response stream to XML
var xmldoc = new XmlDocument();
xmlResponse = xmldoc;

// Close Response
catch (WebException webException)
throw new Exception(webException.Message);
catch (Exception exception)
throw new Exception(exception.Message);
// Release connections
if (requestStream != null){

if (responseStream != null){

if (httpWebResponse != null){

// Return API Response
return xmlResponse;

Capture and Read the Response

XmlDocument response = SubmitXmlRequest(uri, xmlString);

Console.WriteLine(“Inner Text – ” + response.InnerText);

Console.WriteLine(“Inner XML – ” + response.InnerXml);


Categories: Misc Tags: ,