wcf实现跨域访问所需的配置文件
在wcf跨域访问操作的时候,需要用户自定义文件、来明确访问用户的身份和非法用户登录,日记录文件如下:
一、在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>
二、在客户端应用项目中添加一个中介类ServerManager.cs
publicclass ServerManager {
privatestatic ServiceWcfClient servicePicture =new ServiceWcfClient();
internalstatic 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();