Calling a Windows Authenticated WCF Service in a Plugin in CRM
Views (625)
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.

Like
Report
*This post is locked for comments