从silverlight调用https wcf服务

时间:2023-02-06 20:31:19

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:

我正在尝试从silverlight访问https wcf服务。 clientaccesspolicy放在服务root上,我已通过silverlightspy验证它显示为有效且允许调用。我能够从桌面客户端成功调用该webservice,但是当试图从silverlight调用它时会抛出一个错误,调用....服务失败可能是跨域poliecy等无效....任何想法????这里也是服务跨域策略:

    <?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 个解决方案

#1


You need a separate domain node for https:

您需要一个单独的域节点用于https:

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

From this post:

从这篇文章:

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

#2


This is a great source of silverlight + wcf info:

这是silverlight + wcf信息的重要来源:

http://www.netfxharmonics.com/2008/11/Understanding-WCF-Services-in-Silverlight-2

#3


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:

如果服务和silverlight应用程序是从同一网站提供的,并且您使用的是Silverlight 4,则可以通过以下方式在没有跨域策略文件的情况下完成此操作:

  • Accessing the silverlight application through https
  • 通过https访问silverlight应用程序

  • Using a relative address in the ServiceReferences.ClientConfig file to access the service
  • 使用ServiceReferences.ClientConfig文件中的相对地址来访问服务

  • Using transport mode security in the BasicHttpBinding for the service.
  • 在BasicHttpBinding中为服务使用传输模式安全性。

Here's an example of the ServiceReferences.ClientConfig:

以下是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>

#4


Have you looked here?

你看过这儿吗?

Calling WCF Service from Silverlight

从Silverlight调用WCF服务

#1


You need a separate domain node for https:

您需要一个单独的域节点用于https:

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

From this post:

从这篇文章:

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

#2


This is a great source of silverlight + wcf info:

这是silverlight + wcf信息的重要来源:

http://www.netfxharmonics.com/2008/11/Understanding-WCF-Services-in-Silverlight-2

#3


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:

如果服务和silverlight应用程序是从同一网站提供的,并且您使用的是Silverlight 4,则可以通过以下方式在没有跨域策略文件的情况下完成此操作:

  • Accessing the silverlight application through https
  • 通过https访问silverlight应用程序

  • Using a relative address in the ServiceReferences.ClientConfig file to access the service
  • 使用ServiceReferences.ClientConfig文件中的相对地址来访问服务

  • Using transport mode security in the BasicHttpBinding for the service.
  • 在BasicHttpBinding中为服务使用传输模式安全性。

Here's an example of the ServiceReferences.ClientConfig:

以下是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>

#4


Have you looked here?

你看过这儿吗?

Calling WCF Service from Silverlight

从Silverlight调用WCF服务