Showing posts with label ServiceConfigurationFactory. Show all posts
Showing posts with label ServiceConfigurationFactory. Show all posts

06 July 2011

IFD Claims based Authentication

Recently I had difficulties with creating client application to CRM deployed using Internet Facing deployment with Claims Based Authentication ADFS 2.0 Sample code shows connecting to IFD CRM only available at CRM SDK samplecode\cs\wsdlbasedproxies\ifd, but it supposes that you have to add Service References to Discovery Service and to Organization Service. I was not going to use Service References, but how to instantiate and configure OrganizationServiceProxy class item in the right way was not clear for me.
In my case ServiceConfigurationFactory class helped me. Below is peace of code how I'm retrieving IOrganizationService instance:

Uri organizationUriIFD = new Uri("https://[server]:[port]/XRMServices/2011/Organization.svc");

credentials.UserName.UserName = "username";
credentials.UserName.Password = "password";


using (Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(config, credentials))
{
// This statement is required to enable early-bound type support.
_serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

IOrganizationService _service = (IOrganizationService)_serviceProxy;

WhoAmIResponse response = (WhoAmIResponse)_service.Execute(new WhoAmIRequest());
Console.WriteLine(response.UserId.ToString());

Console.ReadLine();
}