Using Web Service as a Data Source in Sql Server Reporting Services


Suppose this is a simple web method inside a web service in ASP.NET.

[WebMethod]

public string HelloWorld(String FirstName, String LastName) {

return “Hello “ + FirstName+ ” “ + LastName ;

}

Now we would to add the above as a xml data source in out Report.

For this we need to do the following

  • Create a new Report
  • Select <New DataSet..>
  • For Type (inside General Tab) select XML as DataSource type.
  • Inside connection string give the path to the web service.
  • i.e. http://localhost:2584/WebSites/Service.asmx
  • Define query for the data source in the following manner

<Query>

<Method Namespace=http://tempuri.org/ Name=HelloWorld>

</Method>

<SoapAction>http://tempuri.org/HelloWorld</SoapAction>

</Query>

 

We can create report parameters for FirstName and LastName parameters of the method.

Or we want to define default values for these parameters define the query as following

 

<Query>

<Method Namespace=http://tempuri.org/ Name=HelloWorld>

<Parameters>

<Parameter Name=FirstName>

<DefaultValue>Nishant</DefaultValue>

</Parameter>

<Parameter Name=LastName>

<DefaultValue>Rana</DefaultValue>

</Parameter>

</Parameters>

</Method>

<SoapAction>http://tempuri.org/HelloWorld</SoapAction>

</Query>

 

Bye..

Developing Custom Workflow Activities in CRM 4.0


We can create our own custom workflow activities and register it so that they can appear inside workflow editor in CRM.

For creating custom workflow activity we need to first select Workflow Activity Library project template inside Visual Studio with framework version 3.0.

Class within the activity library should derive from Activity class or could derive from SequenceActivity class.

Let’s create a simple custom workflow class

For this add a class inside your Workflow Activity Library project.

Add reference to Microsoft.Crm.Sdk and Microsoft.Crm.SdkTypeProxy dlls.

using System.Workflow.ComponentModel;

using System.Workflow.Runtime;

using System.Workflow.Activities;

using System.Workflow.Activities.Rules;

using Microsoft.Crm.Workflow; 

namespace MyWorkflow

{

[CrmWorkflowActivity(“My First Custom Activity”,“My Custom Activity Group”)]

public class MySimpleCustomActivity :Activity

{

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

{

// custom logic

return ActivityExecutionStatus.Closed;

}

}

}

 

CrmWorkflowActivity Attribute – To allow our activity to be visible inside the workflow editor. First parameter is the name of the workflow activity and second parameter is the group name, which could be used for grouping similar kind of workflow activities.

We can create custom activity by inheriting SequenceActivity class, which would be a composite activity wherein we can add other activity available with windows workflow foundation like

IfElseActivity,IfElseBranchActivity,PolicyActivity,DelayActivity etc.

For this right click on your project and add a new Activity in your project.

Open it in design mode. We can see the option of (Drop Activities Here)

Therein we can drop the built in activities found in windows workflow foundation for building our custom logic. Here we need not override the Execute method like we did in earlier case. The sequence activity will execute the activities that we would have dragged and dropped for writing our logic.

[CrmWorkflowActivity(“My First Custom Activity”, “My Custom Activity Group”)]

 

public partial class Activity3: SequenceActivity

{

public Activity3()

{

InitializeComponent();

}

}

 

While building our workflow we could also define input and output parameter that will appear inside Set Properties dialog box while defining Step and Dyanmic Value editor inside Form Assistant respectively.

To define input and output parameters we need to make use of dependency property and CrmInput and CrmOutput Attribute.

[CrmInput(“Name”)]

[CrmDefault(“Nishant”)]

public string InputProperty

{

get { return (string)GetValue(InputPropertyProperty); }

set { SetValue(InputPropertyProperty, value); }

}

 

public static readonly DependencyProperty InputPropertyProperty =

DependencyProperty.Register(“InputProperty”, typeof(string), typeof(nameOfActivityClass));

 

Similary we can define output parameter only difference would that we will use [CrmOutput(“FullName”)] attribute.

CrmDefault attribute is optional one.

 

The same property could act as both input as well as output parameter.

 

[CrmInput(“FName”)]

[CrmOutput(“LName”)]

[CrmDefault(“Nishant”)]

public string MyProperty

{

. . . .

 

 

The following data type are supported that could be used as input/output parameter

 

String, CrmNumber, CrmDecimal, CrmFloat, CrmMoney , CrmDateTime, CrmMoney, CrmBoolean, Status, Picklist, Lookup.

 

For lookup we can specify the parameter as following

 

 

[CrmInput(“Territory”)]

[CrmReferenceTarget(“territory”)]

public Lookup TerritoryProperty

{

get { return (Lookup)GetValue(TerritoryPropertyProperty); }

set { SetValue(TerritoryPropertyProperty, value); }

}

 

public static readonly DependencyProperty TerritoryPropertyProperty =

DependencyProperty.Register(“TerritoryProperty”, typeof(Lookup), typeof(Activity1));

For picklist

[CrmInput(“AddressType”)]

[CrmAttributeTarget(“account”,“address1_addresstypecode”)]

 

public Picklist AddressTypeProperty

{

get { return (Picklist)GetValue(AddressTypePropertyProperty); }

set { SetValue(AddressTypePropertyProperty, value); }

}

 

public static readonly DependencyProperty AddressTypePropertyProperty =

DependencyProperty.Register(“AddressTypeProperty”, typeof(Picklist), typeof(Activity1));

 

Using CrmService and MetadataService within custom workflow activity through workflow context

We can register our own custom services with workflow runtime. The built in services provided by Windows workflow foundation are following

PersistenceService, QueuingService, SchedulerService, TransactionService, TrackingService etc.

Similary MS CRM has used it to register ContextService with the runtime. It provides the current context information for the workflow instance which is executing at that time.

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

{

IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));

IWorkflowContext context = contextService.Context; 

ICrmService crmService = context.CreateCrmService(); 

IMetadataService crmMetadataService = context.CreateMetadataService(); 

 

return ActivityExecutionStatus.Closed;

 

}

For registering the custom activity we need to use Plugin registration tool.

Open Plugin Registration Tool

Select Register New Assembly

Select you assmebly ( It should be signed assembly and no need to specify anything else within the plugin registration tool).

Click on Register Selected Plugin

Restart Crm Asynchronous Service

Bye..

Unable to find a version of the runtime to run the application


I was facing the problem while trying to run one of my windows application created in Visual studio 2005 using .NET framework 2.0.

Few days back the application was running fine and today it on trying to run it i was getting the error.

The way it solved for me was to again open the project in solution explorer in visual studio and rebuilding it.

Bye,..

Understanding DynamicEntity in Microsoft Dynamic CRM.


We can use the DynamicEntity to develop against entities and attributes that are not defined at design time.

Or to write code that must work on entities/attributes that would be created/added after the code is deployed.

Let’s take an example of how to use DynamicEntity for creating and updating records using Dlls(Microsoft.crm.sdk and Microsoft.crm.sdktypeproxy) and also by using web service..

Setting up CrmService

CrmAuthenticationToken myToken = new CrmAuthenticationToken();

myToken.OrganizationName = “orgname”;

myToken.AuthenticationType = 0;

CrmService myService = new CrmService();

myService.Credentials = System.Net.CredentialCache.DefaultCredentials;

myService.Url = http://servername:port/MSCrmServices/2007/CrmService.asmx&#8221;;

myService.CrmAuthenticationTokenValue = myToken;


Creating a contact record using DynamicEntity inside Microsoft.Crm.Sdk.dll

// Creating an instance of DynamicEntity Class

// Specifying the schema name of Contact entity whose record we are

// going to create

DynamicEntity myDE = new DynamicEntity();

myDE.Name = “contact”;

// Creating an instance of StringProperty to specify firstname attribute value

StringProperty myFirstName = new StringProperty();

myFirstName.Name = “firstname”;

myFirstName.Value = “Nishant”;

// Adding it to DynamicEntity’s properties

myDE.Properties.Add(myFirstName);

// Creating an instance of StringProperty to specify lastname attribute value

StringProperty myLastName = new StringProperty();

myLastName.Name = “lastname”;

myLastName.Value = “Rana”;

myDE.Properties.Add(myLastName);

try

{

contactGuid= myService.Create(myDE);

}

catch (SoapException ex)

{

MessageBox.Show(ex.Detail.InnerXml);

}


