Monday, December 19, 2011

Dynamics CRM 2011 : C# Code for Retrieving Organization Deployment Information

In Dynamics CRM 2011 we can use Deployment Service Retrieve Request to retrieve the Organization deployment information i.e. SSRS Server URL, SQL Server Name, Organization Name, Organization State etc... You can use the code below to retrieve the organization deployment information in C#.

 [C# Code]


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk.Deployment;
using System.Net;

namespace wod.xRM.Deployment
{
    class OrganizationDeployment
    {
        private void main()
        {
            //Instantiating deployment service client object, make sure to replace Server Name and Port Number
            DeploymentServiceClient wod_DeloymentService = Microsoft.Xrm.Sdk.Deployment.Proxy.ProxyClientHelper.CreateClient(new Uri("http://ServerName:PortNumber/XRMDeployment/2011/Deployment.svc"));

            //Setting deployment service client credentials, make sure to replace user name, password & domain
            wod_DeloymentService.ClientCredentials.Windows.ClientCredential = new NetworkCredential("UserName", "Password", "Domain");

            //Instantiating request for retrieving organization deployment information
            RetrieveRequest wod_OrgRetRequest = new RetrieveRequest();

            //Filtering request to retrieve only organization deployment information
            wod_OrgRetRequest.EntityType = DeploymentEntityType.Organization;

            wod_OrgRetRequest.InstanceTag = new EntityInstanceId();

            //wod_OrgRetRequest.InstanceTag.Name contains organization name of organization
            wod_OrgRetRequest.InstanceTag.Name = "OrgName";

            //Passing request object to service execute method
            RetrieveResponse wod_Response = (RetrieveResponse)wod_DeloymentService.Execute(wod_OrgRetRequest);

            //Getting SSRS URL address
            string wod_SSRSUrl = ((Organization)wod_Response.Entity).SrsUrl;

            //Getting SQL Server name
            string wod_SqlServerName = ((Organization)wod_Response.Entity).SqlServerName;

            //Getting Database Name
            string wod_DatabaseName = ((Organization)wod_Response.Entity).DatabaseName;

            //Getting Organization state
            OrganizationState wod_OrganizationState = ((Organization)wod_Response.Entity).State;

        }

    }
}


2 comments:

  1. When choosing the Antique Basin Taps, one should shop around before purchasing a specific item. There is always a tendency to find something that may sometimes look better or be priced in a more pleasing way than the purchased one.

    ReplyDelete
  2. This code connects to a CRM instance, retrieves specified attributes from the specified entity, and applies a condition to filter the results. Ootdtak Kot Pernah Adjust the entityName, columns, and condition variables to match your specific requirements. Remember to replace the connection string with your CRM details.

    ReplyDelete