Silverlight:连接到安全的ASMX服务

时间:2010-09-28 18:19:40

标签: security silverlight-4.0 https asmx credentials

我需要使用Silverlight 4通过HTTPS连接到ASMX安全Web服务。我已经能够使用以下配置使用WPF应用程序连接到该服务:

  <binding name="wsSomeWebService" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    <security mode="Transport">
      <transport clientCredentialType="Basic" proxyCredentialType="Basic"
          realm="www.somedomain.com" />
      <message clientCredentialType="UserName" algorithmSuite="Default" />
    </security>
  </binding>

在代码中我执行以下操作:

client.ClientCredentials.UserName.UserName = "username";
client.ClientCredentials.UserName.Password = "password";

但是,当我尝试从Silverlight连接时,我总是会遇到安全性异常。

在服务器上,策略文件如下所示:

<access-policy> 
  <cross-domain-access> 
    <policy> 
      <allow-from http-methods="*" http-request-headers="*">      
        <domain uri="*"/> 
      </allow-from>      
      <grant-to>      
        <resource path="/" include-subpaths="true"/> 
      </grant-to>      
    </policy> 
  </cross-domain-access> 
</access-policy> 

在Silverlight上,我尝试过使用它:

  <customBinding>
    <binding name="secureBinaryHttpBinding" >
      <security authenticationMode="UserNameOverTransport"/>
      <httpsTransport  />
    </binding>
  </customBinding>

还有这个:

      <basicHttpBinding>
        <binding name="basicSecureBinding" maxBufferSize="2147483647"
            maxReceivedMessageSize="2147483647">
          <security mode="Transport"/>
        </binding>
      </basicHttpBinding>

但似乎都不起作用。

有没有人知道如何在Silverlight客户端上重现我在WPF中使用的成功配置?

1 个答案:

答案 0 :(得分:2)

而不是

<domain uri="*"/>

使用

<domain uri="http://*"/>
<domain uri="https://*" />
clientaccesspolicy.xml 中的

。有关详细信息,请查看此link