calling https wcf service from silverlight

2019-05-30 15:52发布

i am trying to access a https wcf service from silverlight. the clientaccesspolicy is placed on service root and i have validated through silverlightspy its showing it as valid and calls allowed. i am able to call that webservice successfully from desktop client but when tries to call from silverlight it throws an error that call to .... service failed may be cross domain poliecy etc is not valid.... any ideas???? here is the service cross domain policy too:

    <?xml version="1.0" encoding="utf-8"?>
<access-policy>  <cross-domain-access>    
<policy>
      <allow-from http-request-headers="SOAPAction">    
    <domain uri="*" />
      </allow-from> 
     <grant-to>   
     <resource include-subpaths="true" path="/" />
      </grant-to>  
  </policy>
  </cross-domain-access>
</access-policy>

4条回答
啃猪蹄的小仙女
2楼-- · 2019-05-30 16:07

If the service and the silverlight app are served from the same web site and you are using Silverlight 4, you can accomplish this without a cross domain policy file by:

  • Accessing the silverlight application through https
  • Using a relative address in the ServiceReferences.ClientConfig file to access the service
  • Using transport mode security in the BasicHttpBinding for the service.

Here's an example of the ServiceReferences.ClientConfig:

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IMyService" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647">
                  <!--Transport mode security (setup the same way on the server):-->
                    <security mode="Transport" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
          <!--Relative address (This is the part that requires SL4):-->
            <endpoint address="../Services/MyService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
                contract="MyApplication.MyService" name="BasicHttpBinding_IMyService" />
        </client>
    </system.serviceModel>
</configuration>
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-05-30 16:10

You need a separate domain node for https:

 <domain uri="https://*" />

From this post:

http://timheuer.com/blog/archive/2008/10/14/calling-secure-services-with-silverlight-2-ssl-https.aspx

查看更多
Emotional °昔
4楼-- · 2019-05-30 16:19
登录 后发表回答