Updating a record using DynamicEntity


DynamicEntity myDEUpdate = new DynamicEntity();

myDEUpdate.Name = “contact”;

// Create a KeyProperty to hold the guid of the record to be updated

KeyProperty myContactGuid = new KeyProperty();

myContactGuid.Name = “contactid”;

Key myContactKey=new Key();

myContactKey.Value=contactGuid;

myContactGuid.Value = myContactKey;

myDEUpdate.Properties.Add(myContactGuid);

// Create a StringProperty with the new updated value

StringProperty myFirstNameU = new StringProperty();

myFirstNameU.Name = “firstname”;

myFirstNameU.Value = “Nishu”;

myDEUpdate.Properties.Add(myFirstNameU);

try

{

myService.Update(myDEUpdate);

}

catch (SoapException ex)

{

MessageBox.Show(ex.Detail.InnerXml);

}

The above code while using DynamicEntity class inside the WebService.

Create

DynamicEntity myDE = new DynamicEntity();

myDE.Name = “contact”;

StringProperty myFirstName = new StringProperty();

myFirstName.Name = “firstname”;

myFirstName.Value = “Mickey”;

StringProperty myLastName = new StringProperty();

myLastName.Name = “lastname”;

myLastName.Value = “Mouse”;

// myDE.Properties.Add(myLastName);

myDE.Properties = new Property[] {myFirstName, myLastName };

Guid mycontactGuid = new Guid();

try

{

mycontactGuid= myService.Create(myDE);

}

catch (SoapException ex)

{

MessageBox.Show(ex.Detail.InnerXml);

}

UPDATE

DynamicEntity myDEUpdate = new DynamicEntity();

myDEUpdate.Name = “contact”;

KeyProperty myContactGuid = new KeyProperty();

myContactGuid.Name = “contactid”;

Key myContactKey = new Key();

myContactKey.Value = mycontactGuid;

myContactGuid.Value = myContactKey;

StringProperty myFirstNameU = new StringProperty();

myFirstNameU.Name = “firstname”;

myFirstNameU.Value = “Donald”;

myDEUpdate.Properties = new Property[] { myContactGuid, myFirstNameU };

try

{

myService.Update(myDEUpdate);

}

catch (SoapException ex)

{

MessageBox.Show(ex.Detail.InnerXml);

}

In the same manner we can use Retrieve,Delete method with DynamicEntity.

There are certain Request classes that have a property ReturnDynamicEntities which indicates whether to return the result as a collection of instances of the that Entity or the DynamicEntity class.

Bye..

 

Understanding and Using CrmDiscoveryService in CRM 4.0


This is a new web service introduced in CRM 4.0.

Using it we can get organization information as well as organization’s CrmService and MetadataService web service’s url end points.

The web service has three different end point based on authentication mode

Active Directory

http://servername:port/mscrmservices/2007/AD/CrmDiscoveryService.asmx

IFD –

http://servername:port/mscrmservices/2007/IFD/CrmDiscoveryService.asmx

Online –

https://dev.crm.dynamics.com/mscrmservices/2007/passport/CrmDiscoveryService.asmx

In case of IFD and Online, we neet to obtain CrmTicket information that is required.

In case of Online we also need policy information and Passport ticket.

These information provided by CrmDiscoveryService is used for configuring CrmAuthenticationToken and CrmService instances.

For on-premise

If we already know organization name and webservice Url end points that it is not necessary for us to use CrmDiscoveryService.

This is how we can use the CrmDiscoveryService for configuring our Crm Service

CrmDiscoveryService myDiscoveryService = new CrmDiscoveryService();

myDiscoveryService.Credentials = System.Net.CredentialCache.DefaultCredentials;

myDiscoveryService.Url = “validurl.asmx”;

// Retrieving the list of organization that user belongs

RetrieveOrganizationsRequest myRetrieveOrgRequest = new RetrieveOrganizationsRequest();

RetrieveOrganizationsResponse myRetrieveOrgResponse = (RetrieveOrganizationsResponse)myDiscoveryService.Execute(myRetrieveOrgRequest);

// Get organization information

OrganizationDetail myOrgDetail = null;

foreach (OrganizationDetail orgDetail in myRetrieveOrgResponse.OrganizationDetails)

{

if (orgDetail.Equals(“MyOrgName”))

{

myOrgDetail = orgDetail;

break;

} }

// Setting Crm Authentication Token

CrmAuthenticationToken myCrmAuthToken = new CrmAuthenticationToken();

// 0- AD , 1- IFD , 2 – Windows Live

myCrmAuthToken.AuthenticationType = 0;

myCrmAuthToken.OrganizationName = myOrgDetail.OrganizationName;

// Finally setting our CrmService

CrmService myCrmService = new CrmService();

myCrmService.CrmAuthenticationTokenValue = myCrmAuthToken;

myCrmService.Url = myOrgDetail.CrmServiceUrl;

In case of IFD, we need CrmTicket for configuring CrmAuthenticationToken and CrmService.

CrmDiscoveryService myDiscoveryService = new CrmDiscoveryService();

myDiscoveryService.Credentials = System.Net.CredentialCache.DefaultCredentials;

myDiscoveryService.Url = “validurl.asmx”;

// Retrieving the list of organization that user belongs

RetrieveOrganizationsRequest myRetrieveOrgRequest = new RetrieveOrganizationsRequest();

myRetrieveOrgRequest.UserId = @”domain\username”;

myRetrieveOrgRequest.Password = “password”;

RetrieveOrganizationsResponse myRetrieveOrgResponse = (RetrieveOrganizationsResponse)myDiscoveryService.Execute(myRetrieveOrgRequest);

// Get organization information

OrganizationDetail myOrgDetail = null;

foreach (OrganizationDetail orgDetail in myRetrieveOrgResponse.OrganizationDetails)

{

if (orgDetail.Equals(“MyOrgName”))

{

myOrgDetail = orgDetail;

break;

} }

RetrieveCrmTicketRequest myTickectRequest = new RetrieveCrmTicketRequest();

myTickectRequest.OrganizationName = myOrgDetail.OrganizationName;

myTickectRequest.UserId=@”domain\username”;

myTickectRequest.Password = “password”;

RetrieveCrmTicketResponse myTicketResponse = (RetrieveCrmTicketResponse)myDiscoveryService.Execute(myTickectRequest);

// Setting Crm Authentication Token

CrmAuthenticationToken myCrmAuthToken = new CrmAuthenticationToken();

myCrmAuthToken.CrmTicket = myTicketResponse.CrmTicket;

// 0- AD , 1- IFD , 2 – Windows Live

myCrmAuthToken.AuthenticationType = 1

myCrmAuthToken.OrganizationName = myOrgDetail.OrganizationName;

// Finally setting our CrmService

CrmService myCrmService = new CrmService();

myCrmService.CrmAuthenticationTokenValue = myCrmAuthToken;

myCrmService.Url = myOrgDetail.CrmServiceUrl;

In case of Windows Online deployment

We need policy information, passport ticket and CrmTicket for configuring configuring CrmAuthenticationToken and CrmService.

LogonManager – This class is used to authenticate a user with the Windows Live ID service.

To access this class we need to add a reference to following idcrlwrapper.dll

The project can be found at sdk\server\helpers\cs\idcrlwrapper

CrmDiscoveryService myDiscoveryService = new CrmDiscoveryService();

myDiscoveryService.Credentials = System.Net.CredentialCache.DefaultCredentials;

myDiscoveryService.Url = https://dev.crm.dynamics.com/mscrmservices/2007/passport/CrmDiscoveryService.asmx“;

// Retireve Policy Information

RetrievePolicyRequest myPolicyRequest = new RetrievePolicyRequest();

RetrievePolicyResponse myPolicyResponse = (RetrievePolicyResponse)myDiscoveryService.Execute(myPolicyRequest);

LogonManager myLogonManager = new LogonManager();

string myPassportTicket = myLogonManager.Logon(“username”, “password”, “partner”, myPolicyResponse.Policy, “environment”);

myLogonManager.Dispose();

// Retrieving the list of organization that user belongs

RetrieveOrganizationsRequest myRetrieveOrgRequestLive = new RetrieveOrganizationsRequest();

myRetrieveOrgRequestLive.PassportTicket = myPassportTicket;

