您的位置:首页 > 其它

以跨域方式访问服务而又没有正确的跨域策略,或策略不适用于 SOAP 服务 问题解决

2010-10-03 13:02 531 查看
解决方法:

  一、在WCF项目根目录下添加clientaccesspolicy.xml文件

<?
xml version
=
"
1.0
"
encoding
=
"
utf-8
"

?>

<
access
-
policy
>

<
cross
-
domain
-
access
>

<
policy
>

<
allow
-
from http
-
request
-
headers
=
"
*
"
>

<
domain uri
=
"
*
"
/>

</
allow
-
from
>

<
grant
-
to
>

<
resource path
=
"
/
"
include
-
subpaths
=
"
true
"
/>

</
grant
-
to
>

</
policy
>

</
cross
-
domain
-
access
>

</
access
-
policy
>

二、在silverlight项目中添加一个中介类ServerManager.cs

public

class
ServerManager

{

private

static
ServiceWcfClient servicePicture
=

new
ServiceWcfClient();

internal

static
ServiceWcfClient GetPox()

{

if
(servicePicture.State
==
System.ServiceModel.CommunicationState.Created)

{

servicePicture.Endpoint.Address
=

new
System.ServiceModel.EndpointAddress(
" http://localhost:52207/ServiceWcf.svc "
);

return
servicePicture;

}

else

{

return
servicePicture;

}

}

}

三、实例化实体类的时候一般是这样:ServiceWcfClient clientWcf = new ServiceWcfClient();

换成:ServiceWcfClient clientWcf = ServerManager.GetPox();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