将Silverlight应用程序连接到自托管WCF服务
我已经创建了一个运行在192.168.0.199:87上的WCF服务。这项服务可以正常工作。然而,当我在VS中创建Silverlight应用程序在我的开发pc上使用此服务时,我遇到了跨域问题。我该怎么解决这个问题?该服务不是IIS WCF服务。我也无法在同一端口上承载WCF服务和Silverlight应用程序。Silverlight正在192.178.0.199:87上查找clientaccesspolicy.xml,在本例中,这是我的自托管WCF服务的地址 任何帮助都会很好 这是我的代码,我不知道我是否酿造了一些好东西。 我的app.config文件位于此处。我认为这是一个端点问题,但我不确定。将Silverlight应用程序连接到自托管WCF服务,wcf,self-hosting,Wcf,Self Hosting,我已经创建了一个运行在192.168.0.199:87上的WCF服务。这项服务可以正常工作。然而,当我在VS中创建Silverlight应用程序在我的开发pc上使用此服务时,我遇到了跨域问题。我该怎么解决这个问题?该服务不是IIS WCF服务。我也无法在同一端口上承载WCF服务和Silverlight应用程序。Silverlight正在192.178.0.199:87上查找clientaccesspolicy.xml,在本例中,这是我的自托管WCF服务的地址 任何帮助都会很好 这是我的代码,我不
命名空间窗口窗体应用程序11
{
公共部分类Form1:Form
{
公共服务主机_host=null;
公共表格1()
{
初始化组件();
}
私有无效按钮1\u单击(对象发送者,事件参数e)
{
_主机=新服务主机(类型为(WmsStatService));
_host.Open();
}
}
//定义服务合同。
[ServiceContract(命名空间=”http://WindowsFormsApplication11")]
公共接口iwmstat
{
[经营合同]
字符串sayHello(字符串名称);
[OperationContract,WebGet(UriTemplate=“/clientaccesspolicy.xml”)]
流GetSilverlightPolicy();
}
公共类WmsStatService:IWMStat
{
公共字符串sayHello(字符串名称)
{
返回“你好”+姓名+“很高兴认识你!”;
}
Stream StringToStream(字符串结果)
{
WebOperationContext.Current.OutgoingResponse.ContentType=“应用程序/xml”;
返回新的MemoryStream(Encoding.UTF8.GetBytes(result));
}
公共流GetSilverlightPolicy()
{
//结果包含clienaccpolicy.xml内容。
//
字符串结果=@“
";
返回StringToStream(结果);
}
}
}
namespace WindowsFormsApplication11
{
public partial class Form1 : Form
{
public ServiceHost _host = null;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
_host = new ServiceHost(typeof(WmsStatService));
_host.Open();
}
}
// Define a service contract.
[ServiceContract(Namespace = "http://WindowsFormsApplication11")]
public interface IWmsStat
{
[OperationContract]
string sayHello(string name);
[OperationContract, WebGet(UriTemplate = "/clientaccesspolicy.xml")]
Stream GetSilverlightPolicy();
}
public class WmsStatService : IWmsStat
{
public string sayHello(string name)
{
return "hello there " + name + " nice to meet you!";
}
Stream StringToStream(string result)
{
WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml";
return new MemoryStream(Encoding.UTF8.GetBytes(result));
}
public Stream GetSilverlightPolicy()
{
// result cointains the clienaccpolicy.xml content.
//
string result = @"<?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>";
return StringToStream(result);
}
}
}