26 |
*/ |
*/ |
27 |
using System; |
using System; |
28 |
using System.IO; |
using System.IO; |
29 |
|
using DotGNU.XmlRpc.Serialization.Formatters; |
30 |
|
using DotGNU.XmlRpc; |
31 |
|
|
32 |
namespace DotGNU.DGEE.Protocols |
namespace DotGNU.DGEE.Protocols |
33 |
{ |
{ |
34 |
public class XmlRpcProtocolHandler : IProtocolHandler |
public class XmlRpcProtocolHandler : IProtocolHandler |
35 |
{ |
{ |
36 |
|
MethodCallFormatter requestFormat = new MethodCallFormatter(); |
37 |
|
MethodResponseFormatter replyFormat = new MethodResponseFormatter(); |
38 |
|
|
39 |
public object Request( StreamReader input ) |
public object Request( StreamReader input ) |
40 |
{ |
{ |
|
string buf = input.ReadToEnd(); |
|
|
|
|
41 |
// Handle any incoming request |
// Handle any incoming request |
42 |
Console.Out.WriteLine( ">>> Request: {0}", buf ); |
Console.Out.WriteLine( ">>> Request" ); |
43 |
|
|
44 |
// Determine the method from the protocol |
// Determine the method from the protocol |
45 |
Console.Out.WriteLine( "--- Deserialising" ); |
Console.Out.WriteLine( "--- Deserialising Request" ); |
46 |
|
XmlRpcMethod method = (XmlRpcMethod)requestFormat.Deserialize( input.BaseStream ); |
47 |
|
|
48 |
return buf; |
return method; |
49 |
} |
} |
50 |
|
|
51 |
public object Invoke( object o ) |
public object Invoke( object o ) |
52 |
{ |
{ |
53 |
// Invoke the method |
// Invoke the method |
54 |
Console.Out.WriteLine( "--- Invoking" ); |
Console.Out.WriteLine( "--- Invoking Requested Method" ); |
55 |
|
//Console.Out.WriteLine( o ); |
56 |
return "Hello NPG!!! I've been invoked. yes yes yessss!"; |
|
57 |
|
XmlRpcResponse resp = new XmlRpcResponse(); |
58 |
|
int i = 1234567890; |
59 |
|
resp.Add( i ); |
60 |
|
return resp; |
61 |
} |
} |
62 |
|
|
63 |
public void Error( Stream output ) |
public void Error( Stream output ) |
66 |
|
|
67 |
public void Response( StreamWriter output, object o ) |
public void Response( StreamWriter output, object o ) |
68 |
{ |
{ |
|
output.Write( o ); |
|
|
|
|
69 |
// Serialise the result of the method |
// Serialise the result of the method |
70 |
Console.Out.WriteLine( "--- Serialising: {0}", o ); |
Console.Out.WriteLine( "--- Serialising Response" ); |
71 |
|
|
72 |
|
replyFormat.Serialize( output.BaseStream, (XmlRpcResponse)o ); |
73 |
|
|
74 |
// Send it back to the client |
// Send it back to the client |
75 |
Console.Out.WriteLine( "<<< Response" ); |
Console.Out.WriteLine( "<<< Response" ); |
76 |
} |
} |