web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Calling a Windows Authenticated WCF Service in a Plugin in CRM

Nishant Rana Profile Picture Nishant Rana 11,325 Microsoft Employee

Hi,

Suppose we need to call the service created here in our plugin

http://nishantrana.me/2014/09/05/configure-a-wcf-service-for-windows-authentication/

As plugin don’t have configuration file, we need to specify binding information in Code.

The sample code to call the WCF Service by passing Network Credentials


private static void CallWCFService()
{
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;

// Specify the endpointAddress
EndpointAddress endpointAddress = new EndpointAddress(new Uri("http://servername:port/Service1.svc"));

ServiceReference1.Service1Client client = new ServiceReference1.Service1Client(binding, endpointAddress);
if (client.ChannelFactory.Credentials != null)
client.ChannelFactory.Credentials.Windows.ClientCredential = new System.Net.NetworkCredential("username", "password", "domain");
if (client.ClientCredentials != null)
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;
MessageBox.Show(client.GetData(1));
}

Hope it helps ..

 

 


Filed under: C#, CRM, CRM 2011 Tagged: CRM, CRM 2011, WCF

This was originally posted here.

Comments

*This post is locked for comments