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 :
Microsoft Dynamics CRM (Archived)

Consume HTTPS WCF Service From Dynamics CRM 2015 Plugin

(0) ShareShare
ReportReport
Posted on by

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.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi,

    You may get help  from here

    blog.mikejmcguire.com/.../programatically-using-basichttpsbinding-and-usernamepasswordvalidator-classes-in-a-wcf-c-net-windows-service

    You can set similar properties for BasicHttpsBinding as  like you used here BasicHttpBinding.

    Hope this helps.

  • Community Member Profile Picture
    on at

    Goutam,

    Thanks for the advice on this one.

    The project that I am working on is only targeting 4.0 for framework and I know basichttpsbinding requires 4.5.

    This makes sense as to why I didn't see this before.

    For anyone curious, I ended up just switching both the WCF Service and the code from basichttpbinding to wshttpbinding.

    This gave me the security options I needed.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans