[How To]:Converting a WCF Service to REST Enabled – Part 1

Below are the steps to convert make the service REST enabled :

Step 1 :

In IserviceRequestManager.cs, replace the [Operation Contract] with [WebGet] and add reference “System.ServiceModel.Web”

Step 2 :

In ServiceRequestManager.svc markup, add the attribute “Factory=”System.ServiceModel.Activation.WebServiceHostFactory”.

As shown below :

<%@
ServiceHost
Language=”C#”
Debug=”true”
Service=”XYZ.ServiceManagement.Services.ServiceRequestManager”
CodeBehind=”ServiceRequestManager.svc.cs”
Factory=”System.ServiceModel.Activation.WebServiceHostFactory”
%>

Step 3 :

In web.config within the <system.ServiceModel> add the following configuration :

“<standardEndpoints>
<webHttpEndpoint>
<!– the “” standard endpoint is used by WebServiceHost for auto creating a web endpoint. –>
<standardEndpoint name=”” helpEnabled=”true”/>
</webHttpEndpoint>
</standardEndpoints>”

As shown below :

Happy Exploring J

Advertisements

Customer Care Accelerator (CCA) for CRM 2011 (Part 3 – Hosting Bing as Hosted Control)

Please refer the earlier post

1. Customer Care Accelerator – Part 1

2. Customer Care Accelerator – Part 2

Here we would be hosting the Bing search page using Hosted Control.

Add a new class library project to the Agent Desktop Solution.

Add a new User Control class to the project

Add references to the following assemblies

Inherit the HostedControl class

And override the implement the Hosted Control class in the following manner

</pre>
using System;
using System.Windows.Forms;
using Microsoft.Uii.Common.Logging;
using Microsoft.Uii.Csr;
using Microsoft.Uii.Csr.Browser.Web;

namespace MyHostedControl
{
 /// <summary>
 /// Class BingHostedControl
 /// </summary>
 public partial class BingHostedControl : HostedControl
 {
 /// <summary>
 /// The navigation URL
 /// </summary>
 private readonly string _navigationUrl;

/// <summary>
 /// Represents the web page dom
 /// </summary>
 private HtmlDocument _doc;

/// <summary>
 /// The web browser
 /// </summary>
 private WebBrowserExtended _webBrowser;

/// <summary>
 /// Initializes a new instance of the <see cref="BingHostedControl"/> class.
 /// </summary>
 public BingHostedControl()
 {
 InitializeComponent();
 }


 /// <summary>
 /// Initializes a new instance of the <see cref="BingHostedControl"/> class.
 /// </summary>
 /// <param name="appId">The app id.</param>
 /// <param name="appName">Name of the app.</param>
 /// <param name="extensionXml">The extension XML.</param>
 public BingHostedControl(Guid appId, string appName, string extensionXml)
 : base(appId, appName, extensionXml)
 {
 _navigationUrl = "http://www.bing.com";
 InitializeComponent();
 }

/// <summary>
 /// Initializes this instance.
 /// </summary>
 public override void Initialize()
 {
 try
 {
 InitializeBrowser();
 base.Initialize();
 }
 catch (Exception exception)
 {
 Logging.Error("Bing Hosted App", "Error occurred initializing the Bing control", exception);
 throw;
 }
 }

/// <summary>
 /// Initialize Browser
 /// </summary>
 private void InitializeBrowser()
 {
 _webBrowser = new WebBrowserExtended(false, true, true);
 _webBrowser.Dock = DockStyle.Fill;
 _webBrowser.Visible = true;
 Controls.Add(_webBrowser);
 }


 /// <summary>
 /// Close the web browser process before closing the hosted control
 /// </summary>
 public override void Close()
 {
 try
 {
 if (_webBrowser != null)
 {
 _webBrowser.CloseBrowser();
 _webBrowser.Dispose();
 }

base.Close();
 }
 catch (Exception exception)
 {
 Logging.Error("Bing Hosted App", "Error occurred initializing the Bing control", exception);
 throw;
 }
 }