RetrieveOrganizationsResponse myRetrieveOrgResponseLive = (RetrieveOrganizationsResponse)myDiscoveryService.Execute(myRetrieveOrgRequestLive);

// Get organization information

OrganizationDetail myOrgDetailLive = null;

foreach (OrganizationDetail orgDetail in myRetrieveOrgResponseLive.OrganizationDetails)

{

if (orgDetail.Equals(“MyOrgName”))

{

myOrgDetailLive = orgDetail;

break;

}

}

RetrieveCrmTicketRequest myTickectRequest = new RetrieveCrmTicketRequest();

myTickectRequest.OrganizationName = myOrgDetail.OrganizationName;

myTickectRequest.PassportTicket = myPassportTicket;

RetrieveCrmTicketResponse myTicketResponse = (RetrieveCrmTicketResponse)myDiscoveryService.Execute(myTickectRequest);

// Setting Crm Authentication Token

CrmAuthenticationToken myCrmAuthToken = new CrmAuthenticationToken();

myCrmAuthToken.CrmTicket = myTicketResponse.CrmTicket;

// 0- AD , 1- IFD , 2 – Windows Live

myCrmAuthToken.AuthenticationType = 2;

myCrmAuthToken.OrganizationName = myOrgDetail.OrganizationName;

// Finally setting our CrmService

CrmService myCrmService = new CrmService();

myCrmService.CrmAuthenticationTokenValue = myCrmAuthToken;

myCrmService.Url = myOrgDetail.CrmServiceUrl;

Bye…

Using CrmDeploymentService CRM 4.0


We have a new webservice in CRM 4.0 i.e. CrmDeploymentService

This is the end-point for this web service

http://<servername%5B:port%5D>/mscrmservices/2007/crmdeploymentservice.asmx

Using CrmDeploymentService we can do the following

Create/Delete/Disable/Enable/Update/Set Default an organization etc.

There are two types of Microsoft Dynamics CRM deployment entities: Organization and Server. The Deployment SDK provides programmatic access for manipulating the Organization entity. It does not currently enable you to write code against the Server entity for actions such as enabling and disabling a Microsoft Dynamics CRM server.

We have a separate sdk for the Deployement.

We can download the sdk at the following location

http://www.microsoft.com/downloads/details.aspx?FamilyId=2874D878-E28D-4530-A185-4DEE1FCDD12E&displaylang=en

Some basic examples of using the service

// Create an instance of CrmDeploymentService

CrmDeploymentService myDeployService = new CrmDeploymentService();

myDeployService.Credentials = System.Net.CredentialCache.DefaultCredentials;

myDeployService.Url = ” valid url”;

// To retrieve server license type information

RetrieveLicenseRequest myLicRequest = new RetrieveLicenseRequest();

RetrieveLicenseResponse myLicResponse = (RetrieveLicenseResponse)myDeployService.Execute(myLicRequest);

MessageBox.Show(“License Type “ + myLicResponse.LicenseType.ToString());

// To get the organization information

RetrieveAllRequest myRetriveAllRequest = new RetrieveAllRequest();

// only organization is supported ( other is Server)

myRetriveAllRequest.EntityName = EntityName.Organization;

RetrieveAllResponse myRetriveAllResponse = (RetrieveAllResponse)myDeployService.Execute(myRetriveAllRequest);

foreach(DeploymentEntity myEntity in myRetriveAllResponse.Entities)

{

Organization myOrganization = (Organization)myEntity;

MessageBox.Show(myOrganization.FriendlyName);

MessageBox.Show(myOrganization.Id.ToString());

MessageBox.Show(myOrganization.UniqueName);

}

//// To disable an organization

SetStateOrganizationRequest myOrgSetStateRequest = new SetStateOrganizationRequest();

myOrgSetStateRequest.EntityName = EntityName.Organization;

myOrgSetStateRequest.Id = new Guid(“4c7fc991-0a41-dd11-bfd9-001d7d22e1af”);

myOrgSetStateRequest.State = OrganizationState.Disabled;

SetStateOrganizationResponse myOrgSetStateResponse =(SetStateOrganizationResponse) myDeployService.Execute(myOrgSetStateRequest);

Bye …..

Nishant Rana's Weblog

Everything related to Microsoft .NET Technology

Skip to content ↓