Silverlight automatically selects security security mode between http and https

Our Silverlight application can work both in HTTP mode and in https mode (SSL, using transport security mode). In our file, ServiceReferences.ClientConfigwe simply configured our service endpoint as follows:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="DefaultEndpoint"
                 maxBufferSize="2147483647"
                 maxReceivedMessageSize="2147483647">
          <security mode="None" />
          <!-- Enable for SSL: mode="Transport" -->
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="/services/DefaultService.svc"
                binding="basicHttpBinding"
                bindingConfiguration="DefaultEndpoint"
                contract="OurNamespace.IOurContractAsync"
                name="DefaultEndpoint" />
    </client>
  </system.serviceModel>
</configuration>

. , XAP: From http://example.com/slpage.html https://example.com/slpage.html. , "" "". . "", https, , "..https , http..." . Silverlight , ? ?

+3
2

, , ( , , +1 !):

ServiceReferences.ClientConfig , , :

<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="DefaultBinding"
                 maxBufferSize="2147483647"
                 maxReceivedMessageSize="2147483647">
          <security mode="None" />
        </binding>
      </basicHttpBinding>
      <customBinding>
        <binding name="SecureBinding">
          <textMessageEncoding messageVersion="Soap12WSAddressing10" />
          <httpsTransport maxBufferSize="2147483647"
                          maxReceivedMessageSize="2147483647" />
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="/services/DefaultService.svc"
                binding="basicHttpBinding"
                bindingConfiguration="DefaultBinding"
                contract="OurNamespace.IOurContractAsync"
                name="DefaultEndpoint" />
      <endpoint address="/services/DefaultService.svc"
                binding="customBinding"
                bindingConfiguration="SecureBinding"
                contract="OurNamespace.IOurContractAsync"
                name="SecureEndpoint" />
    </client>
  </system.serviceModel>
</configuration>

App.Current.Host.Source.Scheme. ChannelFactory, :

protected string EndpointName {
  get {
    return (App.Current.Host.Source.Scheme == "https") ?
      "SecureEndpoint" : "DefaultEndpoint";
  }
}

protected IOurContractAsync CreateInterface() {
  var channelFactory = ChannelFactory<IOurContractAsync>(EndpointName);
  return channelFactory.CreateChannel();
}

, !

,

+5

, initparams SL- -,

param name= "initParams" value = "Https = true"

https   false html-.   SL   .

/ - SL.

SL initparams ( https → transport else none) , sl , , .

factory - - , , serviceconfig.

MyServiceClient client = Factory.MakeClient() 

, . MakeClient , .

+1

Source: https://habr.com/ru/post/1786881/


All Articles