【问题标题】:Cross domain error in WCF wsHttpBindingwith silverlightWCF wsHttpBindingwith silverlight 中的跨域错误
【发布时间】:2014-01-02 00:27:59
【问题描述】:

我有一个 WCF 服务,我在 web.config 中使用 wsHttpBinding

我还从 IIS7 创建了一个测试证书,并将其用于与网站的 https 绑定

服务的Web配置如下

<system.serviceModel>
  <behaviors>
   <serviceBehaviors>
    <behavior name="WsBehaviour">
     <serviceMetadata httpsGetEnabled="true"/>
     <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
   </serviceBehaviors>
  </behaviors>

  <bindings>
   <wsHttpBinding>
    <binding name="WsBinding">
      <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
        <message clientCredentialType="None" algorithmSuite="Default" />        
      </security>            
    </binding>
   </wsHttpBinding>    
  </bindings>

  <services>
   <service name="WsService.Service1" behaviorConfiguration ="WsBehaviour">
     <endpoint address="https://MachineName.DomainName:8087/WsService/Service1.svc"
      binding="wsHttpBinding" bindingConfiguration="WsBinding" contract="WsService.IService1" >

       <identity>
         <dns value="localhost" />
       </identity>

     </endpoint>
   </service>
  </services>  
 </system.serviceModel>

当我在浏览器中打开 URL 时,它运行良好,当我向 silverlight 项目添加服务引用时,它也运行良好。

但是当我从应用程序调用服务时,它给出了一个跨域错误。

我在项目中也包含clientaccesspolicy.xmlcrossDomain.xml,但仍然遇到问题

An error occurred while trying to make a request to URI
'https://MachineName.DomainName:8087/WsService/Service1.svc'. This
could be due to attempting to access a service in a cross-domain way
without a proper cross-domain policy in place, or a policy that is
unsuitable for SOAP services. You may need to contact the owner of the
service to publish a cross-domain policy file and to ensure it allows
SOAP-related HTTP headers to be sent. This error may also be caused by
using internal types in the web service proxy without using the
InternalsVisibleToAttribute attribute. Please see the inner exception
for more details.

【问题讨论】:

    标签: c# wcf silverlight cross-domain wshttpbinding


    【解决方案1】:

    clientaccesspolicy.xml 需要在您的 Web 服务器的根目录中,而不是在您的项目中。

    http://msdn.microsoft.com/en-us/library/cc197955(v=vs.95).aspx

    3. 将 crossdomain.xml 文件保存到托管服务的域的根目录。例如,如果服务托管在http://fabrikam.com,那么文件必须位于http://fabrikam.com/crossdomain.xml

    【讨论】:

    • 您好 Rob 感谢您的回答,现在 xml 问题已解决,但我仍然面临跨域错误
    【解决方案2】:

    您需要在您托管在 IIS 上的 WCF 服务的根文件夹中添加 clientaccesspolicy.xml 和 crossDomain.xml。

    【讨论】:

      猜你喜欢
      • 2011-08-27
      • 2011-11-15
      • 2011-03-27
      • 2012-09-05
      • 2011-10-15
      • 1970-01-01
      • 2011-05-03
      • 1970-01-01
      • 2010-09-30
      相关资源
      最近更新 更多