 /// <summary>
 /// Method is used to perform automation
 /// </summary>
 /// <param name="args">event arguments</param>
 protected override void DoAction(RequestActionEventArgs args)
 {
 try
 {
 if (args == null)
 {
 return;
 }

if (args.Action.Equals("default"))
 {
 _webBrowser.DocumentComplete += WebBrowser_DocumentComplete;
 _webBrowser.Navigate(_navigationUrl);
 }

base.DoAction(args);
 }
 catch (Exception exception)
 {
 Logging.Error("Bing Hosted App", "Error occurred initializing the Bing control", exception);
 throw;
 }
 }


 /// <summary>
 /// Called when web application is completely loaded
 /// </summary>
 /// <param name="sender">sender object</param>
 /// <param name="e">event arguments</param>
 private void WebBrowser_DocumentComplete(object sender, DocumentCompleteEventArgs e)
 {
 try
 {
 if (_webBrowser != null &&
 (_webBrowser.ReadyState == WebBrowserReadyState.Complete ||
 _webBrowser.ReadyState == WebBrowserReadyState.Loaded))
 {
 _doc = _webBrowser.Document as HtmlDocument;
 if (_doc != null)
 {
 // perform DOM operation as reuquired
 //_document = _doc.GetElementsByTagName("FRAME");
 }
 }
 }
 catch (InvalidOperationException exception)
 {
 Close();
 Logging.Error("Bing Hosted App", "Error occurred while loading Bing control", exception);
 throw;
 }
 catch (Exception exception)
 {
 Close();
 Logging.Error("Bing Hosted App", "Error occurred while loading Bing control", exception);
 throw;
 }
 }
 }
}
<pre>

Create a new UII Hosted Application record in CRM

Here we will see a default UII Actions defined for the Hosted Control which we can access in the DoAction method of the Hosted Control.

Run the Agent Desktop.exe

We can see the Bing search page hosted inside the Agent Desktop as a Hosted Control. We will get into details of the Hosted Control and other stuffs and will see more real world examples in the future posts.

Customer Care Accelerator (CCA) for CRM 2011 (Part 2 – Hosting Bing as Web Hosted Control)

As I have already covered installation and configuration in part 1 of the post, let’s take a little step further with a simple example in which we will host Bing inside Agent Desktop in a new tab as a Web Hosted Control.

Open the CRM organization.

Go to UII Settings à Create a new UII Hosted Applications

Specify the following values for the new UII hosted application record

Hosted Application Type
à Web Hosted Application

Application is Global
à Checked (To make it appear in the Agent desktop when it loads)

URL
à URL of the Bing search page.

Save the record and run the AgentDesktop.exe.

We can see the Bing search page hosted inside the Agent Desktop.

This was very simple example. As we move forward we’d look into more complex and real world scenarios.

Hope it helps.

Customer Care Accelerator (CCA) for CRM 2011 (Part 1 – Installation)

I have been playing around with CCA for quite some time now for few of my recent projects. So just thought of sharing some of my learnings. Will try to cover as much as possible in different parts. For the part 1 let us start with the installation.

The first step to which is to download it. We can get the CCA components from the market place.

http://pinpoint.microsoft.com/en-IN/applications/Customer-Care-Accelerator-for-Microsoft-Dynamics-CRM-2011-12884949176

Which would be CCA.cab file which we need to extract. It will have one more cab file in it. CustomerCareAccelerator.zip.cab which also needs to be extracted.

It will contain following files and folders in it

Open the Accelerator folder and execute run the 32 bit or 64 bit Customer Care Accelerator exe.

It would have following files and folders in it.

Open the source code folder and open the Agent Desktop solution therein.

If we try to build the solution it will fail as it would be expecting references to certain assemblies that will be missing

To get those assemblies open the UII folder and run the executable inside.

The executable will install the following folders

The Framework folder will contain all the required assemblies.

