views:

283

answers:

1

I want to comunicate with Console XML RPC server from my silvelight application. Is it possibile?

Steps: 1. Start the Console XML RPC server

Code for Console XML RPC server is this:

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. Run Silverlight application I used the code from http://code.google.com/p/xmlrpc-silverlight/ I created new Silverlight application to which I have attached the code from that link. When I start web site (in localhost with port 1139) which executes my SL app happens 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
        {
         ...
        }
    }
    

I am using VS2008 Professional,XP Professional, .net 3.5, Silverlight3. I will gladly provide any additional information (or code) which is needed.

+1  A: 

I suspect that this is a case of a missing clientaccesspolicy.xml file.

Since your silverlight app will have been launched from another authority it will attempt to access this file the http://localhost:5678/. Since you little test doesn't support that file Silverlight blocks this cross "domain" activity.

AnthonyWJones
How to resolve that? I put clientaccesspolicy.xml (with maximum permission - there isn't any restriction) file in \bin folder where is XML-RPC console exe file. Still same error.
Bero
@Bero: I don't know much about HttpChannel but I'd be surpised if your little test app could magically start delivering content out of the bin folder like that. Silverlight can make these RPCs but it assumes some semblence of a web server be present so that in addition to making the RPC request it can make other requests like "gimme your clientaccesspolicy.xml".
AnthonyWJones