thm*_*shd 3 silverlight ssl wcf silverlight-4.0
我们的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>
Run Code Online (Sandbox Code Playgroud)
可以在两种模式下访问配置的端点.它只取决于加载XAP文件的上下文:From http://example.com/slpage.html或https://example.com/slpage.html.不幸的是,我们必须在"无"和"传输"之间手动切换安全模式设置.其他一切都已按预期工作.当安全模式为"无"并且我们通过https访问时,我们得到一个例外"提供了..https但是预期了http ......",反之亦然.是否有机会让Silverlight自动决定应该使用哪种安全模式?这个问题最简单的解决方案是什么?
提前致谢
托马斯
我们最终得到了以下解决方案(不完全是Valentin所建议的,但+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>
Run Code Online (Sandbox Code Playgroud)
在初始化时,我们读取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();
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
最好的问候,托马斯
| 归档时间: |
|
| 查看次数: |
1782 次 |
| 最近记录: |