Creating Web Services for Dynamics CRM Online Integration

Back to Blog Listing

Getting Started

To use CRM in code you will first have to download and reference the CRM DLLs. You will require the Microsoft.CRM DLLs as well as the Microsoft.XRM DLLs. These can be found at:

Make sure to reference the following in your project:

  • Microsoft.Crm.Sdk
  • Microsoft.Crm.Sdk.Query
  • Microsoft.Crm.Sdk.TypeProxy
  • System.ServiceModel
  • Microsoft.Xrm
  • Microsoft.Xrm.Sdk.Client
  • Microsoft.Xrm.Sdk

Web References

In order to connect to the CRM 2011 online web services you must first create a web reference to the organisation WSDL. Notes on how to do this are as follows:


Getting Connected

Once the web reference is in place you must next create a connection to that web service. This can be done in the following way

  • Within the CRM SDK downloaded there is a VB class file called “DeviceIdManager.vb”, add this to your project. (a copy of this file can be found in the appendix 1.0 also)
  • The easiest way to create a connection that will be used multiple times is to create a “Utilities” class file that can be globally used by your WCF. Within this class create a “SetupCRMService” function that returns a CrmService object.
  • The code within the setup function should have the following syntax (PLEASE NOTE the organization URI will need the domain changed to be that of YOUR CRM Online):
' Login information for authentication through the Windows Live service.
        Dim _username As String = "[Windows Live Email Address]"
        Dim _password As String = "[Windows Live Password]"
        Dim credentials As ClientCredentials = New ClientCredentials()
        credentials.UserName.UserName = _username
        credentials.UserName.Password = _password
        credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials
        Dim organisationUri As New Uri("[CRMURL]/XRMServices/2011/Organization.svc")
        Dim homeRealmUri As Uri = Nothing
        Dim serviceProxy As OrganizationServiceProxy = New OrganizationServiceProxy(organisationUri, homeRealmUri, credentials, GetDeviceCredentials)
        Using (serviceProxy)
            Dim service As IOrganizationService = serviceProxy
            Return service
        End Using


Using Connection

Once you have the connector function available. Then you need to use it to initiate a CRM connection

Dim conf As New Utilities
Dim ser As IOrganizationService = conf.SetupCRMService()


You can then use the variable “ser” to perform actions against the primary CRM service.

Create Object

Contact in this case is just an example, by changing the entity type in the creation call you can use any CRM entity type.

Dim contact As Entity = New Entity("contact")
contact("accountid") = AccountID
contact("firstname") = firstname
contact("middlename") = middlename
contact("lastname") = lastname
Dim ID As Guid = ser.Create(contact)


Retrieve Entity Details (without early bound entity classes)

As with creation you can use any entity type you wish here. In order to return all the attribute values you wish you must ensure to add the names of these attributes to the list of strings within the column set as they appear in the CRM.

Dim conf As New Utilities
Dim ser As IOrganizationService = conf.SetupCRMWebService_NEW()
Dim accountID As New System.Guid("33C62572-1BF1-E111-A865-D48564519C24")
Dim cols As New Query.ColumnSet(New String() {"accountid", "address1_city"
Dim account As Entity = New Entity("account")
account = ser.Retrieve("account", accountID, cols)
Dim address As String = account("address1_line1")

About the Author

James CTwo is our blogging alter ego for the Dynamics CRM and Web experts here at C2. We have a passion for anything CRM, Web Design or Social Media. We love writing about it! Find us on YouTube & Twitter.

comments powered by Disqus

Our White Papers

Discover the content that matters to you on business transformation. Explore how you can drive customer engagement, empower your team, optimise your businesses and revolutionise your products with the next digital revolution. For more information visit our white paper library.


C2 Newsletter

Our newsletter is sent on a quarterly basis, offering detailed insights into all aspects of business transformation with Microsoft cloud technologies. We also promote upcoming events and special offers throughout the year. Sign up to get involved today.

Dynamics 365 Office 365 Power BI Silver Partner