如何使用SSL保护启用Silverlight的WCF Web服务?

Ytt*_*ium 7 silverlight wcf

如何使用SSL保护启用Silverlight的WCF Web服务?我试过设置它类似于SSL保护的常规WCF服务,但它似乎不起作用.您在Web.Config中设置了什么,以及您在Silverlight的ServiceReferences.ClientConfig中设置了什么?

我注意到在Silverlight客户端应用程序的ServiceReferences.ClientConfig文件中,"绑定"标记仅允许basicHttpBinding和NOT wsHttpBinding.这是否意味着您无法保护启用Silverlight的WCF服务?如果有,有更好的方法来保护它吗?

小智 11

我配置了三个关键位置以在我自己的应用程序中使用https.

Web.config文件

在行为标签中包含以下行:

<serviceMetadata httpsGetEnabled="true"/>
Run Code Online (Sandbox Code Playgroud)

对于MEX端点,请确保使用https协议:

<endpoint address="mex" binding="mexHttpsBinding"
          contract="IMetadataExchange" />
Run Code Online (Sandbox Code Playgroud)

创建自定义绑定.重要的是运输安全:

  <basicHttpBinding>
    <binding name="myServicesBinding">
      <security mode="Transport"/>
    </binding>
  </basicHttpBinding>
Run Code Online (Sandbox Code Playgroud)

您还可以包含通常的授权内容:

<authorization>
  <allow users="?"/>
  <deny users="*"/>
</authorization>
Run Code Online (Sandbox Code Playgroud)

Silverlight的

在Silverlight端,要么将ServiceReference指向现在的安全服务,要么在代码中手动设置连接.ServiceReferences.ClientConfig文件应该包含安全性内容:

<security mode="Transport"/>
Run Code Online (Sandbox Code Playgroud)

代码版本如下所示:

BasicHttpBinding b = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
Run Code Online (Sandbox Code Playgroud)

可能有更复杂的事情可以做,但对大多数人来说这应该是足够好的.


blo*_*art -2

Silverlight 不支持 WS* - 基本上将客户端配置中的 URL 更改为 https:// url - 这就是您所能做的