Partager via


Primer on CRM Web Services Part 1 - the Basics

What is a web service ?
A web service is a programming interface exposed by an application. It follows industry standards that allow it to be consumed ( used ) by any software technology that understands the web service standards defined by W3C.

CRM Live exposes two web services: CrmService & CrmMetadataService

CrmService is used to fetch data, set data, make programmatic configuration changes, etc.
CrmMetadataService is used to query about the metadata. The metadata describes the entities, attributes, relationships, and so on, of the organization.

The WSDL, which stands for web service description language, can be fetched from your CRM system via the Settings-Download WSDL. You use this to create your web reference’s.

The endpoint URL for each of these in an internet facing deployment of CRM can be discovered thru the CrmDiscoveryService Web Service. You’ll also use the CrmDiscoveryService for policy information during the authentication process. The reference for the discovery service is at
https://MyOrgName/MSCRMServices/2007/Passport/CrmDiscoveryService.asmx

Then in your code set the URL for the CrmService and CrmMetadataService using the endpoint returned from the discovery services. The URLs can be retrieved from your ticket response object.

===============================================

Example :

// STEP 1: Retrieve a policy from the Discovery Web service.
CrmDiscoveryService discoveryService = new CrmDiscoveryService();
discoveryService.Url = String.Format("https://{0}/MSCRMServices/2007/Passport/CrmDiscoveryService.as
mx", _hostname);

RetrievePolicyRequest policyRequest = new RetrievePolicyRequest();
RetrievePolicyResponse policyResponse = (RetrievePolicyResponse)discoveryService.Execute(policyRequest);

// STEP 2: Retrieve a Passport ticket from the Passport service.
LogonManager lm = new LogonManager();
string passportTicket = lm.Logon(UserID, Password, _partner, policyResponse.Policy, _environment);

 

// STEP 3: Retrieve a CrmTicket from the Discovery Web service.
RetrieveCrmTicketRequest crmTicketRequest = new RetrieveCrmTicketRequest();
crmTicketRequest.OrganizationName = _organization;
crmTicketRequest.PassportTicket = passportTicket;
RetrieveCrmTicketResponse crmTicketResponse = (RetrieveCrmTicketResponse)discoveryService.Execute(crmTicketRequest);

 

// STEP 4: Create and configure an instance of the CrmService Web service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = AuthenticationType.Passport;
token.CrmTicket = crmTicketResponse.CrmTicket;
token.OrganizationName = crmTicketResponse.OrganizationDetail.OrganizationName;
CrmService crmService = new CrmService();
crmService.Url = crmService.CrmAuthenticationTokenValue = token;

 

// STEP 5: Invoke the desired CrmService Web service methods.
lead newlead = new lead();
newlead.description = "Lead Test";
newlead.subject = "My Lead Test Topic";
newlead.firstname ="John";
newlead.lastname = "Doe";
newlead.telephone1 = "425-421-1234";

// Call the Create method to create an lead
Guid leadID = crmService.Create(newlead);

===============================================

There are other examples of how to use the web services in the SDK.

You can download the SDK at

www.microsoft.com/downloads/details.aspx?FamilyID=82e632a7-faf9-41e0-8ec1-a2662aae9dfb&DisplayLang=en

 

 

Next, I'll blog about how you can program against custom entities.

cheers - Jon

Comments

  • Anonymous
    March 03, 2008
    What is a web service ? A web service is a programming interface exposed by an application. It follows

  • Anonymous
    June 01, 2010
    Simple and works...... why does the SDK have to be so confusing and outdated on this subject for CRM Live!  Thank you so much!