用silverlight5进行Wshttpinding [英] Wshttpbinding with silverlight5

查看:112
本文介绍了用silverlight5进行Wshttpinding的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


i有一个WCF服务并在web配置中使用wsHttpBinding。



从IIS7创建测试证书并将其用作https绑定与网站



服务网络配置如下

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

< bindings>
< wsHttpBinding>
< binding name =" WsBinding">
< security mode =" Transport">
< transport clientCredentialType =" None" proxyCredentialType = QUOT;无"境界= QUOT;" />
< message clientCredentialType =" None" algorithmSuite = QUOT;默认" />
< / security>
< / binding>
< / wsHttpBinding>
< / bindings>

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

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

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





虽然在浏览器中打开Url它工作得很完美,也完美地为Silverlight项目添加服务。但是当从应用程序调用服务时,
会产生跨域错误,我还在项目中包含了clientaccesspolicy.xml和crossDomain.xml,但仍然遇到问题


< pre class ="prettyprint"style ="">尝试向URI
'https://MachineName.DomainName:8087 / WsService / Service1.svc'发出请求时发生错误。这个
可能是因为尝试以跨域方式访问服务
而没有适当的跨域策略,或者
的策略不适合SOAP服务。您可能需要联系
服务的所有者以发布跨域策略文件,并确保它允许发送与
SOAP相关的HTTP标头。在使用Web服务代理中的内部类型而不使用
InternalsVisibleToAttribute属性的情况下,
也可能导致此错误。有关详细信息,请参阅内部异常

请指导我对应用程序进行任何更改,同时您也可以分享相同的示例链接


提前感谢 








Chirag Sr. Sw.Developer Ahmedab​​ad




解决方案

您好,


如错误所示,您需要添加交叉 - 域策略。请在承载服务的域的根目录中绑定clientaccesspolicy.xml文件,以配置服务以允许跨域访问。并确保
已将crossdomain.xml文件保存到托管服务的域的根目录。有关详细信息,请参阅:


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


另外,你可以安装Fiddler,并观看您的客户端请求clientAccessPolicy.xml的Fiddler(这是一个简单的http GET请求,如下载图像或其他)


此外,请尝试以下类似帖子中提到的方法


http://social.msdn.microsoft.com/Forums/silverlight/en-US / 85b4b91e-7aa6-4f7b-82ed-8ecf30e9bfef /错误尝试到接入即服务-IN-A-跨域路 - 无需-A-适当-跨域策略上?论坛= silverlightweb


http://stackoverflow.com/questions/451424/silverlight-crossdomain


祝你好运,


i have a WCF service and using wsHttpBinding in web config.

create a test certificate from IIS7 and use it as https binding with website

Web config of Service as below

<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>


while open Url in browser it was working perfect, also work perfect in add Service referance to silverlight project . but while call service from application it will gives cross-domain error , i have also include clientaccesspolicy.xml and crossDomain.xml in project, but still face a problem

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.

Please guide me for any changes in app , also you can share any sample link for the same 

thanks in advance 


Chirag Sr. Sw.Developer Ahmedabad


解决方案

Hello,

Just as the error implies, you need add cross-domain policy. please place a clientaccesspolicy.xml file at the root of the domain where the service is hosted to configure the service to allow cross-domain access. and make sure you have saved the crossdomain.xml file to the root of the domain where the service is hosted. For details please refer:

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

Also, you can install Fiddler, and watch in Fiddler where your client is requesting clientAccessPolicy.xml (it's a simple http GET request, like downloading an image or whatever)

In addition, please try the methods mentioned in the following similar posts

http://social.msdn.microsoft.com/Forums/silverlight/en-US/85b4b91e-7aa6-4f7b-82ed-8ecf30e9bfef/error-attempting-to-access-a-service-in-a-crossdomain-way-without-a-proper-crossdomain-policy-in?forum=silverlightweb

http://stackoverflow.com/questions/451424/silverlight-crossdomain

Best regards,


这篇关于用silverlight5进行Wshttpinding的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