解决方法:
一、在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();