2

The Cook Computing blog has a post discussing how dynamics in .NET 4 could be used to create dynamic RPC calls. (Post: ALTERNATIVE SYNTAX FOR MEMBER CALLS ON C# DYNAMIC TYPES )

The post shows the following example:

using System.Dynamic;

class XmlRpcClient : DynamicObject
{
  string endpoint;

  public XmlRpcClient(string endpoint)
  {
    this.endpoint = endpoint;
  }

  public object Invoke(string methodName, object[] args)
  {
    return 5; // actually make call to XML-RPC endpoint here
  }

  public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, 
    out object result)
  {
    result = Invoke(binder.Name, args);
    return true;
  }
}

The part I don't understand is the comment stating "actually make call to XML-RPC endpoint here".

Is there a way to use the XML-RPC.NET library in the invoke method or would you need to make a HttpWebRequest call?

Thanks

Larry Hipp
  • 6,205
  • 3
  • 26
  • 31
  • What would be the purpose of using this? Aren't you calling an XML-RPC service that has statically-defined methods anyway? – mellamokb Jul 18 '11 at 16:06
  • When using the XML-RPC.NET library you must define an Interface that represents the service you are calling. I want to use dynamics because I will be calling multiple versions of the xml-rpc service. I'm trying to avoid having an Interface defined for each version of the service I will encounter. – Larry Hipp Jul 18 '11 at 16:44
  • I'm not sure with XML-RPC how you would be able to communicate with a service without the interface, because the interface handles the communication via the XmlRpcService superclass and the attributes decorating the methods. You would almost have to reverse engineer the library to see how it happens underneath, as you stated in your post, making your HttpWebRequest calls manually. – mellamokb Jul 18 '11 at 17:08

1 Answers1

2

When I wrote the post "Alternative Syntax…" dynamic support in C# had only just been announced so I was just describing a possible implementation to take advantage of these new features.

Implementing "actually make call to XML-RPC endpoint here" would require a call to the XmlRpcClientProtocol class though this class would need some minor modifications to be used in this way.

Charles Cook
  • 1,989
  • 1
  • 16
  • 7