35 |
public String GetReply( String assemblyName, String className, String methodName ) |
public String GetReply( String assemblyName, String className, String methodName ) |
36 |
{ |
{ |
37 |
|
|
|
XmlRpcStruct h = new XmlRpcStruct(); |
|
|
|
|
|
int i = 1; |
|
|
double d = 2.99; |
|
|
bool b = false; |
|
|
byte[] bytes = {0x00, 0x12, 0x34, 0x56, 0xAA, 0x55, 0xFF}; |
|
|
|
|
|
h["one"] = i; |
|
|
h["two"] = d; |
|
|
h["three"] = b; |
|
|
|
|
|
XmlRpcStruct h0 = new XmlRpcStruct(); |
|
|
h0["nested one"] = 11; |
|
|
h0["nested two"] = 22; |
|
|
h["A structure"] = h0; |
|
|
|
|
|
XmlRpcArray a = new XmlRpcArray(); |
|
|
a.Add( i ); |
|
|
a.Add( d ); |
|
|
a.Add( b ); |
|
|
a.Add( "some dodgy text"); |
|
|
a.Add( h0 ); |
|
|
a.Add( DateTime.Now ); |
|
|
a.Add( bytes ); |
|
|
h["An array"] = a; |
|
|
|
|
|
|
|
|
// use the XmlRpcWriter just like you would XmlTextWriter. In |
|
|
// fact it inherits XmlTextWriter but detection of invalid |
|
|
// states is not implemented yet. That'll come soon |
|
|
|
|
|
// Write a methodCall |
|
|
StringWriter sw; |
|
|
XmlRpcWriter writer; |
|
|
|
|
|
sw = new StringWriter(); |
|
|
writer = new XmlRpcWriter( sw ); |
|
|
writer.Formatting = Formatting.Indented; |
|
|
|
|
|
writer.WriteStartDocument(); |
|
|
writer.WriteMethodCall( "ThinkOfALady", a ); |
|
|
writer.WriteEndDocument(); |
|
|
sw.Flush(); |
|
|
string call = sw.ToString(); |
|
|
sw.Close(); |
|
|
// feed it into the reader to detect anomalies |
|
|
XmlRpcReader reader = new XmlRpcReader( call ); |
|
|
Console.Out.WriteLine( "XmlRpcReader: methodCall\n{0}", call ); |
|
|
sw = null; |
|
|
writer = null; |
|
|
|
|
|
// Write a methodResponse |
|
|
sw = new StringWriter(); |
|
|
writer = new XmlRpcWriter( sw ); |
|
|
writer.Formatting = Formatting.Indented; |
|
|
|
|
|
writer.WriteStartDocument(); |
|
|
writer.WriteMethodResponse( h ); |
|
|
writer.WriteEndDocument(); |
|
|
sw.Flush(); |
|
|
string reply = sw.ToString(); |
|
|
sw.Close(); |
|
|
reader = new XmlRpcReader( reply ); |
|
|
|
|
|
// Console.Out.WriteLine( "XmlRpcWriter\n{0}", reply ); |
|
|
Console.Out.WriteLine( "XmlRpcReader: methodResponse\n{0}", reply ); |
|
|
|
|
|
// Write an error |
|
|
sw = new StringWriter(); |
|
|
writer = new XmlRpcWriter( sw ); |
|
|
writer.Formatting = Formatting.Indented; |
|
|
|
|
|
writer.WriteStartDocument(); |
|
|
writer.WriteMethodResponse( new XmlRpcInvalidStateException( "Test Exception Thrown" )); |
|
|
writer.WriteEndDocument(); |
|
|
sw.Flush(); |
|
|
sw.Close(); |
|
|
Console.Out.WriteLine( "XmlRpcWriter: exception\n{0}", sw ); |
|
38 |
|
|
39 |
return "end"; |
return "end"; |
40 |
} |
} |