今天在做一个Demo时,突然发现一个问题,在wcf服务的根目录下放置一个策略文件后
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
<?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 path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
发现调用仍然会出现跨域的异常,
思前想后,找不到原因所在,后来想起来,之前在本上做tcp绑定的WCF时,我在wwwroot下放置了一个策略文件
内容是:
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
<?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>
<socket-resource port="4502-4534" protocol="tcp" />
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="*" />
</allow-from>
<grant-to>
<socket-resource port="4502-4534" protocol="tcp" />
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
而实际上这个策略文件是为了同时使用TCP和HTTP绑定的WCF放到wwwroot下的,于是我将这个文件移除掉
再调用一下服务,ok,调用成功;
注:在WCF为Silverlight提供数据服务时,我们需要在HTTP绑定类型的WCF服务根目录下放置策略文件,但是需要确保此策略文件的唯一性,如果在WWWROOT下也放置这样的文件,可能导致IIS无法正确向Silverlight递交这个策略文件。