Blog

SharePoint of Contact 2: Integrating SharePoint 2010 with CRM Online

SharePoint of Contact 2: Integrating SharePoint 2010 with CRM Online

SharePoint of Contact 2: Using CRM Online Data within SharePoint

In this previous blog post, I explained how to integrate Microsoft Dynamics CRM with SharePoint 2010 using an External Content Type (ECT) linked to the Dynamics SQL Server instance. Today I will explain how to integrate Microsoft Dynamics CRM Online with SharePoint 2010, also using an ECT. Since CRM Online data is only accessible via web services, we will use a WCF web service-based ECT.

First a note about why CRM Online data is only accessible via web services. CRM Online is Microsoft's cloud-hosted CRM solution, so the location of the databases containing your data is not local. For this reason, we will not be able to pursue the strategy outlined in the first blog post, but will instead use the web services provided by CRM Online.

Next, I will note that the CRM Online web services can only be used by a client running .NET 4. SharePoint 2010 is built with .NET 3.5, so SharePoint's Business Connectivity Services (BCS) cannot connect directly to the CRM Online web service. Instead, we will build an intermediary web service that runs on an application pool using the .NET 4 runtime and has a BCS-compatible interface.

To start, set up a CRM Online account (if you do not already have one )and associate it with a Windows Live ID. Once you can access your CRM Online account in a web browser, download the CRM 2011 SDK.

Within the "bin" directory of the CRM SDK find the crmsvcutil executable. This tool will generate the CRM data model used by your CRM Online site in code so that we will be able to use Linq to query CRM data. The syntax of the tool follows.

crmsvcutil.exe /url:https://[Site Name].crm.dynamics.com/XRMServices/2011/Organization.svc /out:CrmDataModel.cs /username:"[Live ID]" /password:"[Password]"

The file CrmDataModel.cs will be used in your web service.

Next, open up Visual Studio 2010 and create a new project based on a WCF Web Service template. Be sure to set the .NET Framework version to 4. Add CrmDataModel.cs to the project.

I would also suggest deleting the default web service item from the project and adding a new one with a more specific name.

Next, flesh out the web service so that it can gather the desired entities from CRM Online and deliver them to the web service consumer. Please see this blog for example code on how to use the CRM data model. If designing the web service to be used as part of an ECT, keep in mind the CRRUD operations (Create, Read List, Read Item, Update, Delete) that an ECT supports.

Next test out the web service. Visual Studio 2010 has a great point-and-click client for testing out web services that is opened when you begin debugging the web service through the IDE. If testing on a server that does not have Visual Studio 2010 installed, I have found that WCFStorm Lite is a great tool for reproducing the behavior of the Visual Studio WCF client.

Once you have verified that the web service is functional, you will have to create a web site and application pool to host it. Please remember that since this web service is unsecured, it should run either on a server that is not externally accessible or on a closed port. When adding the web site, make sure to grant the user IIS_IUSRS read/execute permissions to the site. This can be done through IIS Manager by right-clicking on the site folder and selecting Permissions. Also, remember when creating the application pool to be used by this site to set it to use the .NET 4 Framework. This can be done by selecting the application pool in IIS Manager and configuring Basic Settings. Lastly in IIS set the "Load User Profile" option to true under the Advanced Settings of the application pool.

Add the web service to the site by selecting the WCF project folder you created as a web application. This should be the location of the .svc files generated when building the project. You may need to grant permissions to this application to IIS_IUSRS. Fire up a browser and navigate to the new site you created - you should receive a page summarizing the web service.

If installing the web service on a server different than that hosting Visual Studio, be sure to copy the .svc files, the web.config configuration file, and the code assembly containing the service's logic. This assembly should be placed in a "bin" folder that resides at the same location as the web application folder holding the .svc files.

To test the web service, debug one of the service's code-behind files, or start up WCFStorm. If debugging through Visual Studio 2010, the methods available through the service should be available, as well as the arguments that can be passed to each method. The interface for WCFStorm is similar.

After the web service has been tested and the data returned has been verified, you can create an ECT using the WCF service rather than a SQL Server view as explained in the previous SharePoint-CRM integration blog post. You can also use the web service as a service reference in another .NET project - with any framework version.

Comments

hakh
# hakh
Hi,

What about to do this with sharepoint 2010 online. Is there some solution to things like above?
Peter Gleadell
Deleting the LiveDeviceID folder has done the trick.
Thanks very much for your help. It is miuch appreciated.

Kind regards
Peter
Jack Cosgrove
# Jack Cosgrove
Since the crm4 domain resolves you should use that.

Take a look at this blog for a potential solution. http://mubashersharif.blogspot.com/2012/06/crmsvcutilexe-parameter-is-incorrect.html
Peter Gleadell
Hi Jack,
Thanks very much for getting back to me.

If I put https://thecloudpartnership.crm4.dynamics.com/XRMServices/2011/Organization.svc in the browser I see some XML. However if I put in https://thecloudpartnership.crm.dynamics.com/XRMServices/2011/Organization.svc it does not resolve.


However If I use the URL https://thecloudpartnership.crm4.dynamics.com/XRMServices/2011/Organization.svc in crmsvcutil.exe I get a message to say the parameter is incorrect.

If I change the URL to https://thecloudpartnership.crm.dynamics.com/XRMServices/2011/Organization.svc I get the message saying the reference cannot be resolved


The typing in my message to your blog was not good here is the syntax I am using is:
crmsvcutil.exe /url:https://thecloudpartnership.crm.dynamics.com/XRMServices/2011/Organization.svc /out:GeneratedCode.cs /username:"[User Name]" /password:"[Password]"

Do you think this is an issue with the tool and I need to try and report it to Microsoft?

Regards
Peter
Jack Cosgrove
# Jack Cosgrove
Hi Peter.

I am not sure if the crmsvcutil.exe application or your CRM Online instance is localized, but I noticed that you used "Organisation" rather than "Organization". I also noticed that you used the "svs" file extension rather than "svc". Can you try using your web browser to navigate to the URL passed to crmsvcutil before running the application itself? If the address is correct, you will see a bunch of XML defining the service.
Peter Gleadell
Hi an following your post on how to integrate CRM 2011 online with SharePoint 2010.

I am stuck at using crmsvcutil.exe. Having followed the syntax exactly I get error message Exiting program with exception: Metadata contains a reference that cannot be resolved: 'https://thecloudpartnership.crm.dynamics.com/XRMServices/2011/Organisation.svs?wsdl.

Our CRM online service is on CRM4. If I change the reference in the URL to CRM4 I get an error message saying the parameter is incorrect.

Your advice would be much appreciated

Post a comment

Name (required)

Email (required)

CAPTCHA image
Enter the code shown above: