title: Silverlight automatically choose security transport mode between http and https
body: <p>Our Silverlight Application can run in both <em>http</em> and <em>https</em> (SSL, using <em>Transport</em> Security) Mode. In our <code>ServiceReferences.ClientConfig</code> file we simply configured our Service Endpoint this way:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
  
    &lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name="DefaultEndpoint"
                   maxBufferSize="2147483647"
                   maxReceivedMessageSize="2147483647"&gt;
            &lt;security mode="None" /&gt;
            &lt;!-- Enable for SSL: mode="Transport" --&gt;
          &lt;/binding&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
        &lt;endpoint address="/services/DefaultService.svc"
                  binding="basicHttpBinding"
                  bindingConfiguration="DefaultEndpoint"
                  contract="OurNamespace.IOurContractAsync"
                  name="DefaultEndpoint" /&gt;
      &lt;/client&gt;
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>The configured Endpoint can be accessed in both Modes. It simply depends in which context the XAP file was loaded: From <code>http://example.com/slpage.html</code> or <code>https://example.com/slpage.html</code>. Unfortunately, we have to manually switch the <strong>Security Mode</strong> setting between "None" and "Transport". Everything else would already work as desired. When Security Mode is "None" and we access via https, we get an Exception that "..https was provided but http was expected..." and vice versa. Any chance to let Silverlight automatically decide which Security Mode should be used? What is the simplest solution to this problem?</p>
  
  <p>Thanks in advance</p>
  
  <p>Thomas</p>