gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 12:51:01 26 4
gpt4 key购买 nike

我们的 Silverlight 应用程序可以在 httphttps(SSL,使用Transport 安全)模式下运行。在我们的 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 文件的上下文:从 http://example.com/slpage.htmlhttps://example.com/slpage.html .不幸的是,我们必须在“无”和“传输”之间手动切换安全模式设置。其他一切都已经按预期工作了。当安全模式为“无”并且我们通过 https 访问时,我们会得到一个异常,即“提供了 ..https 但应该是 http...”,反之亦然。是否有机会让 Silverlight 自动决定应该使用哪种安全模式?这个问题最简单的解决方案是什么?

提前致谢

托马斯

最佳答案

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

ServiceReferences.ClientConfig 包含绑定(bind)和端点配置,如下所示:

<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 属性。 Service客户端由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();
}

希望这对您有所帮助!

最好的问候,托马斯

关于Silverlight 自动在 http 和 https 之间选择安全传输模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4757464/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com