【问题标题】:Silverlight communication with XML RPC console serverSilverlight 与 XML RPC 控制台服务器的通信
【发布时间】:2010-12-07 07:37:35
【问题描述】:

我想通过我的 silvelight 应用程序与控制台 XML RPC 服务器通信。可以吗?

步骤: 1. 启动 Console XML RPC 服务器

控制台 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();
  }
}
  1. 运行 Silverlight 应用程序 我使用了http://code.google.com/p/xmlrpc-silverlight/的代码 我创建了新的 Silverlight 应用程序,我已将来自该链接的代码附加到该应用程序。当我启动执行我的 SL 应用程序的网站(在 localhost 中,端口为 1139)时,会发生 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。我很乐意提供所需的任何其他信息(或代码)。

【问题讨论】:

    标签: silverlight xml-rpc


    【解决方案1】:

    我怀疑这是缺少 clientaccesspolicy.xml 文件的情况。

    由于您的 silverlight 应用程序将从另一个授权机构启动,它会尝试访问此文件 http://localhost:5678/。由于您的小测试不支持该文件,Silverlight 会阻止此跨“域”活动。

    【讨论】:

    • 如何解决?我将 clientaccesspolicy.xml(具有最大权限 - 没有任何限制)文件放在 XML-RPC 控制台 exe 文件所在的 \bin 文件夹中。还是一样的错误。
    • @Bero:我对 HttpChannel 了解不多,但如果您的小测试应用程序能够神奇地开始像这样从 bin 文件夹中传送内容,我会感到惊讶。 Silverlight 可以进行这些 RPC,但它假定存在一些 Web 服务器的外观,因此除了发出 RPC 请求之外,它还可以发出其他请求,例如“给我你的 clientaccesspolicy.xml”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-17
    • 1970-01-01
    相关资源
    最近更新 更多