c# - WCF wsHttpBindingwith silverlight 中的跨域错误

标签 c# wcf silverlight cross-domain wshttpbinding

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

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

服务的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.

enter image description here

最佳答案

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

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

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

关于c# - WCF wsHttpBindingwith silverlight 中的跨域错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20580014/

相关文章:

c# - PagedViewCollection 按列分组,而不是属性

silverlight - Silverlight 中的并发连接数

c# - 同步函数内的异步调用

c# - 数据不会保存在我的数据库中

c# - 如何从 Windows 7 客户端计算机在远程 Windows 服务器上重新启动 IIS?

c# - 使用/不使用 SSL/TLS 在客户端上验证 wcf 端点的最佳实践

wcf - 如何将字节数组从 Silverlight 保存到文件

c# - 类型 '*' ,作为 ServiceHost 指令中的 Service 属性值提供,或在配置元素中提供 * 无法找到

c# - 如何替换 HTML 内容?

.net - 使用 Silverlight 2b2 上传二进制数据