Hello all,
I've been able to successfully consume WCF services from plugins by programmatically instantiating a BasicHttpBinding and adding the service through Service References.
Here is a snippet of that code:
string endPoint = "myEndPointHere";
using(var MyServiceClient = GetMyServiceClient(endPoint)
{
MyServiceClient.ClientCredentials.Windows.ClientCredential = clientCredentials.Windows.ClientCredential; // clientCredentials is instantiated previously in code.
MyServiceClient.callSomeMethod();
}
GetMyServiceClient(string endPoint)
{
BasicHttpBinding binding = new BasicHttpBinding();
binding.SendTimeout = TimeSpan.FromMinutes(1);
binding.OpenTimeout = TimeSpan.FromMinutes(1);
binding.CloseTimeout = TimeSpan.FromMinutes(1);
binding.ReceiveTimeout = TimeSpan.FromMinutes(10);
binding.AllowCookies = false;
binding.BypassProxyOnLocal = false;
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding.MessageEncoding = WSMessageEncoding.Text;
binding.TextEncoding = System.Text.Encoding.UTF8;
binding.TransferMode = TransferMode.Buffered;
binding.MaxReceivedMessageSize = 104857600;
BasicHttpSecurity httpSecurity = new BasicHttpSecurity();
HttpTransportSecurity httpTransport = new HttpTransportSecurity();
httpTransport.ClientCredentialType = HttpClientCredentialType.Windows;
httpSecurity.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
httpSecurity.Transport = httpTransport;
binding.Security = httpSecurity;
binding.UseDefaultWebProxy = true;
return new MyService.MyServiceClient(binding, new EndpointAddress(endpoint));
}
The issue that I am running into is, I'm am now running into difficulties attempting to consume a WCF service that requires that I use HTTPS with Windows Authentication.
By any chance, would anyone know of a way that I can modify the above code to allow HTTPS (but from my research that might not be possible with basichttpbinding) so should I be using another binding such as wsHttpBinding, and if so, are there any working examples available?
Thank you for all the help.