Aug 21, 2012

Using CRM Webservice from custom web page (CRM 4.0)

Suppose we need to do any operation in CRM through a custom webpage. Now we need to use CRM web service in the most standard way. Below is the way we can instantiate and authenticate the service which could be used in our page.

If we put it in a method;

public static CrmService getCrmWebService(string _serverName, string _orgName)

         CrmAuthenticationToken token = new CrmAuthenticationToken();
         token.AuthenticationType = 0;
         token.OrganizationName = _orgName;

         CrmService _service = new CrmService();
         _service.Url = "http://" + _serverName + "/mscrmservices/2007/crmservice.asmx";
         _service.CrmAuthenticationTokenValue = token;

         NetworkCredential _cred = new NetworkCredential();
         _cred.Domain = "CRMBIZDOMAIN";
         _cred.UserName = "CRM_ADMIN_01";
         _cred.Password = "F1xit@OR5";
         _service.Credentials = _cred;

         return _service;

Calling part;

CrmService _CrmService = CrmCore.getCrmWebService("corp-biz01:5555", "AxCRM01");

Now any operation is possible.

To check how to do the same thing in CRM 2011, click here.