示例#1
0
        public void DeserializeObjectParams1()
        {
            string        xml        = @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Foo1</methodName>
  <params>
    <param>
      <value>
        <i4>5678</i4>
      </value>
    </param>
    <param>
      <value>
        <i4>1</i4>
      </value>
    </param>
    <param>
      <value>
        <string>one</string>
      </value>
    </param>
  </params>
</methodCall>";
            StringReader  sr         = new StringReader(xml);
            var           serializer = new XmlRpcRequestDeserializer();
            XmlRpcRequest request    = serializer.DeserializeRequest(sr, this.GetType());

            Assert.AreEqual(request.Method, "Foo1", "method is Foo");
            Assert.AreEqual((int)request.Args[0], 5678, "first argument is int");
            Assert.AreEqual(request.Args[1].GetType(), typeof(object[]), "argument is object[]");
            Assert.AreEqual(
                (object[])request.Args[1],
                new object[] { 1, "one" },
                "second argument is params array 1, \"one\"");
        }
示例#2
0
        public void TooManyParameters()
        {
            string xml = @"<?xml version=""1.0""?>
<methodCall>
<methodName>blogger.getUsersBlogs</methodName>
<params>
<param>
<value>
<string>ffffffabffffffce6dffffff93ffffffac29ffffffc9fffffff826ffffffdefffff
fc9ff\
ffffe43c0b763036ffffffa0fffffff3ffffffa963377716</string>
</value>
</param>
<param>
<value>
<string>myusername</string>
</value>
</param>
<param>
<value>
<string>mypassword</string>
</value>
</param>
</params>
</methodCall>";

            StringReader  sr           = new StringReader(xml);
            var           deserializer = new XmlRpcRequestDeserializer();
            XmlRpcRequest request      = deserializer.DeserializeRequest(sr, GetType());
        }
示例#3
0
        public void DeserializeObjectInvalidParams()
        {
            string       xml          = @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Bar</methodName>
  <params>
    <param>
      <value>
        <string>string one</string>
      </value>
    </param>
    <param>
      <value>
        <i4>2</i4>
      </value>
    </param>
  </params>
</methodCall>";
            StringReader sr           = new StringReader(xml);
            var          deserializer = new XmlRpcRequestDeserializer();

            try
            {
                XmlRpcRequest request = deserializer.DeserializeRequest(sr, this.GetType());
                Assert.Fail("Should detect invalid type of parameter #2");
            }
            catch (XmlRpcTypeMismatchException)
            {
            }
        }
        public void Base64MultiLine()
        {
            string xml = @"<?xml version=""1.0""?>
            <methodCall>
              <methodName>TestHex</methodName>
              <params>
            <param>
              <value>
            <base64>AQIDBAUGBwgJ
            AQIDBAUGBwg=</base64>
              </value>
            </param>
              </params>
            </methodCall>";
            StringReader sr = new StringReader(xml);
            var deserializer = new XmlRpcRequestDeserializer();
            XmlRpcRequest request = deserializer.DeserializeRequest(sr, null);

            Assert.AreEqual(request.Args[0].GetType(), typeof(byte[]),
              "argument is byte[]");
            byte[] ret = (byte[])request.Args[0];
            Assert.AreEqual(17, ret.Length, "argument is byte[17]");
            for (int i = 0; i < 9; i++)
                Assert.AreEqual(i + 1, ret[i], "first 9 members are 1 to 9");
            for (int i = 0; i < 8; i++)
                Assert.AreEqual(i + 1, ret[i + 9], "last 8 members are 1 to 9");
        }
示例#5
0
        public void Base64MultiLine()
        {
            string        xml          = @"<?xml version=""1.0""?>
<methodCall>
  <methodName>TestHex</methodName>
  <params>
    <param>
      <value>
        <base64>AQIDBAUGBwgJ
AQIDBAUGBwg=</base64>
      </value>
    </param>
  </params>
</methodCall>";
            StringReader  sr           = new StringReader(xml);
            var           deserializer = new XmlRpcRequestDeserializer();
            XmlRpcRequest request      = deserializer.DeserializeRequest(sr, null);

            Assert.AreEqual(request.Args[0].GetType(), typeof(byte[]),
                            "argument is byte[]");
            byte[] ret = (byte[])request.Args[0];
            Assert.AreEqual(17, ret.Length, "argument is byte[17]");
            for (int i = 0; i < 9; i++)
            {
                Assert.AreEqual(i + 1, ret[i], "first 9 members are 1 to 9");
            }
            for (int i = 0; i < 8; i++)
            {
                Assert.AreEqual(i + 1, ret[i + 9], "last 8 members are 1 to 9");
            }
        }
示例#6
0
        public void DeserializeObjectParamsStrings()
        {
            string        xml          = @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Bar</methodName>
  <params>
    <param>
      <value>
        <string>one</string>
      </value>
    </param>
    <param>
      <value>
        <string>two</string>
      </value>
    </param>
  </params>
</methodCall>";
            StringReader  sr           = new StringReader(xml);
            var           deserializer = new XmlRpcRequestDeserializer();
            XmlRpcRequest request      = deserializer.DeserializeRequest(sr, this.GetType());

            Assert.AreEqual(request.Method, "Bar", "method is Foo");
            Assert.AreEqual(request.Args[0].GetType(), typeof(string[]), "argument is string[]");
            Assert.AreEqual(
                (string[])request.Args[0],
                new[] { "one", "two" },
                "argument is params array \"one\", \"two\"");
        }
示例#7
0
        private static XmlRpcRequest DeserializeRequest(string xml)
        {
            var sr           = new StringReader(xml);
            var deserializer = new XmlRpcRequestDeserializer();

            return(deserializer.DeserializeRequest(sr, null));
        }
示例#8
0
 public void ISO_8859_1()
 {
     using (var stm = new FileStream("testdocuments/iso-8859-1_request.xml", FileMode.Open, FileAccess.Read))
     {
         var deserializer = new XmlRpcRequestDeserializer();
         var request      = deserializer.DeserializeRequest(stm, null);
         request.Args[0].ShouldBeOfType <string>();
         request.Args[0].ShouldBe("hæ hvað segirðu þá");
     }
 }
示例#9
0
        public void DeserializeMassimo()
        {
            StringReader  sr           = new StringReader(massimoRequest);
            var           deserializer = new XmlRpcRequestDeserializer();
            XmlRpcRequest request      = deserializer.DeserializeRequest(sr, this.GetType());

            Assert.AreEqual(request.Method, "Send_Param", "method is Send_Param");
            Assert.AreEqual(typeof(string), request.Args[0].GetType(), "argument is string");
            Assert.AreEqual(typeof(object[]), request.Args[1].GetType(), "argument is object[]");
        }
示例#10
0
        public Stream Invoke(Stream requestStream)
        {
            try
            {
                var  serializer   = new XmlRpcResponseSerializer();
                var  deserializer = new XmlRpcRequestDeserializer();
                Type type         = this.GetType();
                XmlRpcServiceAttribute serviceAttr = (XmlRpcServiceAttribute)
                                                     Attribute.GetCustomAttribute(this.GetType(),
                                                                                  typeof(XmlRpcServiceAttribute));

                if (serviceAttr != null)
                {
                    if (serviceAttr.XmlEncoding != null)
                    {
                        serializer.XmlEncoding = Encoding.GetEncoding(serviceAttr.XmlEncoding) ?? Config.DefaultEncoding;
                    }
                    serializer.UseEmptyParamsTag = serviceAttr.UseEmptyElementTags;
                    serializer.UseIntTag         = serviceAttr.UseIntTag;
                    serializer.UseStringTag      = serviceAttr.UseStringTag;
                    serializer.UseIndentation    = serviceAttr.UseIndentation;
                    serializer.Indentation       = serviceAttr.Indentation;
                }

                XmlRpcRequest  xmlRpcReq  = deserializer.DeserializeRequest(requestStream, this.GetType());
                XmlRpcResponse xmlRpcResp = Invoke(xmlRpcReq);

                Stream responseStream = new MemoryStream();
                serializer.SerializeResponse(responseStream, xmlRpcResp);
                responseStream.Seek(0, SeekOrigin.Begin);
                return(responseStream);
            }
            catch (Exception ex)
            {
                XmlRpcFaultException fex;
                if (ex is XmlRpcException)
                {
                    fex = new XmlRpcFaultException(0, ((XmlRpcException)ex).Message);
                }
                else if (ex is XmlRpcFaultException)
                {
                    fex = (XmlRpcFaultException)ex;
                }
                else
                {
                    fex = new XmlRpcFaultException(0, ex.Message);
                }
                XmlRpcSerializer serializer     = new XmlRpcSerializer();
                Stream           responseStream = new MemoryStream();
                serializer.SerializeFaultResponse(responseStream, fex);
                responseStream.Seek(0, SeekOrigin.Begin);
                return(responseStream);
            }
        }
示例#11
0
        public void DeserializeObjectParamsInsufficientParams()
        {
            string        xml          = @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Foo1</methodName>
  <params>
  </params>
</methodCall>";
            StringReader  sr           = new StringReader(xml);
            var           deserializer = new XmlRpcRequestDeserializer();
            XmlRpcRequest request      = deserializer.DeserializeRequest(sr, this.GetType());
        }
示例#12
0
        public void DeserializeLinisgreEmptyParam()
        {
            string        xml          = @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Linisgre</methodName>
  <params>
    <param/>
  </params>
</methodCall>";
            StringReader  sr           = new StringReader(xml);
            var           deserializer = new XmlRpcRequestDeserializer();
            XmlRpcRequest request      = deserializer.DeserializeRequest(sr, this.GetType());
        }
示例#13
0
        private MethodCall DeserializeRequest(
            ITransportHeaders requestHeaders,
            Stream requestStream)
        {
            var requestUri   = (string)requestHeaders["__RequestUri"];
            var svcType      = GetServiceType(requestUri);
            var deserializer = new XmlRpcRequestDeserializer();
            var xmlRpcReq    = deserializer.DeserializeRequest(requestStream, svcType);
            var headers      = GetChannelHeaders(requestHeaders, xmlRpcReq, svcType);
            var mthdCall     = new MethodCall(headers);

            mthdCall.ResolveMethod();
            return(mthdCall);
        }
示例#14
0
        public void NoParam1()
        {
            const string Xml =
                @"<?xml version=""1.0"" ?> 
<methodCall>
<methodName>MethodNoArgs</methodName> 
<params/>
</methodCall>";

            var sr         = new StringReader(Xml);
            var serializer = new XmlRpcRequestDeserializer();

            Should.NotThrow(() => serializer.DeserializeRequest(sr, GetType()));
        }
示例#15
0
        public void DeserializeZeroParameters()
        {
            string        xml        = @"<?xml version=""1.0""?>
<methodCall>
  <methodName>FooZeroParameters</methodName>
  <params />
</methodCall>";
            StringReader  sr         = new StringReader(xml);
            var           serializer = new XmlRpcRequestDeserializer();
            XmlRpcRequest request    = serializer.DeserializeRequest(sr, this.GetType());

            Assert.AreEqual(request.Method, "FooZeroParameters", "method is FooZeroParameters");
            Assert.AreEqual(0, request.Args.Length, "no arguments");
        }
示例#16
0
        public void DeserializeParamsEmpty()
        {
            string        xml        = @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Foo</methodName>
  <params/>
</methodCall>";
            StringReader  sr         = new StringReader(xml);
            var           serializer = new XmlRpcRequestDeserializer();
            XmlRpcRequest request    = serializer.DeserializeRequest(sr, this.GetType());

            Assert.AreEqual(request.Method, "Foo", "method is Foo");
            Assert.AreEqual(request.Args[0].GetType(), typeof(object[]), "argument is obj[]");
            Assert.AreEqual((request.Args[0] as object[]).Length, 0, "argument is empty array of object");
        }
示例#17
0
    public Stream Invoke(Stream requestStream)
    {
      try
      {
        var serializer = new XmlRpcResponseSerializer();
        var deserializer = new XmlRpcRequestDeserializer();
        Type type = this.GetType();
        XmlRpcServiceAttribute serviceAttr = (XmlRpcServiceAttribute)
          Attribute.GetCustomAttribute(this.GetType(),
          typeof(XmlRpcServiceAttribute));

        if (serviceAttr != null)
        {
            if (serviceAttr.XmlEncoding != null)
            {
                serializer.XmlEncoding = Encoding.GetEncoding(serviceAttr.XmlEncoding) ?? Config.DefaultEncoding;
            }
            serializer.UseEmptyParamsTag = serviceAttr.UseEmptyElementTags;
            serializer.UseIntTag = serviceAttr.UseIntTag;
            serializer.UseStringTag = serviceAttr.UseStringTag;
            serializer.UseIndentation = serviceAttr.UseIndentation;
            serializer.Indentation = serviceAttr.Indentation;
        }

        XmlRpcRequest xmlRpcReq = deserializer.DeserializeRequest(requestStream, this.GetType());
        XmlRpcResponse xmlRpcResp = Invoke(xmlRpcReq);

        Stream responseStream = new MemoryStream();
        serializer.SerializeResponse(responseStream, xmlRpcResp);
        responseStream.Seek(0, SeekOrigin.Begin);
        return responseStream;
      }
      catch (Exception ex)
      {
        XmlRpcFaultException fex;
        if (ex is XmlRpcException)
          fex = new XmlRpcFaultException(0, ((XmlRpcException)ex).Message);
        else if (ex is XmlRpcFaultException)
          fex = (XmlRpcFaultException)ex;
        else 
          fex = new XmlRpcFaultException(0, ex.Message);
        XmlRpcSerializer serializer = new XmlRpcSerializer();
        Stream responseStream = new MemoryStream();
        serializer.SerializeFaultResponse(responseStream, fex);
        responseStream.Seek(0, SeekOrigin.Begin);
        return responseStream;      
      }
    }
示例#18
0
        public Stream Invoke(Stream requestStream)
        {
            try
            {
                var serializer   = new XmlRpcResponseSerializer();
                var deserializer = new XmlRpcRequestDeserializer();
                var serviceAttr  = Attribute.GetCustomAttribute(GetType(), typeof(XmlRpcServiceAttribute)) as XmlRpcServiceAttribute;
                if (serviceAttr != null)
                {
                    if (serviceAttr.XmlEncoding != null)
                    {
                        serializer.XmlEncoding = Encoding.GetEncoding(serviceAttr.XmlEncoding);
                    }
                    serializer.UseEmptyParamsTag = serviceAttr.UseEmptyElementTags;
                    serializer.UseIntTag         = serviceAttr.UseIntTag;
                    serializer.UseStringTag      = serviceAttr.UseStringTag;
                    serializer.UseIndentation    = serviceAttr.UseIndentation;
                    serializer.Indentation       = serviceAttr.Indentation;
                }

                var xmlRpcReq      = deserializer.DeserializeRequest(requestStream, GetType());
                var xmlRpcResp     = Invoke(xmlRpcReq);
                var responseStream = new MemoryStream();
                serializer.SerializeResponse(responseStream, xmlRpcResp);
                responseStream.Seek(0, SeekOrigin.Begin);
                return(responseStream);
            }
            catch (Exception ex)
            {
                XmlRpcFaultException fex;
                var xmlRpcException = ex as XmlRpcException;
                if (xmlRpcException != null)
                {
                    fex = new XmlRpcFaultException(0, xmlRpcException.Message);
                }
                else
                {
                    fex = (ex as XmlRpcFaultException)
                          ?? new XmlRpcFaultException(0, ex.Message);
                }

                var serializer     = new XmlRpcSerializer();
                var responseStream = new MemoryStream();
                serializer.SerializeFaultResponse(responseStream, fex);
                responseStream.Seek(0, SeekOrigin.Begin);
                return(responseStream);
            }
        }
示例#19
0
        public void EmptyParam1()
        {
            const string Xml =
                @"<?xml version=""1.0"" ?> 
<methodCall>
<methodName>TestString</methodName> 
<params>
  <param/>
</params>
</methodCall>";

            var sr         = new StringReader(Xml);
            var serializer = new XmlRpcRequestDeserializer();

            Should.NotThrow(() => serializer.DeserializeRequest(sr, null));
        }
示例#20
0
        public void DeserializeLinisgreNoArgs()
        {
            string        xml          = @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Linisgre</methodName>
  <params>
  </params>
</methodCall>";
            StringReader  sr           = new StringReader(xml);
            var           deserializer = new XmlRpcRequestDeserializer();
            XmlRpcRequest request      = deserializer.DeserializeRequest(sr, this.GetType());

            Assert.AreEqual(request.Method, "Linisgre", "method is Linisgre");
            Assert.AreEqual(request.Args[0].GetType(), typeof(object[]), "argument is object[]");
            Assert.AreEqual((object[])request.Args[0], new object[0], "argument is empty params array");
        }
示例#21
0
        public void TwoLeadingSpace()
        {
            string xml = @"<?xml version=""1.0""?>
<methodCall><methodName>rtx.EchoString</methodName>
<params>
<param><value>  ddd</value></param>
</params></methodCall>";

            StringReader  sr           = new StringReader(xml);
            var           deserializer = new XmlRpcRequestDeserializer();
            XmlRpcRequest request      = deserializer.DeserializeRequest(sr, GetType());

            Assert.AreEqual(request.Args[0].GetType(), typeof(string),
                            "argument is string");
            Assert.AreEqual("  ddd", request.Args[0]);
        }
示例#22
0
        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;
            }
        }
示例#23
0
        public void DateTimeFormats()
        {
            const string Xml =
                @"<?xml version=""1.0"" ?> 
<methodCall>
<methodName>TestDateTime</methodName> 
<params>
  <param>
    <value><dateTime.iso8601>20020707T11:25:37Z</dateTime.iso8601></value>
  </param>
  <param>
    <value><dateTime.iso8601>20020707T11:25:37</dateTime.iso8601></value>
  </param>
  <param>
    <value><dateTime.iso8601>2002-07-07T11:25:37Z</dateTime.iso8601></value>
  </param>
  <param>
    <value><dateTime.iso8601>2002-07-07T11:25:37</dateTime.iso8601></value>
  </param>
</params>
</methodCall>";

            var sr           = new StringReader(Xml);
            var deserializer = new XmlRpcRequestDeserializer();

            deserializer.NonStandard = XmlRpcNonStandard.AllowNonStandardDateTime;
            XmlRpcRequest request = deserializer.DeserializeRequest(sr, null);

            request.Args[0].ShouldBeOfType <DateTime>();
            request.Args[1].ShouldBeOfType <DateTime>();
            request.Args[2].ShouldBeOfType <DateTime>();
            request.Args[3].ShouldBeOfType <DateTime>();

            var dt0 = (DateTime)request.Args[0];
            var dt1 = (DateTime)request.Args[1];
            var dt2 = (DateTime)request.Args[2];
            var dt3 = (DateTime)request.Args[3];

            var dt = new DateTime(2002, 7, 7, 11, 25, 37);

            dt0.ShouldBe(dt, "DateTime WordPress");
            dt1.ShouldBe(dt, "DateTime XML-RPC spec");
            dt2.ShouldBe(dt, "DateTime TypePad");
            dt3.ShouldBe(dt, "DateTime other");
        }
示例#24
0
        public void TooFewParameters()
        {
            string xml = @"<?xml version=""1.0""?>
<methodCall>
<methodName>blogger.getUsersBlogs</methodName>
<params>
<param>
<value>
<string>myusername</string>
</value>
</param>
</params>
</methodCall>";

            StringReader  sr           = new StringReader(xml);
            var           deserializer = new XmlRpcRequestDeserializer();
            XmlRpcRequest request      = deserializer.DeserializeRequest(sr, GetType());
        }
示例#25
0
        public void DeserializeRequestStructWithNil()
        {
            const string Xml =
            @"<?xml version=""1.0""?>
            <methodCall>
            <methodName>StructWithArrayMethod</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>";

            var sr = new StringReader(Xml);
            var deserializer = new XmlRpcRequestDeserializer();
            var request = deserializer.DeserializeRequest(sr, GetType());

            request.Method.ShouldBe("StructWithArrayMethod");
            request.Args.Length.ShouldBe(1);
            request.Args[0].ShouldBeOfType<StructWithArray>();
            ((StructWithArray)request.Args[0]).ints
                .ShouldBe(new int?[] { 1, null, 3});
        }
示例#26
0
        public void Class()
        {
            string xml = @"<?xml version=""1.0""?>
<methodCall>
  <methodName>TestClassMethod</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>";

            StringReader  sr           = new StringReader(xml);
            var           deserializer = new XmlRpcRequestDeserializer();
            XmlRpcRequest request      = deserializer.DeserializeRequest(sr, GetType());

            Assert.AreEqual(request.Args[0].GetType(), typeof(TestClass),
                            "argument is TestClass");
            //      XmlRpcStruct xrs = (XmlRpcStruct)request.args[0];
            //      Assert.IsTrue(xrs.Count == 4, "XmlRpcStruct has 4 members");
            //      Assert.IsTrue(xrs.ContainsKey("member1") && (int)xrs["member1"] == 1,
            //        "member1");
            //      Assert.IsTrue(xrs.ContainsKey("member2") && (int)xrs["member2"] == 2,
            //        "member2");
            //      Assert.IsTrue(xrs.ContainsKey("member-3") && (int)xrs["member-3"] == 3,
            //        "member-3");
            //      Assert.IsTrue(xrs.ContainsKey("member-4") && (int)xrs["member-4"] == 4,
            //        "member-4");
        }
示例#27
0
        public void DeserializeRequestStructWithNil()
        {
            const string Xml =
                @"<?xml version=""1.0""?>
<methodCall>
    <methodName>StructWithArrayMethod</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>";

            var sr           = new StringReader(Xml);
            var deserializer = new XmlRpcRequestDeserializer();
            var request      = deserializer.DeserializeRequest(sr, GetType());

            request.Method.ShouldBe("StructWithArrayMethod");
            request.Args.Length.ShouldBe(1);
            request.Args[0].ShouldBeOfType <StructWithArray>();
            ((StructWithArray)request.Args[0]).ints
            .ShouldBe(new int?[] { 1, null, 3 });
        }
        public Stream Invoke(Stream requestStream)
        {
            try
            {
                var serializer = new XmlRpcResponseSerializer();
                var deserializer = new XmlRpcRequestDeserializer();
                var serviceAttr = Attribute.GetCustomAttribute(GetType(), typeof(XmlRpcServiceAttribute)) as XmlRpcServiceAttribute;
                if (serviceAttr != null)
                {
                    if (serviceAttr.XmlEncoding != null)
                        serializer.XmlEncoding = Encoding.GetEncoding(serviceAttr.XmlEncoding);
                    serializer.UseEmptyParamsTag = serviceAttr.UseEmptyElementTags;
                    serializer.UseIntTag = serviceAttr.UseIntTag;
                    serializer.UseStringTag = serviceAttr.UseStringTag;
                    serializer.UseIndentation = serviceAttr.UseIndentation;
                    serializer.Indentation = serviceAttr.Indentation;
                }

                var xmlRpcReq = deserializer.DeserializeRequest(requestStream, GetType());
                var xmlRpcResp = Invoke(xmlRpcReq);
                var responseStream = new MemoryStream();
                serializer.SerializeResponse(responseStream, xmlRpcResp);
                responseStream.Seek(0, SeekOrigin.Begin);
                return responseStream;
            }
            catch (Exception ex)
            {
                XmlRpcFaultException fex;
                var xmlRpcException = ex as XmlRpcException;
                if (xmlRpcException != null)
                    fex = new XmlRpcFaultException(0, xmlRpcException.Message);
                else
                {
                    fex = (ex as XmlRpcFaultException)
                        ?? new XmlRpcFaultException(0, ex.Message);
                }

                var serializer = new XmlRpcSerializer();
                var responseStream = new MemoryStream();
                serializer.SerializeFaultResponse(responseStream, fex);
                responseStream.Seek(0, SeekOrigin.Begin);
                return responseStream;
            }
        }
    public void StringEmptyValue1()
    {
      string xml = @"<?xml version=""1.0"" ?> 
<methodCall>
  <methodName>TestString</methodName> 
  <params>
    <param>
      <value></value>
    </param>
  </params>
</methodCall>";
      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = deserializer.DeserializeRequest(sr, null);
 
      Assert.AreEqual(request.method, "TestString", "method is TestString");
      Assert.AreEqual(request.args[0].GetType(),  typeof(string),
        "argument is string");
      Assert.AreEqual((string)request.args[0], "", "argument is empty string"); 
    }
示例#30
0
        public void Blakemore()
        {
            string xml = @"<?xml version=""1.0""?>
<methodCall><methodName>rtx.useArrayOfStruct</methodName>
<params>
<param><value><array>
<data><value>
<struct><member><name>detail</name><value><string>elephant</string></value></member><member><name>number</name><value><int>76</int></value></member></struct>
</value></data>
<data><value>
<struct><member><name>detail</name><value><string>rhino</string></value></member><member><name>number</name><value><int>33</int></value></member></struct>
</value></data>
<data><value>
<struct><member><name>detail</name><value><string>porcupine</string></value></member><member><name>number</name><value><int>106</int></value></member></struct>
</value></data>
</array></value></param>
</params></methodCall>";

            StringReader  sr           = new StringReader(xml);
            var           deserializer = new XmlRpcRequestDeserializer();
            XmlRpcRequest request      = deserializer.DeserializeRequest(sr, GetType());
        }
示例#31
0
        public void Base64Empty()
        {
            const string Xml =
                @"<?xml version=""1.0""?>
<methodCall>
  <methodName>TestHex</methodName>
  <params>
    <param>
      <value>
        <base64></base64>
      </value>
    </param>
  </params>
</methodCall>";
            StringReader  sr           = new StringReader(Xml);
            var           deserializer = new XmlRpcRequestDeserializer();
            XmlRpcRequest request      = deserializer.DeserializeRequest(sr, null);

            Assert.AreEqual(request.Args[0].GetType(), typeof(byte[]),
                            "argument is byte[]");
            Assert.AreEqual(request.Args[0], new byte[0],
                            "argument is zero length byte[]");
        }
        public void Base64Empty()
        {
            const string Xml =
            @"<?xml version=""1.0""?>
            <methodCall>
              <methodName>TestHex</methodName>
              <params>
            <param>
              <value>
            <base64></base64>
              </value>
            </param>
              </params>
            </methodCall>";
            StringReader sr = new StringReader(Xml);
            var deserializer = new XmlRpcRequestDeserializer();
            XmlRpcRequest request = deserializer.DeserializeRequest(sr, null);

            Assert.AreEqual(request.Args[0].GetType(), typeof(byte[]),
              "argument is byte[]");
            Assert.AreEqual(request.Args[0], new byte[0],
              "argument is zero length byte[]");
        }
示例#33
0
        public void DeserializeRequestNilMethod()
        {
            const string Xml =
            @"<?xml version=""1.0"" ?>
            <methodCall>
              <methodName>NilMethod</methodName>
              <params>
            <param>
              <value><nil /></value>
            </param>
            <param>
              <value><int>12345</int></value>
            </param>
              </params>
            </methodCall>";

            var sr = new StringReader(Xml);
            var deserializer = new XmlRpcRequestDeserializer();
            var request = deserializer.DeserializeRequest(sr, GetType());

            request.Method.ShouldBe("NilMethod");
            request.Args[0].ShouldBeNull();
            request.Args[1].ShouldBe(12345);
        }
示例#34
0
        public void DeserializeRequestNilMethod()
        {
            const string Xml =
                @"<?xml version=""1.0"" ?> 
<methodCall>
  <methodName>NilMethod</methodName> 
  <params>
    <param>
      <value><nil /></value>
    </param>
    <param>
      <value><int>12345</int></value>
    </param>
  </params>
</methodCall>";

            var sr           = new StringReader(Xml);
            var deserializer = new XmlRpcRequestDeserializer();
            var request      = deserializer.DeserializeRequest(sr, GetType());

            request.Method.ShouldBe("NilMethod");
            request.Args[0].ShouldBeNull();
            request.Args[1].ShouldBe(12345);
        }
示例#35
0
    public void DeserializeParamsEmpty()
    {
      string xml = 
        @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Foo</methodName>
  <params/>
</methodCall>";
      StringReader sr = new StringReader(xml);
      var serializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = serializer.DeserializeRequest(sr, this.GetType());
  
      Assert.AreEqual(request.method, "Foo", "method is Foo");
      Assert.AreEqual(request.args[0].GetType(),  typeof(object[]),
        "argument is obj[]");
      Assert.AreEqual((request.args[0] as object[]).Length, 0, 
        "argument is empty array of object");
    }
 public void ISO_8859_1()
 {
   using (Stream stm = new FileStream("testdocuments/iso-8859-1_request.xml", 
           FileMode.Open, FileAccess.Read))
   {
     var deserializer = new XmlRpcRequestDeserializer();
     XmlRpcRequest request = deserializer.DeserializeRequest(stm, null);
     Assert.AreEqual(request.args[0].GetType(), typeof(string), 
       "argument is string");
     Assert.AreEqual((string)request.args[0], "hæ hvað segirðu þá",
       "argument is 'hæ hvað segirðu þá'");
   }
 }
示例#37
0
    public void DeserializeObjectParamsInsufficientParams()
    {
      string xml =
        @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Foo1</methodName>
  <params>
  </params>
</methodCall>";
      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = deserializer.DeserializeRequest(sr, this.GetType());
    }
    public void InvalidInteger()
    {
      string xml = @"<?xml version=""1.0"" ?> 
<methodCall>
<methodName>TestInt</methodName> 
<params>
  <param>
    <value><i4>12kiol</i4></value>
  </param>
</params>
</methodCall>";
      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = deserializer.DeserializeRequest(sr, null);
      Assert.Fail("Invalid integer should cause exception");
    }
示例#39
0
    public void DeserializeObjectParamsStrings()
    {
      string xml = 
        @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Bar</methodName>
  <params>
    <param>
      <value>
        <string>one</string>
      </value>
    </param>
    <param>
      <value>
        <string>two</string>
      </value>
    </param>
  </params>
</methodCall>";
      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = deserializer.DeserializeRequest(sr, this.GetType());
      Assert.AreEqual(request.method, "Bar", "method is Foo");
      Assert.AreEqual(request.args[0].GetType(), typeof(string[]), 
        "argument is string[]");
      Assert.AreEqual((string[])request.args[0], new string[] { "one", "two" }, 
        "argument is params array \"one\", \"two\"");
    }
示例#40
0
    public void DeserializeLinisgreNoArgs()
    {
      string xml =
@"<?xml version=""1.0""?>
<methodCall>
  <methodName>Linisgre</methodName>
  <params>
  </params>
</methodCall>";
      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = deserializer.DeserializeRequest(sr, this.GetType());
      Assert.AreEqual(request.method, "Linisgre", "method is Linisgre");
      Assert.AreEqual(request.args[0].GetType(), typeof(object[]),
        "argument is object[]");
      Assert.AreEqual((object[])request.args[0], new object[0],
        "argument is empty params array");
    }
    public void MissingParams()
    {
      string xml = @"<?xml version=""1.0"" ?> 
<methodCall>
<methodName>TestString</methodName> 
</methodCall>";
      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = deserializer.DeserializeRequest(sr, null);
    }
    public void ZeroLengthMethodName()
    {
      string xml = @"<?xml version=""1.0"" ?> 
<methodCall>
<methodName></methodName> 
<params>
  <param>
    <value>test string</value>
  </param>
</params>
</methodCall>";
      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = deserializer.DeserializeRequest(sr, null);
    }
    public void ZeroI8()
    {
      string xml = @"<?xml version=""1.0"" ?> 
<methodCall>
  <methodName>TestInt</methodName> 
  <params>
    <param>
      <value><i8>0</i8></value>
    </param>
  </params>
</methodCall>";
      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = deserializer.DeserializeRequest(sr, null);
      Assert.AreEqual(request.args[0].GetType(), typeof(long),
        "argument is long");
      Assert.AreEqual((long)request.args[0], 0, "argument is 0");
    }
    public void NoParam1()
    {
      string xml = @"<?xml version=""1.0"" ?> 
<methodCall>
<methodName>MethodNoArgs</methodName> 
<params/>
</methodCall>";
      StringReader sr = new StringReader(xml);
      var serializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = serializer.DeserializeRequest(sr, this.GetType());
    }
    public void NegativeOverflowI8()
    {
      string xml = @"<?xml version=""1.0"" ?> 
<methodCall>
<methodName>TestInt</methodName> 
<params>
  <param>
    <value><i8>-9999999999999999999999999999999999999999999</i8></value>
  </param>
</params>
</methodCall>";
      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = deserializer.DeserializeRequest(sr, null);
    }
    public void NoParam2()
    {
      string xml = @"<?xml version=""1.0"" ?> 
<methodCall>
  <methodName>MethodNoArgs</methodName> 
  <params>
  </params>
</methodCall>";
      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = deserializer.DeserializeRequest(sr, this.GetType());
      //Console.WriteLine("");
    }
    public void ZeroInteger()
    {
      string xml = @"<?xml version=""1.0"" ?> 
<methodCall>
  <methodName>TestInt</methodName> 
  <params>
    <param>
      <value><i4>0</i4></value>
    </param>
  </params>
</methodCall>";
      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = deserializer.DeserializeRequest(sr, null);

      Assert.IsTrue(request.method == "TestInt", "method is TestInt");
      Assert.AreEqual(request.args[0].GetType(), typeof(int),
        "argument is int");
      Assert.AreEqual((int)request.args[0], 0, "argument is 0");
    }
示例#48
0
    public void DeserializeZeroParameters()
    {
      string xml =
        @"<?xml version=""1.0""?>
<methodCall>
  <methodName>FooZeroParameters</methodName>
  <params />
</methodCall>";
      StringReader sr = new StringReader(xml);
      var serializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = serializer.DeserializeRequest(sr, 
        this.GetType());
      Assert.AreEqual(request.method, "FooZeroParameters", 
        "method is FooZeroParameters");
      Assert.AreEqual(0, request.args.Length, "no arguments");
    }
 public void MissingMethodCall()
 {
   string xml = @"<?xml version=""1.0"" ?> <elem/>";
   StringReader sr = new StringReader(xml);
   var deserializer = new XmlRpcRequestDeserializer();
   XmlRpcRequest request = deserializer.DeserializeRequest(sr, null);
 }
示例#50
0
    public void DeserializeObjectParams1()
    {
      string xml = 
        @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Foo1</methodName>
  <params>
    <param>
      <value>
        <i4>5678</i4>
      </value>
    </param>
    <param>
      <value>
        <i4>1</i4>
      </value>
    </param>
    <param>
      <value>
        <string>one</string>
      </value>
    </param>
  </params>
</methodCall>";
      StringReader sr = new StringReader(xml);
      var serializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = serializer.DeserializeRequest(sr, this.GetType());
      Assert.AreEqual(request.method, "Foo1", "method is Foo");
      Assert.AreEqual((int)request.args[0], 5678, "first argument is int");
      Assert.AreEqual(request.args[1].GetType(),  typeof(object[]),
        "argument is object[]");
      Assert.AreEqual((object[])request.args[1], new object[] { 1, "one" }, 
        "second argument is params array 1, \"one\"");
    }
    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;
      }
    }
示例#52
0
    public void DeserializeObjectInvalidParams()
    {
      string xml = 
        @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Bar</methodName>
  <params>
    <param>
      <value>
        <string>string one</string>
      </value>
    </param>
    <param>
      <value>
        <i4>2</i4>
      </value>
    </param>
  </params>
</methodCall>";
      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcRequestDeserializer();
      try
      {
        XmlRpcRequest request = deserializer.DeserializeRequest(sr, 
          this.GetType());
        Assert.Fail("Should detect invalid type of parameter #2");
      }
      catch(XmlRpcTypeMismatchException)
      {
      }
    }
    public void DateTimeFormats()
    {
      string xml = @"<?xml version=""1.0"" ?> 
<methodCall>
<methodName>TestDateTime</methodName> 
<params>
  <param>
    <value><dateTime.iso8601>20020707T11:25:37Z</dateTime.iso8601></value>
  </param>
  <param>
    <value><dateTime.iso8601>20020707T11:25:37</dateTime.iso8601></value>
  </param>
  <param>
    <value><dateTime.iso8601>2002-07-07T11:25:37Z</dateTime.iso8601></value>
  </param>
  <param>
    <value><dateTime.iso8601>2002-07-07T11:25:37</dateTime.iso8601></value>
  </param>
</params>
</methodCall>";

      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcRequestDeserializer();
      deserializer.NonStandard = XmlRpcNonStandard.AllowNonStandardDateTime;
      XmlRpcRequest request = deserializer.DeserializeRequest(sr, null);

      Assert.IsTrue(request.args[0] is DateTime, "argument is DateTime");
      DateTime dt0 = (DateTime)request.args[0];
      DateTime dt1 = (DateTime)request.args[1];
      DateTime dt2 = (DateTime)request.args[2];
      DateTime dt3 = (DateTime)request.args[3];

      DateTime dt = new DateTime(2002, 7, 7, 11, 25, 37);
      Assert.AreEqual(dt0, dt, "DateTime WordPress");
      Assert.AreEqual(dt0, dt, "DateTime XML-RPC spec");
      Assert.AreEqual(dt0, dt, "DateTime TypePad");
      Assert.AreEqual(dt0, dt, "DateTime other");
    }
示例#54
0
    public void DeserializeLinisgreEmptyParam()
    {
      string xml =
@"<?xml version=""1.0""?>
<methodCall>
  <methodName>Linisgre</methodName>
  <params>
    <param/>
  </params>
</methodCall>";
      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = deserializer.DeserializeRequest(sr, this.GetType());
    }
    public void StructProperties()
    {
      string xml = @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Foo</methodName>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>member1</name>
            <value>
              <i4>1</i4>
            </value>
          </member>
          <member>
            <name>member2</name>
            <value>
              <i4>2</i4>
            </value>
          </member>
          <member>
            <name>member-3</name>
            <value>
              <i4>3</i4>
            </value>
          </member>
          <member>
            <name>member-4</name>
            <value>
              <i4>4</i4>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodCall>";

      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = deserializer.DeserializeRequest(sr, null);

      Assert.AreEqual(request.args[0].GetType(), typeof(XmlRpcStruct),
        "argument is XmlRpcStruct");
      XmlRpcStruct xrs = (XmlRpcStruct)request.args[0];
      Assert.IsTrue(xrs.Count == 4, "XmlRpcStruct has 4 members");
      Assert.IsTrue(xrs.ContainsKey("member1") && (int)xrs["member1"] == 1, 
        "member1");
      Assert.IsTrue(xrs.ContainsKey("member2") && (int)xrs["member2"] == 2, 
        "member2");
      Assert.IsTrue(xrs.ContainsKey("member-3") && (int)xrs["member-3"] == 3,
        "member-3");
      Assert.IsTrue(xrs.ContainsKey("member-4") && (int)xrs["member-4"] == 4,
        "member-4");
      


    }
示例#56
0
 public void DeserializeMassimo()
 {
   StringReader sr = new StringReader(massimoRequest);
   var deserializer = new XmlRpcRequestDeserializer();
   XmlRpcRequest request = deserializer.DeserializeRequest(sr, this.GetType());
   Assert.AreEqual(request.method, "Send_Param", "method is Send_Param");
   Assert.AreEqual(typeof(string), request.args[0].GetType(),  
     "argument is string");
   Assert.AreEqual(typeof(object[]), request.args[1].GetType(),  
     "argument is object[]");
 }
    public void EmptyInteger()
    {
      string xml = @"<?xml version=""1.0"" ?> 
<methodCall>
<methodName>TestInt</methodName> 
<params>
  <param>
    <value><i4></i4></value>
  </param>
</params>
</methodCall>";
      StringReader sr = new StringReader(xml);
      var serializer = new XmlRpcRequestDeserializer();
      XmlRpcRequest request = serializer.DeserializeRequest(sr, null);
    }