Sep 24, 2012

Using CRM Webservice from custom web page (CRM 2011)

One of the previous posts we illustrated the way of using CRM service in custom page for CRM 4.0. Check it here.

Now we will see how the same task is accomplished in CRM 2011

If we put it in a method;

public static IOrganizationService getService()
{
ClientCredentials _cred = new ClientCredentials();

_cred.Windows.ClientCredential = new NetworkCredential("CRM_ADMIN_01", "F1xit@OR5", "CRMBIZDOMAIN");
string _url = "http://crmbiz:5555/abcltd/XRMServices/2011/Organization.svc";

OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(new Uri(_url), null, _cred, null);

return (IOrganizationService)serviceProxy;
}

Now the calling part;

6 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Please find more descriptive article here;
    http://axforum.info/forums/showthread.php?t=38211

    ReplyDelete
  3. private IOrganizationService CRMService()
    {
    try
    {
    string username = System.Configuration.ConfigurationManager.AppSettings["domain"] + @"\" + System.Configuration.ConfigurationManager.AppSettings["user"];
    string password = System.Configuration.ConfigurationManager.AppSettings["password"];
    var userCredentials = new ClientCredentials();
    userCredentials.UserName.UserName = username;
    userCredentials.UserName.Password = password;

    string orgUrl = System.Configuration.ConfigurationManager.AppSettings["url"];
    string discoveryUrl = System.Configuration.ConfigurationManager.AppSettings["disurl"];
    ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };


    IServiceConfiguration discoveryConfiguration = ServiceConfigurationFactory.CreateConfiguration(new System.Uri(discoveryUrl));
    SecurityTokenResponse userResponseWrapper = discoveryConfiguration.Authenticate(userCredentials);
    var _discServiceProxy = new DiscoveryServiceProxy(discoveryConfiguration, userResponseWrapper);
    IServiceConfiguration serviceConfiguration = ServiceConfigurationFactory.CreateConfiguration(new System.Uri(orgUrl));

    var serviceProxy = new OrganizationServiceProxy(serviceConfiguration,userResponseWrapper);
    serviceProxy.EnableProxyTypes();

    return (IOrganizationService)serviceProxy;


    }
    catch (Exception ex) {return null; }

    }

    ReplyDelete
  4. Where SvcHelper came from? I trying to follow your example, but i dont know the context of SvcHelper...

    ReplyDelete
    Replies
    1. Sorry for not elaborating.
      I have written this method as a static method in a class. In fact, you can call this without initiating an object.
      In fact, this is how it should be within a class called SvcHelper.

      public class svcHelper
      {
      public static IOrganizationService getService()
      {

      }
      }

      Delete