Getting CSLALight to work over HTTPS

Getting CSLALight to work over HTTPS

Old forum URL: forums.lhotka.net/forums/t/7832.aspx


cds posted on Tuesday, October 20, 2009

I've got a CSLALight-based app running fine, but some users now want to use SSL - i.e. run over HTTPS.

I thought this would be easy but it turned out not to be. I got it to work in the end, so thought I'd post it here in case it helps somebody else (and I have a few lingering questions...)

So, I want my app to configure itself dynamically based on whether it's HTTP or HTTPS at runtime.

var pageUri = HtmlPage.Document.DocumentUri.ToString();
if (pageUri.ToLower().Contains("https"))
{
var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.MaxBufferSize = int.MaxValue;
binding.MaxReceivedMessageSize = int.MaxValue;
binding.ReceiveTimeout = TimeSpan.FromMinutes(10);
binding.SendTimeout = TimeSpan.FromMinutes(10);
binding.OpenTimeout = TimeSpan.FromMinutes(10);

WcfProxy.DefaultBinding = binding;
}


So, I'm setting a new Binding on the WcfProxy which has the security mode set to Transport.

Next, I had to modify my web.config's WCF configuration to add the following element into the binding:

security mode="Transport"


Then, further on down, the binding configuration is referenced in the endpoint.


So, as I said, this works. However, I'd prefer not to have to make changes at install time to the web.config file. Is there a way I can have multiple WCF configurations that would take the correct security setting depending on whether HTTP or HTTPS was being used?

Hopefully there's a WCF expert here who can help me with this.

Cheers...

Craig

sergeyb replied on Tuesday, October 20, 2009

Yep, you can certainly have two endpoints and two services (.svc files). You would need to set a different default url on the proxy class as well instead of relying on .ClientConfig.

Sergey Barskiy
Principal Consultant
office: 678.405.0687 | mobile: 404.388.1899

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation


-----Original Message-----
From: cds [mailto:cslanet@lhotka.net]
Sent: Tuesday, October 20, 2009 7:18 PM
To: Sergey Barskiy
Subject: [CSLA .NET] Getting CSLALight to work over HTTPS

I've got a CSLALight-based app running fine, but some users now want to use SSL - i.e. run over HTTPS.

I thought this would be easy but it turned out not to be. I got it to work in the end, so thought I'd post it here in case it helps somebody else (and I have a few lingering questions...)

So, I want my app to configure itself dynamically based on whether it's HTTP or HTTPS at runtime.

var pageUri = HtmlPage.Document.DocumentUri.ToString();
if (pageUri.ToLower().Contains("https"))
{
var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.MaxBufferSize = int.MaxValue;
binding.MaxReceivedMessageSize = int.MaxValue;
binding.ReceiveTimeout = TimeSpan.FromMinutes(10);
binding.SendTimeout = TimeSpan.FromMinutes(10);
binding.OpenTimeout = TimeSpan.FromMinutes(10);

WcfProxy.DefaultBinding = binding;
}


So, I'm setting a new Binding on the WcfProxy which has the security mode set to Transport.

Next, I had to modify my web.config's WCF configuration to add the following:





-->






Then, further on down, the binding configuration is referenced in the endpoint:













So, as I said, this works. However, I'd prefer not to have to make changes at install time to the web.config file. Is there a way I can have multiple WCF configurations that would take the correct security setting depending on whether HTTP or HTTPS was being used?

Hopefully there's a WCF expert here who can help me with this.

Cheers...

Craig

Copyright (c) Marimer LLC