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 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 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 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 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 object Invoke(MethodInfo methodInfo, params object[] parameters) { var request = XmlRpcClientProtocol.MakeXmlRpcRequest(methodInfo, parameters); using var memoryStream = new MemoryStream(); var serializer = new XmlRpcRequestSerializer(Configuration); serializer.SerializeRequest(memoryStream, request); memoryStream.Seek(0, SeekOrigin.Begin); using var requestMessage = new HttpRequestMessage() { Method = HttpMethod.Post, Content = new StreamContent(memoryStream) }; using var response = _client.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult(); response.EnsureSuccessStatusCode(); using var responseStream = response.Content.ReadAsStreamAsync().ConfigureAwait(false).GetAwaiter().GetResult(); var deserializer = new XmlRpcResponseDeserializer(Configuration); var responseAnswer = deserializer.DeserializeResponse(responseStream, request.MethodInfo.ReturnType); return(responseAnswer.ReturnValue); }
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 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 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 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 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 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 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); }