public void SerializeRequestNilParams() { var stm = new MemoryStream(); var req = new XmlRpcRequest(); req.Args = new Object[] { new object[] { 1, null, 2 } }; req.Method = "NilParamsMethod"; req.Mi = GetType().GetMethod("NilParamsMethod"); var ser = new XmlRpcRequestSerializer(); ser.Indentation = 4; ser.SerializeRequest(stm, req); stm.Position = 0; var tr = new StreamReader(stm); tr.ReadToEnd().ShouldBe( @"<?xml version=""1.0""?> <methodCall> <methodName>NilParamsMethod</methodName> <params> <param> <value> <i4>1</i4> </value> </param> <param> <value> <nil /> </value> </param> <param> <value> <i4>2</i4> </value> </param> </params> </methodCall>"); }
public void SerializeRequest() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[] { IntEnum.Two }; req.Method = "Foo"; var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>Foo</methodName> <params> <param> <value> <i4>2</i4> </value> </param> </params> </methodCall>", reqstr); }
public void SerializeObjectParams() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.args = new Object[] { new object[] { 1, "one" } }; req.method = "Foo"; req.mi = typeof(IFoo).GetMethod("Foo"); var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual( @"<?xml version=""1.0""?> <methodCall> <methodName>Foo</methodName> <params> <param> <value> <i4>1</i4> </value> </param> <param> <value> <string>one</string> </value> </param> </params> </methodCall>", reqstr); }
public void SerializeRequestWithEnumStringParam() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[] { IntEnum.Two }; req.Method = "EnumMethod1"; req.Mi = this.GetType().GetMethod("EnumMethod1"); var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>EnumMethod1</methodName> <params> <param> <value> <string>Two</string> </value> </param> </params> </methodCall>", reqstr); }
public void SerializeObjectParams() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[] { new object[] { 1, "one" } }; req.Method = "Foo"; req.Mi = typeof(IFoo).GetMethod("Foo"); var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>Foo</methodName> <params> <param> <value> <i4>1</i4> </value> </param> <param> <value> <string>one</string> </value> </param> </params> </methodCall>", reqstr); }
// private methods // void SerializeMessage( IMethodCallMessage mcm, ref ITransportHeaders headers, ref Stream stream) { ITransportHeaders reqHeaders = new TransportHeaders(); reqHeaders["__Uri"] = mcm.Uri; reqHeaders["Content-Type"] = "text/xml; charset=\"utf-8\""; reqHeaders["__RequestVerb"] = "POST"; MethodInfo mi = (MethodInfo)mcm.MethodBase; string methodName = GetRpcMethodName(mi); XmlRpcRequest xmlRpcReq = new XmlRpcRequest(methodName, mcm.InArgs); // TODO: possibly call GetRequestStream from next sink in chain? // TODO: SoapClientFormatter sink uses ChunkedStream - check why? Stream stm = new MemoryStream(); var serializer = new XmlRpcRequestSerializer(); serializer.SerializeRequest(stm, xmlRpcReq); stm.Position = 0; headers = reqHeaders; stream = stm; }
public void SerializeRequestNil() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.args = new Object[] { null, 1234567 }; req.method = "NilMethod"; req.mi = this.GetType().GetMethod("NilMethod"); var ser = new XmlRpcRequestSerializer(); ser.Indentation = 4; ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual( @"<?xml version=""1.0""?> <methodCall> <methodName>NilMethod</methodName> <params> <param> <value> <nil /> </value> </param> <param> <value> <i4>1234567</i4> </value> </param> </params> </methodCall>", reqstr); }
public void SerializeRequestNil() { var stm = new MemoryStream(); var req = new XmlRpcRequest(); req.Args = new Object[] { null, 1234567 }; req.Method = "NilMethod"; req.Mi = GetType().GetMethod("NilMethod"); var ser = new XmlRpcRequestSerializer(); ser.Indentation = 4; ser.SerializeRequest(stm, req); stm.Position = 0; var tr = new StreamReader(stm); tr.ReadToEnd().ShouldBe( @"<?xml version=""1.0""?> <methodCall> <methodName>NilMethod</methodName> <params> <param> <value> <nil /> </value> </param> <param> <value> <i4>1234567</i4> </value> </param> </params> </methodCall>"); }
public void SerializeWithMappingOnType() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[] { IntEnum.Four }; req.Method = "Bar"; var proxy = XmlRpcProxyGen.Create <TestMethods2>(); req.Mi = proxy.GetType().GetMethod("Bar"); var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>Bar</methodName> <params> <param> <value> <string>Four</string> </value> </param> </params> </methodCall>", reqstr); }
public void SerializeRequestStructArrayWithNil() { var stm = new MemoryStream(); var req = new XmlRpcRequest(); req.Args = new Object[] { new StructWithArray { ints = new int?[] { 1, null, 3 } } }; req.Method = "NilMethod"; req.Mi = GetType().GetMethod("NilMethod"); var ser = new XmlRpcRequestSerializer(); ser.Indentation = 4; ser.SerializeRequest(stm, req); stm.Position = 0; var tr = new StreamReader(stm); tr.ReadToEnd().ShouldBe( @"<?xml version=""1.0""?> <methodCall> <methodName>NilMethod</methodName> <params> <param> <value> <struct> <member> <name>ints</name> <value> <array> <data> <value> <i4>1</i4> </value> <value> <nil /> </value> <value> <i4>3</i4> </value> </data> </array> </value> </member> </struct> </value> </param> </params> </methodCall>"); }
public void DateTimeLocales() { var oldci = Thread.CurrentThread.CurrentCulture; try { Should.NotThrow(() => { foreach (var locale in Utils.GetLocales()) { var ci = new CultureInfo(locale); Thread.CurrentThread.CurrentCulture = ci; if (ci.LCID == 0x401 || // ar-SA (Arabic - Saudi Arabia) ci.LCID == 0x465 || // div-MV (Dhivehi - Maldives) ci.LCID == 0x41e) // th-TH (Thai - Thailand) { break; } var dt = new DateTime(1900, 01, 02, 03, 04, 05); while (dt < DateTime.Now) { var stm = new MemoryStream(); var req = new XmlRpcRequest(); req.Args = new object[] { dt }; req.Method = "Foo"; var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; var deserializer = new XmlRpcRequestDeserializer(); var request = deserializer.DeserializeRequest(stm, null); request.Args[0].ShouldBeOfType <DateTime>(); var dt0 = (DateTime)request.Args[0]; dt0.ShouldBe(dt, "DateTime argument 0"); dt += new TimeSpan(100, 1, 1, 1); } } }); } finally { Thread.CurrentThread.CurrentCulture = oldci; } }
public void SerializeMassimo() { object[] param1 = new object[] { "test/Gain1", "Gain", 1, 1, new[] { 0.5 } }; object[] param2 = new object[] { "test/METER", "P1", 1, 1, new[] { -1.0 } }; Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[] { "IFTASK", new object[] { param1, param2 } }; req.Method = "Send_Param"; req.Mi = this.GetType().GetMethod("Send_Param"); var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(massimoRequest, reqstr); }
public void SerializeRequestArrayWithNull() { var stm = new MemoryStream(); var req = new XmlRpcRequest(); var array = new [] { "AAA", null, "CCC" }; req.Args = new Object[] { array }; req.Method = "ArrayMethod"; req.Mi = GetType().GetMethod("ArrayMethod"); var ser = new XmlRpcRequestSerializer(); ser.Indentation = 4; ser.SerializeRequest(stm, req); stm.Position = 0; var tr = new StreamReader(stm); tr.ReadToEnd().ShouldBe( @"<?xml version=""1.0""?> <methodCall> <methodName>ArrayMethod</methodName> <params> <param> <value> <array> <data> <value> <string>AAA</string> </value> <value> <nil /> </value> <value> <string>CCC</string> </value> </data> </array> </value> </param> </params> </methodCall>"); }
public void SerializeRequestStructWithNil() { var stm = new MemoryStream(); var req = new XmlRpcRequest(); req.Args = new Object[] { new Bounds() }; req.Method = "NilMethod"; req.Mi = GetType().GetMethod("NilMethod"); var ser = new XmlRpcRequestSerializer(); ser.Indentation = 4; ser.SerializeRequest(stm, req); stm.Position = 0; var tr = new StreamReader(stm); tr.ReadToEnd().ShouldBe( @"<?xml version=""1.0""?> <methodCall> <methodName>NilMethod</methodName> <params> <param> <value> <struct> <member> <name>lowerBound</name> <value> <nil /> </value> </member> <member> <name>upperBound</name> <value> <nil /> </value> </member> </struct> </value> </param> </params> </methodCall>"); }
public void SerializeZeroParametersNoParams() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[0]; req.Method = "FooZeroParameters"; req.Mi = typeof(IFoo).GetMethod("FooZeroParameters"); var ser = new XmlRpcRequestSerializer(); ser.UseEmptyParamsTag = false; ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>FooZeroParameters</methodName> </methodCall>", reqstr); }
public void Class() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); TestClass arg = new TestClass(); arg._int = 456; arg._string = "Test Class"; req.Args = new object[] { arg }; req.Method = "Foo"; var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>Foo</methodName> <params> <param> <value> <struct> <member> <name>_int</name> <value> <i4>456</i4> </value> </member> <member> <name>_string</name> <value> <string>Test Class</string> </value> </member> </struct> </value> </param> </params> </methodCall>", reqstr); }
public void SerializeIntNoParams() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[] { new[] { 1, 2, 3 } }; req.Method = "BarNotParams"; req.Mi = typeof(IFoo).GetMethod("BarNotParams"); var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>BarNotParams</methodName> <params> <param> <value> <array> <data> <value> <i4>1</i4> </value> <value> <i4>2</i4> </value> <value> <i4>3</i4> </value> </data> </array> </value> </param> </params> </methodCall>", reqstr); }
public void NoParams2() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[0]; req.Method = "system.pid"; req.Mi = this.GetType().GetMethod("getPid"); var ser = new XmlRpcRequestSerializer(); ser.Indentation = 2; ser.UseIntTag = true; ser.UseEmptyParamsTag = false; ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>system.pid</methodName> </methodCall>", reqstr); }
public void SerializeIntNoParams() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.args = new object[] { new int[] { 1, 2, 3 } }; req.method = "BarNotParams"; req.mi = typeof(IFoo).GetMethod("BarNotParams"); var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual( @"<?xml version=""1.0""?> <methodCall> <methodName>BarNotParams</methodName> <params> <param> <value> <array> <data> <value> <i4>1</i4> </value> <value> <i4>2</i4> </value> <value> <i4>3</i4> </value> </data> </array> </value> </param> </params> </methodCall>", reqstr); }
public void SerializeRequestStructArrayWithNil() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.args = new Object[] { new StructWithArray { ints = new int?[] { 1, null, 3 } } }; req.method = "NilMethod"; req.mi = this.GetType().GetMethod("NilMethod"); var ser = new XmlRpcRequestSerializer(); ser.Indentation = 4; ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual( @"<?xml version=""1.0""?> <methodCall> <methodName>NilMethod</methodName> <params> <param> <value> <struct> <member> <name>ints</name> <value> <array> <data> <value> <i4>1</i4> </value> <value> <nil /> </value> <value> <i4>3</i4> </value> </data> </array> </value> </member> </struct> </value> </param> </params> </methodCall>", reqstr); }
public void StructParamsWithParams() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[] { 1234, "test", new[] { 10.1 } }; req.Method = "FooWithParams"; req.Mi = this.GetType().GetMethod("FooWithParams"); var ser = new XmlRpcRequestSerializer(); ser.Indentation = 2; ser.UseIntTag = true; ser.SerializeRequest(stm, req); }
public object Invoke( Object clientObj, MethodInfo mi, params object[] parameters) { #if (SILVERLIGHT) throw new NotSupportedException(); #else _responseHeaders = null; _responseCookies = null; WebRequest webReq = null; object reto = null; try { string useUrl = GetEffectiveUrl(clientObj); webReq = GetWebRequest(new Uri(useUrl)); XmlRpcRequest req = MakeXmlRpcRequest(webReq, mi, parameters, clientObj, _xmlRpcMethod, _id); SetProperties(webReq); SetRequestHeaders(Headers, webReq); #if (!COMPACT_FRAMEWORK) SetClientCertificates(ClientCertificates, webReq); #endif Stream serStream = null; Stream reqStream = null; bool logging = (RequestEvent != null); if (!logging) { serStream = reqStream = webReq.GetRequestStream(); } else { serStream = new MemoryStream(2000); } try { var serializer = new XmlRpcRequestSerializer(XmlRpcFormatSettings); serializer.SerializeRequest(serStream, req); if (logging) { reqStream = webReq.GetRequestStream(); serStream.Position = 0; Util.CopyStream(serStream, reqStream); reqStream.Flush(); serStream.Position = 0; OnRequest(new XmlRpcRequestEventArgs(req.proxyId, req.number, serStream)); } } finally { if (reqStream != null) { reqStream.Close(); } } HttpWebResponse webResp = GetWebResponse(webReq) as HttpWebResponse; _responseCookies = webResp.Cookies; _responseHeaders = webResp.Headers; Stream respStm = null; Stream deserStream; logging = (ResponseEvent != null); try { respStm = webResp.GetResponseStream(); #if (!COMPACT_FRAMEWORK && !FX1_0) respStm = MaybeDecompressStream((HttpWebResponse)webResp, respStm); #endif if (!logging) { deserStream = respStm; } else { deserStream = new MemoryStream(2000); Util.CopyStream(respStm, deserStream); deserStream.Flush(); deserStream.Position = 0; } if (logging) { OnResponse(new XmlRpcResponseEventArgs(req.proxyId, req.number, deserStream)); deserStream.Position = 0; } XmlRpcResponse resp = ReadResponse(req, webResp, deserStream); reto = resp.retVal; } finally { if (respStm != null) { respStm.Close(); } } } finally { if (webReq != null) { webReq = null; } } return(reto); #endif }
public void LFString() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[] { "\n" }; req.Method = "Foo"; var ser = new XmlRpcRequestSerializer(); ser.UseStringTag = true; ser.Indentation = 4; ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>Foo</methodName> <params> <param> <value> " + "<string>\n</string>" + @" </value> </param> </params> </methodCall>", reqstr); }
public void RecursiveMemberTest() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); var example = new RecursiveMember { Level = "1", childExample = new RecursiveMember { Level = "2", childExample = new RecursiveMember { Level = "3", } } }; req.Args = new object[] { example }; req.Method = "Foo"; var ser = new XmlRpcRequestSerializer(); ser.UseStringTag = false; ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>Foo</methodName> <params> <param> <value> <struct> <member> <name>Level</name> <value>1</value> </member> <member> <name>childExample</name> <value> <struct> <member> <name>Level</name> <value>2</value> </member> <member> <name>childExample</name> <value> <struct> <member> <name>Level</name> <value>3</value> </member> </struct> </value> </member> </struct> </value> </member> </struct> </value> </param> </params> </methodCall>", reqstr); }
public void PropertyMemberName() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[] { new TestPropertyMemberName { Title1 = "abc", Title2 = "def" } }; req.Method = "Foo"; var ser = new XmlRpcRequestSerializer(); ser.UseStringTag = true; ser.Indentation = 2; ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>Foo</methodName> <params> <param> <value> <struct> <member> <name>title2</name> <value> <string>def</string> </value> </member> <member> <name>title1</name> <value> <string>abc</string> </value> </member> </struct> </value> </param> </params> </methodCall>", reqstr); }
public void NullMappingNil() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[] { new NullMappingNilStruct() }; req.Method = "Foo"; var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>Foo</methodName> <params> <param> <value> <struct> <member> <name>s</name> <value> <nil /> </value> </member> <member> <name>i</name> <value> <nil /> </value> </member> </struct> </value> </param> </params> </methodCall>", reqstr); }
public void ZeroLengthBas64() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[] { new byte[0] }; req.Method = "Foo"; var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>Foo</methodName> <params> <param> <value> <base64 /> </value> </param> </params> </methodCall>", reqstr); }
public void SerializeWithMappingOnInterface() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.args = new Object[] { IntEnum.Zero, new IntEnum[] { IntEnum.One, IntEnum.Two }, new ItfEnumClass { IntEnum = ItfEnum.One, intEnum = ItfEnum.Two, IntEnums = new ItfEnum[] { ItfEnum.One, ItfEnum.Two }, intEnums = new ItfEnum[] { ItfEnum.Three, ItfEnum.Four }, } }; req.method = "MappingOnMethod"; req.mi = this.GetType().GetMethod("MappingOnMethod"); var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual( @"<?xml version=""1.0""?> <methodCall> <methodName>MappingOnMethod</methodName> <params> <param> <value> <string>Zero</string> </value> </param> <param> <value> <array> <data> <value> <string>One</string> </value> <value> <string>Two</string> </value> </data> </array> </value> </param> <param> <value> <struct> <member> <name>IntEnum</name> <value> <string>One</string> </value> </member> <member> <name>IntEnums</name> <value> <array> <data> <value> <string>One</string> </value> <value> <string>Two</string> </value> </data> </array> </value> </member> <member> <name>intEnum</name> <value> <string>Two</string> </value> </member> <member> <name>intEnums</name> <value> <array> <data> <value> <string>Three</string> </value> <value> <string>Four</string> </value> </data> </array> </value> </member> </struct> </value> </param> </params> </methodCall>", reqstr); }
public void DefaultFormatting() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[] { 1234567 }; req.Method = "Foo"; var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>Foo</methodName> <params> <param> <value> <i4>1234567</i4> </value> </param> </params> </methodCall>", reqstr); }
static void GetRequestStreamCallback(IAsyncResult asyncResult) { XmlRpcAsyncResult clientResult = (XmlRpcAsyncResult)asyncResult.AsyncState; clientResult.CompletedSynchronously = asyncResult.CompletedSynchronously; try { Stream serStream = null; Stream reqStream = null; bool logging = (clientResult.ClientProtocol.RequestEvent != null); if (!logging) { serStream = reqStream = clientResult.Request.EndGetRequestStream(asyncResult); } else { serStream = new MemoryStream(2000); } try { XmlRpcRequest req = clientResult.XmlRpcRequest; var serializer = new XmlRpcRequestSerializer(); if (clientResult.XmlRpcFormatSettings.XmlEncoding != null) { serializer.XmlEncoding = clientResult.XmlRpcFormatSettings.XmlEncoding; } serializer.UseEmptyElementTags = clientResult.XmlRpcFormatSettings.UseEmptyElementTags; serializer.UseEmptyParamsTag = clientResult.XmlRpcFormatSettings.UseEmptyParamsTag; serializer.UseIndentation = clientResult.XmlRpcFormatSettings.UseIndentation; serializer.Indentation = clientResult.XmlRpcFormatSettings.Indentation; serializer.UseIntTag = clientResult.XmlRpcFormatSettings.UseIntTag; serializer.UseStringTag = clientResult.XmlRpcFormatSettings.UseStringTag; serializer.SerializeRequest(serStream, req); if (logging) { reqStream = clientResult.Request.EndGetRequestStream(asyncResult); serStream.Position = 0; Util.CopyStream(serStream, reqStream); reqStream.Flush(); serStream.Position = 0; clientResult.ClientProtocol.OnRequest( new XmlRpcRequestEventArgs(req.proxyId, req.number, serStream)); } } finally { if (reqStream != null) { reqStream.Close(); } } clientResult.Request.BeginGetResponse( new AsyncCallback(GetResponseCallback), clientResult); } catch (Exception ex) { ProcessAsyncException(clientResult, ex); } }
/// <summary> /// /// </summary> /// <param name="clientObj"></param> /// <param name="mi"></param> /// <param name="parameters"></param> /// <returns></returns> public object Invoke( Object clientObj, MethodInfo mi, params object[] parameters) { #if (SILVERLIGHT) throw new NotSupportedException(); #else #if (!COMPACT_FRAMEWORK) _responseHeaders = null; _responseCookies = null; #endif WebRequest webReq = null; object reto = null; try { string useUrl = GetEffectiveUrl(clientObj); webReq = GetWebRequest(new Uri(useUrl)); XmlRpcRequest req = MakeXmlRpcRequest(webReq, mi, parameters, clientObj, _xmlRpcMethod, _id); SetProperties(webReq); SetRequestHeaders(Headers, webReq); #if (!COMPACT_FRAMEWORK) SetClientCertificates(ClientCertificates, webReq); #endif Stream serStream = null; Stream reqStream = null; bool logging = (RequestEvent != null); if (!logging) serStream = reqStream = webReq.GetRequestStream(); else serStream = new MemoryStream(2000); try { var serializer = new XmlRpcRequestSerializer(XmlRpcFormatSettings); serializer.SerializeRequest(serStream, req); if (logging) { reqStream = webReq.GetRequestStream(); serStream.Position = 0; Util.CopyStream(serStream, reqStream); reqStream.Flush(); serStream.Position = 0; OnRequest(new XmlRpcRequestEventArgs(req.proxyId, req.number, serStream)); } } finally { if (reqStream != null) reqStream.Close(); } HttpWebResponse webResp = GetWebResponse(webReq) as HttpWebResponse; #if (!COMPACT_FRAMEWORK) _responseCookies = webResp.Cookies; _responseHeaders = webResp.Headers; #endif Stream respStm = null; Stream deserStream; logging = (ResponseEvent != null); try { respStm = webResp.GetResponseStream(); if (!logging) { deserStream = respStm; } else { deserStream = new MemoryStream(2000); Util.CopyStream(respStm, deserStream); deserStream.Flush(); deserStream.Position = 0; } #if (!COMPACT_FRAMEWORK && !FX1_0) deserStream = MaybeDecompressStream((HttpWebResponse)webResp, deserStream); #endif if (logging) { OnResponse(new XmlRpcResponseEventArgs(req.proxyId, req.number, deserStream)); deserStream.Position = 0; } XmlRpcResponse resp = ReadResponse(req, webResp, deserStream); reto = resp.retVal; } finally { if (respStm != null) respStm.Close(); } } finally { if (webReq != null) webReq = null; } return reto; #endif }
public void SerializeMassimo() { object[] param1 = new object[] { "test/Gain1", "Gain", 1, 1, new double[] { 0.5 } }; object[] param2 = new object[] { "test/METER", "P1", 1, 1, new double[] { -1.0 } }; Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.args = new Object[] { "IFTASK", new object[] { param1, param2 } }; req.method = "Send_Param"; req.mi = this.GetType().GetMethod("Send_Param"); var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(massimoRequest, reqstr); }
public void StructParams() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[] { 1234, "test", 10.1 }; req.Method = "Foo"; req.Mi = this.GetType().GetMethod("Foo"); var ser = new XmlRpcRequestSerializer(); ser.Indentation = 2; ser.UseIntTag = true; ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>Foo</methodName> <params> <param> <value> <struct> <member> <name>x</name> <value> <int>1234</int> </value> </member> <member> <name>y</name> <value> <string>test</string> </value> </member> <member> <name>z</name> <value> <double>10.1</double> </value> </member> </struct> </value> </param> </params> </methodCall>", reqstr); }
public void XmlRpcMember() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[] { new Struct2 { member1 = 1, member4 = 4 } }; req.Method = "Foo"; var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>Foo</methodName> <params> <param> <value> <struct> <member> <name>member_4</name> <value> <i4>4</i4> </value> </member> <member> <name>member_1</name> <value> <i4>1</i4> </value> </member> </struct> </value> </param> </params> </methodCall>", reqstr); }
public void SerializeRequest() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.args = new Object[] { IntEnum.Two }; req.method = "Foo"; var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual( @"<?xml version=""1.0""?> <methodCall> <methodName>Foo</methodName> <params> <param> <value> <i4>2</i4> </value> </param> </params> </methodCall>", reqstr); }
public void StructParamsGetInfo() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[] { "Bob Dylan", "abcd1234" }; req.Method = "artist.getInfo"; req.Mi = this.GetType().GetMethod("getInfo"); var ser = new XmlRpcRequestSerializer(); ser.Indentation = 2; ser.UseIntTag = true; ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>artist.getInfo</methodName> <params> <param> <value> <struct> <member> <name>artist</name> <value> <string>Bob Dylan</string> </value> </member> <member> <name>api_key</name> <value> <string>abcd1234</string> </value> </member> </struct> </value> </param> </params> </methodCall>", reqstr); }
public void DateTimeLocales() { CultureInfo oldci = Thread.CurrentThread.CurrentCulture; try { foreach (string locale in Utils.GetLocales()) { try { CultureInfo ci = new CultureInfo(locale); Thread.CurrentThread.CurrentCulture = ci; if (ci.LCID == 0x401 // ar-SA (Arabic - Saudi Arabia) || ci.LCID == 0x465 // div-MV (Dhivehi - Maldives) || ci.LCID == 0x41e) // th-TH (Thai - Thailand) break; DateTime dt = new DateTime(1900, 01, 02, 03, 04, 05); while (dt < DateTime.Now) { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.args = new Object[] { dt }; req.method = "Foo"; var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; var deserializer = new XmlRpcRequestDeserializer(); XmlRpcRequest request = deserializer.DeserializeRequest(stm, null); Assert.IsTrue(request.args[0] is DateTime, "argument is DateTime"); DateTime dt0 = (DateTime)request.args[0]; Assert.AreEqual(dt0, dt, "DateTime argument 0"); dt += new TimeSpan(100, 1, 1, 1); } } catch (Exception ex) { Assert.Fail(String.Format("unexpected exception {0}: {1}", locale, ex.Message)); } } } finally { Thread.CurrentThread.CurrentCulture = oldci; } }
public void SerializeRequestArrayWithNull() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); string[] array = new string[] { "AAA", null, "CCC" }; req.args = new Object[] { array }; req.method = "ArrayMethod"; req.mi = this.GetType().GetMethod("ArrayMethod"); var ser = new XmlRpcRequestSerializer(); ser.Indentation = 4; ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual( @"<?xml version=""1.0""?> <methodCall> <methodName>ArrayMethod</methodName> <params> <param> <value> <array> <data> <value> <string>AAA</string> </value> <value> <nil /> </value> <value> <string>CCC</string> </value> </data> </array> </value> </param> </params> </methodCall>", reqstr); }
public void NonSerializedWithInvalidType() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[] { new Struct5 { ds = new System.Data.DataSet(), y = 1234 } }; req.Method = "Foo"; var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual(@"<?xml version=""1.0""?> <methodCall> <methodName>Foo</methodName> <params> <param> <value> <struct> <member> <name>y</name> <value> <i4>1234</i4> </value> </member> </struct> </value> </param> </params> </methodCall>", reqstr); }
public void SerializeZeroParametersNoParams() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.args = new Object[0]; req.method = "FooZeroParameters"; req.mi = typeof(IFoo).GetMethod("FooZeroParameters"); var ser = new XmlRpcRequestSerializer(); ser.UseEmptyParamsTag = false; ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual( @"<?xml version=""1.0""?> <methodCall> <methodName>FooZeroParameters</methodName> </methodCall>", reqstr); }
public void NoIndentation() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new object[] { 1234567 }; req.Method = "Foo"; var ser = new XmlRpcRequestSerializer(); ser.UseIndentation = false; ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual( "<?xml version=\"1.0\"?><methodCall><methodName>Foo</methodName>" + "<params><param><value><i4>1234567</i4></value></param></params>" + "</methodCall>", reqstr); }
public void SerializeWithMappingOnType() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.args = new object[] { IntEnum.Four }; req.method = "Bar"; var proxy = XmlRpcProxyGen.Create<TestMethods2>(); req.mi = proxy.GetType().GetMethod("Bar"); var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual( @"<?xml version=""1.0""?> <methodCall> <methodName>Bar</methodName> <params> <param> <value> <string>Four</string> </value> </param> </params> </methodCall>", reqstr); }
public void SerializeWithMappingOnInterface() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.Args = new Object[] { IntEnum.Zero, new IntEnum[] { IntEnum.One, IntEnum.Two }, new ItfEnumClass { IntEnum = ItfEnum.One, intEnum = ItfEnum.Two, IntEnums = new ItfEnum[] { ItfEnum.One, ItfEnum.Two }, intEnums = new ItfEnum[] { ItfEnum.Three, ItfEnum.Four }, } }; req.Method = "MappingOnMethod"; req.Mi = this.GetType().GetMethod("MappingOnMethod"); var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual( @"<?xml version=""1.0""?> <methodCall> <methodName>MappingOnMethod</methodName> <params> <param> <value> <string>Zero</string> </value> </param> <param> <value> <array> <data> <value> <string>One</string> </value> <value> <string>Two</string> </value> </data> </array> </value> </param> <param> <value> <struct> <member> <name>IntEnum</name> <value> <string>One</string> </value> </member> <member> <name>IntEnums</name> <value> <array> <data> <value> <string>One</string> </value> <value> <string>Two</string> </value> </data> </array> </value> </member> <member> <name>intEnum</name> <value> <string>Two</string> </value> </member> <member> <name>intEnums</name> <value> <array> <data> <value> <string>Three</string> </value> <value> <string>Four</string> </value> </data> </array> </value> </member> </struct> </value> </param> </params> </methodCall>", reqstr); }
static void GetRequestStreamCallback(IAsyncResult asyncResult) { XmlRpcAsyncResult clientResult = (XmlRpcAsyncResult)asyncResult.AsyncState; clientResult.CompletedSynchronously = asyncResult.CompletedSynchronously; try { Stream serStream = null; Stream reqStream = null; bool logging = (clientResult.ClientProtocol.RequestEvent != null); if (!logging) { serStream = reqStream = clientResult.Request.EndGetRequestStream(asyncResult); } else serStream = new MemoryStream(2000); try { XmlRpcRequest req = clientResult.XmlRpcRequest; var serializer = new XmlRpcRequestSerializer(); if (clientResult.XmlRpcFormatSettings.XmlEncoding != null) serializer.XmlEncoding = clientResult.XmlRpcFormatSettings.XmlEncoding; serializer.UseEmptyElementTags = clientResult.XmlRpcFormatSettings.UseEmptyElementTags; serializer.UseEmptyParamsTag = clientResult.XmlRpcFormatSettings.UseEmptyParamsTag; serializer.UseIndentation = clientResult.XmlRpcFormatSettings.UseIndentation; serializer.Indentation = clientResult.XmlRpcFormatSettings.Indentation; serializer.UseIntTag = clientResult.XmlRpcFormatSettings.UseIntTag; serializer.UseStringTag = clientResult.XmlRpcFormatSettings.UseStringTag; serializer.SerializeRequest(serStream, req); if (logging) { reqStream = clientResult.Request.EndGetRequestStream(asyncResult); serStream.Position = 0; Util.CopyStream(serStream, reqStream); reqStream.Flush(); serStream.Position = 0; clientResult.ClientProtocol.OnRequest( new XmlRpcRequestEventArgs(req.proxyId, req.number, serStream)); } } finally { if (reqStream != null) reqStream.Close(); } clientResult.Request.BeginGetResponse( new AsyncCallback(GetResponseCallback), clientResult); } catch (Exception ex) { ProcessAsyncException(clientResult, ex); } }
public void SerializeRequestWithEnumStringParam() { Stream stm = new MemoryStream(); XmlRpcRequest req = new XmlRpcRequest(); req.args = new Object[] { IntEnum.Two }; req.method = "EnumMethod1"; req.mi = this.GetType().GetMethod("EnumMethod1"); var ser = new XmlRpcRequestSerializer(); ser.SerializeRequest(stm, req); stm.Position = 0; TextReader tr = new StreamReader(stm); string reqstr = tr.ReadToEnd(); Assert.AreEqual( @"<?xml version=""1.0""?> <methodCall> <methodName>EnumMethod1</methodName> <params> <param> <value> <string>Two</string> </value> </param> </params> </methodCall>", reqstr); }