diff options
Renamed the new Directories. (removed the "-Source" from the end of them)
Diffstat (limited to 'Common/XmlRpcCS/XmlRpcClientProxy.cs')
-rw-r--r-- | Common/XmlRpcCS/XmlRpcClientProxy.cs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Common/XmlRpcCS/XmlRpcClientProxy.cs b/Common/XmlRpcCS/XmlRpcClientProxy.cs new file mode 100644 index 0000000..f52273a --- /dev/null +++ b/Common/XmlRpcCS/XmlRpcClientProxy.cs | |||
@@ -0,0 +1,61 @@ | |||
1 | namespace Nwc.XmlRpc | ||
2 | { | ||
3 | using System; | ||
4 | using System.Runtime.Remoting.Proxies; | ||
5 | using System.Runtime.Remoting.Messaging; | ||
6 | |||
7 | /// <summary>This class provides support for creating local proxies of XML-RPC remote objects</summary> | ||
8 | /// <remarks> | ||
9 | /// To create a local proxy you need to create a local C# interface and then, via <i>createProxy</i> | ||
10 | /// associate that interface with a remote object at a given URL. | ||
11 | /// </remarks> | ||
12 | public class XmlRpcClientProxy : RealProxy | ||
13 | { | ||
14 | private String _remoteObjectName; | ||
15 | private String _url; | ||
16 | private XmlRpcRequest _client = new XmlRpcRequest(); | ||
17 | |||
18 | /// <summary>Factory method to create proxies.</summary> | ||
19 | /// <remarks> | ||
20 | /// To create a local proxy you need to create a local C# interface with methods that mirror those of the server object. | ||
21 | /// Next, pass that interface into <c>createProxy</c> along with the object name and URL of the remote object and | ||
22 | /// cast the resulting object to the specifice interface. | ||
23 | /// </remarks> | ||
24 | /// <param name="remoteObjectName"><c>String</c> The name of the remote object.</param> | ||
25 | /// <param name="url"><c>String</c> The URL of the remote object.</param> | ||
26 | /// <param name="anInterface"><c>Type</c> The typeof() of a C# interface.</param> | ||
27 | /// <returns><c>Object</c> A proxy for your specified interface. Cast to appropriate type.</returns> | ||
28 | public static Object createProxy(String remoteObjectName, String url, Type anInterface) | ||
29 | { | ||
30 | return new XmlRpcClientProxy(remoteObjectName, url, anInterface).GetTransparentProxy(); | ||
31 | } | ||
32 | |||
33 | private XmlRpcClientProxy(String remoteObjectName, String url, Type t) : base(t) | ||
34 | { | ||
35 | _remoteObjectName = remoteObjectName; | ||
36 | _url = url; | ||
37 | } | ||
38 | |||
39 | /// <summary>The local method dispatcher - do not invoke.</summary> | ||
40 | override public IMessage Invoke(IMessage msg) | ||
41 | { | ||
42 | IMethodCallMessage methodMessage = (IMethodCallMessage)msg; | ||
43 | |||
44 | _client.MethodName = _remoteObjectName + "." + methodMessage.MethodName; | ||
45 | _client.Params.Clear(); | ||
46 | foreach (Object o in methodMessage.Args) | ||
47 | _client.Params.Add(o); | ||
48 | |||
49 | try | ||
50 | { | ||
51 | Object ret = _client.Invoke(_url); | ||
52 | return new ReturnMessage(ret,null,0, | ||
53 | methodMessage.LogicalCallContext, methodMessage); | ||
54 | } | ||
55 | catch (Exception e) | ||
56 | { | ||
57 | return new ReturnMessage(e, methodMessage); | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | } | ||