Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight自动在http和https之间选择安全传输模式_Silverlight_Wcf_Ssl_Silverlight 4.0 - Fatal编程技术网

Silverlight自动在http和https之间选择安全传输模式

Silverlight自动在http和https之间选择安全传输模式,silverlight,wcf,ssl,silverlight-4.0,Silverlight,Wcf,Ssl,Silverlight 4.0,我们的Silverlight应用程序可以在http和https(SSL,使用传输安全)模式下运行。在我们的ServiceReferences.ClientConfig文件中,我们只是以以下方式配置了服务端点: <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <bindings> <basicHttpBindin

我们的Silverlight应用程序可以在http和https(SSL,使用传输安全)模式下运行。在我们的
ServiceReferences.ClientConfig
文件中,我们只是以以下方式配置了服务端点:

<?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自动决定应该使用哪种安全模式?这个问题最简单的解决办法是什么

提前谢谢


Thomas

我认为有很多方法可以从您的网页向SL应用程序提供initparams,如

param name=“initParams” value=“Https=true”

用于https页面 对于html页面为false。解析它 在SL内部,并为设置安全模式 终点

您可以在SL应用程序中以编程方式创建/编辑端点代理

另一种方法是在SL应用程序中设置基于链接的传输行为,而不使用initparams(如果以https->transport-else-none开头),我相信一旦下载了SL应用程序,链接就不应该是相对的,这应该是一个有效的解决方案

您可以创建一个工厂方法来创建服务代理,并将此设置代理逻辑放入其中,这比完全删除此serviceconfig文件要简单

你只要打个电话就行了

MyServiceClient client = Factory.MakeClient() 

我认为这是一个足够优雅的解决方案。在MakeClient中,您可以决定使用什么样的传输安全性并完成它。

我们最终得到了以下解决方案(与Valentin的建议不完全相同,但需要+1帮助!):

servicerences.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>
希望这有帮助

致以最良好的祝愿,
托马斯

谢谢你的提示。是的,我已经知道一些编程解决方案,对于大多数情况,我可以完全抛弃
servicerences.ClientConfig
,这是我不喜欢做的…是的,如果你可以从Scheme中毫无问题地读取它,看起来比传递https=true参数要好。
protected string EndpointName {
  get {
    return (App.Current.Host.Source.Scheme == "https") ?
      "SecureEndpoint" : "DefaultEndpoint";
  }
}

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