我想从我的silvelight应用程序与Console XML RPC服务器通信。可能吗?
步骤: 1.启动Console XML RPC服务器
Console XML RPC服务器的代码是:
using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using CookComputing.XmlRpc;
public class StateNameServer : MarshalByRefObject, IStateName
{
public string GetStateName(int stateNumber)
{
return "whatever";
}
}
class _
{
static void Main(string[] args)
{
IDictionary props = new Hashtable();
props["name"] = "MyHttpChannel";
props["port"] = 5678;
HttpChannel channel = new HttpChannel(props,null,new XmlRpcServerFormatterSinkProvider());
ChannelServices.RegisterChannel(channel,false);
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(StateNameServer),"statename.rem",WellKnownObjectMode.Singleton);
Console.WriteLine("Press <ENTER> to shutdown");
Console.ReadLine();
}
}
运行Silverlight应用程序 我使用了http://code.google.com/p/xmlrpc-silverlight/中的代码 我创建了新的Silverlight应用程序,我已经从该链接附加了代码。当我启动执行我的SL应用程序的网站(在带端口1139的localhost中)发生SecurityException。
void ResponseResponse(IAsyncResult result)
{
XmlRpcHelperRequestState state = result.AsyncState as XmlRpcHelperRequestState;
try
{
state.Response = (HttpWebResponse)state.Request.EndGetResponse(result);
...
}
catch (Exception e)
{
// comes here with SecurityException
}
finally
{
...
}
}
我使用的是VS2008 Professional,XP Professional,.net 3.5,Silverlight3。我很乐意提供所需的任何其他信息(或代码)。
答案 0 :(得分:1)
我怀疑这是缺少clientaccesspolicy.xml文件的情况。
由于您的silverlight应用程序将从其他权限启动,因此它将尝试访问此文件http://localhost:5678/
。由于您的小测试不支持该文件,Silverlight会阻止此跨域“域”活动。