Replace the CRM 2011 dlls with the latest one otherwise we would face authentication errors.

Here download the hotfix for CCA and replace the following assemblies in the framework folder

http://dynamics-crm.pinpoint.microsoft.com/en-us/applications/customer-care-accelerator-for-microsoft-dynamics-crm-2011-12884914795

Add the required references to the projects in the AgentDesktop Solution.

There is one assembly Microsoft.Practices.CompositeUI.Windows which we can get from the following url

http://blogs.msdn.com/b/ukcrm/archive/2011/05/11/getting-started-with-cca-for-crm-2011.aspx

Adding references to it will let us finally build the solution.

Next import the following solutions and the csv files in the CRM organization.

Once the import is successful, open the Microsoft.Crm.Accelerator.Cca.RIConfigLoader.exe of the solution just built.

Create a new connection.

For CRM Service URL, specify the discovery service url and check CRM Online if connection to the Online instance.

Once connected Click Deploy

Create a TEMP folder on the C Drive which Agent Desktop will user for logging.

Next open the AgentDesktop.exe.config and specify the connection information.

And Run the AgentDesktop.exe.

Hope it helps.

Resolved : Permission Denied error while accessing OrganizationService.svc from JavaScript in CRM 2011

Hi,

I was getting the Permission Denied error in one of our JavaScript that was making Ajax call to OrganizationService.svc. Obviously it was because of some cross domain thing. The problem was that it was working fine in one of our organization but gave error when deployed it in a new organization.

Intially using the below code to set the organization service url

var pagecontext = Xrm.Page.context;

var serverUrl = pagecontext.getServerUrl();

var serviceUrl = serverUrl + “/XRMServices/2011/Organization.svc/web”;

Changing it to following resolved the issue for us

var serverUrl = document.location.protocol + “//” + document.location.host + “/” + Xrm.Page.context.getOrgUniqueName();

var serviceUrl = serverUrl + “/XRMServices/2011/Organization.svc/web”;

Hope it helps

Fixed – You cannot start a transaction with a different isolation level than is already set on the current transaction error in Plugin in CRM 2011

Hi,

I was getting the above error on a plugin that was making use of CreateAttribute request class. The plugin was registered on pre-operation Create event.

From the error message it seemed that we cannot use CreateAttribute request message as a part of same transaction in which the plugin was already running. So we tried by registering our plugin in Pre-Validation stage i.e. outside of transaction. (as used to be the case in CRM 4).

This way I was able to resolve the issue.

Hope it helps.

Role-Based SiteMap : Show/Hide Settings Area in CRM 2011

Here I will be describing about a scenario where other than Administrator,no user can see the Settings section in the CRM.

Please find the below problem statement:

Show/Hide Settings area based on the roles

Following are the steps to solve the problem:

  1. Create a new entity named “RoleHideSettingsResource”(any name of your choice).
  2. Give read access of newly created entity only to the Administrator and System Customizer.No other users will have any permission as shown below:

  1. Get the Sitemap xml(using any editor tool*) and edit it as follows :

Search for <Area Id=Settings” ResourceId=Area_Settings
and then add:

<Privilege Entity="new_rolehidesettingsresource" Privilege="Read" />

to all theSubAreas as shown below :

<Area Id="Settings" ResourceId="Area_Settings" ShowGroups="true" Icon="/_imgs/settings_24x24.gif" DescriptionResourceId="Settings_Area_Description">
<Group Id="Business_Setting" ResourceId="Menu_Label_Business" DescriptionResourceId="Menu_Label_Business">
<SubArea Id="nav_businessmanagement" ResourceId="Homepage_BusinessManagement" DescriptionResourceId="BizManagement_SubArea_Description" Icon="/_imgs/ico_18_busmanagement.gif" Url="/tools/business/business.aspx" AvailableOffline="false">
<Privilege Entity="new_rolehidesettingsresource" Privilege="Read" />
</SubArea>

4.Save the xml and update the sitemap and assign appropriate roles to the users.