The request failed with HTTP status 401: Unauthorized. Mandatory updates for Microsoft Dynamics CRM could not be applied successfully

We faced this problem while installing  CRM outlook client in one of our laptops.

I  followed the instructions mentioned below which i found while searching for the same.

On the client computer open the control panel.
Open the User Accounts icon.
Click the Advanced tab.
Click Manage Passwords.
Click Add.
Enter the server name of the CRM server
Enter the username as domain\username
Enter the password.
Click OK, then click Close and then click OK.

 

On the client open IE, click the Tools menu and then click Internet Options.
Click the Security tab.
Click the Local Intranet icon.
Click the Sites button.
Click the Advanced button.
Enter the website for access Microsoft CRM and then click the Add button.
Click OK 3 times.
Close any open IE sessions.

The problem got solved for us !

Bye..

Failed to execute web request for the specified Url (SharePoint)

I was getting this error while trying to build a report ( using sql server reporting services) using xml as a data source against Lists web service of SharePoint.

I was making use of GetListItems method of the Lists web service.

Finally the error was fixed by using Fiddler(web debugging tool) within which we easily view the request and responses sent back and forth.

http://www.fiddlertool.com/fiddler/

Using it I checked the soap request being passed to the web service and was able to correct the error.

For using the web service (Lists) I followed the following steps.

Selected Data Source type as XML

Connection String as the url of the web service

http://servername/_vti_bin/lists.asmx

And the following query

<Query>

<Method Namespace=http://schemas.microsoft.com/sharepoint/soap/ Name=GetListItems>

<Parameters>

<Parameter Name=listName>

<DefaultValue>Employee Satisfaction Survey</DefaultValue>

</Parameter>

</Parameters>

</Method>

<SoapAction>http://schemas.microsoft.com/sharepoint/soap/GetListItems</SoapAction>

</Query>


Bye..

 

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..