示例#1
0
        public void InvalidHTTPContentLeadingWhiteSpace()
        {
            var xml = @"
 
   
<?xml version=""1.0"" ?> 
<methodResponse>
  <params>
    <param>
      <value><i4>12345</i4></value>
    </param>
  </params>
</methodResponse>";

            Stream stm  = new MemoryStream();
            var    wrtr = new StreamWriter(stm, Encoding.ASCII);

            wrtr.Write(xml);
            wrtr.Flush();
            stm.Position = 0;
            var serializer = new XmlRpcSerializer();

            Assert.That(() => serializer.DeserializeResponse(stm, typeof(int)),
                        Throws.TypeOf <XmlRpcIllFormedXmlException>());
        }
示例#2
0
        public void ReturnStructAsXmlRpcStruct()
        {
            var xml = @"<?xml version=""1.0"" encoding=""ISO-8859-1""?> 
<methodResponse>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>key3</name>
            <value>
              <string>this is a test</string>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodResponse>";

            var sr         = new StringReader(xml);
            var serializer = new XmlRpcSerializer();
            var response
                = serializer.DeserializeResponse(sr, typeof(XmlRpcStruct));

            var o   = response.retVal;
            var ret = (string)((XmlRpcStruct)o)["key3"];
        }
示例#3
0
        public void AdvogatoProblem()
        {
            var xml        = @"<?xml version='1.0'?> 
<methodResponse>
<params>
<param>
<array>
<data>
<value>
<dateTime.iso8601>20020707T11:25:37</dateTime.iso8601>
</value>
<value>
<dateTime.iso8601>20020707T11:37:12</dateTime.iso8601>
</value>
</data>
</array>
</param>
</params>
</methodResponse>";
            var sr         = new StringReader(xml);
            var serializer = new XmlRpcSerializer();

            try
            {
                var response
                    = serializer.DeserializeResponse(sr, null);
                var o = response.retVal;
                Assert.Fail("should have thrown XmlRpcInvalidXmlRpcException");
            }
            catch (XmlRpcInvalidXmlRpcException) { }
        }
示例#4
0
        public void StringAndStructInArray()
        {
            // reproduce problem reported by Eric Brittain
            var xml = @"<?xml version=""1.0"" encoding=""ISO-8859-1""?> 
<methodResponse>
  <params>
    <param>
      <value>
        <array>
          <data>
            <value>
              <string>test string</string>
            </value>
            <value>
              <struct>
                <member>
                  <name>fred</name>
                  <value><string>test string 2</string></value>
                </member>
              </struct>
            </value>
          </data>
        </array>
      </value>
    </param>
  </params>
</methodResponse>";

            var sr         = new StringReader(xml);
            var serializer = new XmlRpcSerializer();
            var response   = serializer.DeserializeResponse(sr, null);
            var o          = response.retVal;
        }
示例#5
0
        public void Donhrobjartz_StructMemberDupValue()
        {
            string           xml        = @"<?xml version=""1.0"" encoding=""iso-8859-1""?>
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>period</name>
<value><string>1w</string></value>
<value><string>284</string></value>
</member>
</struct>
</value>
</param>
</params>
</methodResponse>";
            StringReader     sr1        = new StringReader(xml);
            XmlRpcSerializer serializer = new XmlRpcSerializer();

            serializer.NonStandard = XmlRpcNonStandard.IgnoreDuplicateMembers;
            XmlRpcResponse response = serializer.DeserializeResponse(sr1,
                                                                     typeof(Donhrobjartz));
            Donhrobjartz ret = (Donhrobjartz)response.retVal;
        }
示例#6
0
        public void MissingStructMember()
        {
            var xml        = @"<?xml version='1.0'?> 
<methodResponse> 
  <params> 
    <param> 
      <value>
        <struct>
          <member>
            <name>x</name>
            <value>
              <i4>123</i4>
            </value>
          </member>
        </struct>
      </value> 
    </param> 
  </params> 
</methodResponse>";
            var sr         = new StringReader(xml);
            var serializer = new XmlRpcSerializer();

            try
            {
                var response
                    = serializer.DeserializeResponse(sr, typeof(BillStruct));
                Assert.Fail("Should detect missing struct member");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception) { }
        }
示例#7
0
        public void Donhrobjartz_XmlRpcStructMemberDupValue()
        {
            var xml        = @"<?xml version=""1.0"" encoding=""iso-8859-1""?>
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>period</name>
<value><string>1w</string></value>
<value><string>284</string></value>
</member>
</struct>
</value>
</param>
</params>
</methodResponse>";
            var sr1        = new StringReader(xml);
            var serializer = new XmlRpcSerializer();

            serializer.NonStandard = XmlRpcNonStandard.IgnoreDuplicateMembers;
            Assert.That(() => serializer.DeserializeResponse(sr1,
                                                             typeof(XmlRpcStruct)),
                        Throws.TypeOf <XmlRpcInvalidXmlRpcException>());
        }
示例#8
0
        public void AllowInvalidHTTPContentTrailingWhiteSpace()
        {
            var xml = @"


<?xml version=""1.0"" ?> 
<methodResponse>
  <params>
    <param>
      <value><i4>12345</i4></value>
    </param>
  </params>
</methodResponse>";

            Stream stm  = new MemoryStream();
            var    wrtr = new StreamWriter(stm, Encoding.ASCII);

            wrtr.Write(xml);
            wrtr.Flush();
            stm.Position = 0;

            var serializer = new XmlRpcSerializer();

            serializer.NonStandard = XmlRpcNonStandard.AllowInvalidHttpContent;
            var response = serializer.DeserializeResponse(stm, typeof(int));

            var o = response.retVal;

            Assert.IsTrue(o != null, "retval not null");
            Assert.IsTrue(o is int, "retval is int");
            Assert.AreEqual((int)o, 12345, "retval is 12345");
        }
示例#9
0
        public void Donhrobjartz_XmlRpcStructNonMemberStructChild()
        {
            var xml        = @"<?xml version=""1.0"" encoding=""iso-8859-1""?>
<methodResponse>
<params>
<param>
<value>
<struct>
<foo>
This should be ignored.
</foo>
<member>
<name>period</name>
<value><string>1w</string></value>
</member>
<bar>
This should be ignored.
</bar>
</struct>
</value>
</param>
</params>
</methodResponse>";
            var sr1        = new StringReader(xml);
            var serializer = new XmlRpcSerializer();

            serializer.NonStandard = XmlRpcNonStandard.IgnoreDuplicateMembers;
            var response = serializer.DeserializeResponse(sr1,
                                                          typeof(XmlRpcStruct));
            var ret = (XmlRpcStruct)response.retVal;

            Assert.AreEqual(ret.Count, 1);
        }
示例#10
0
        public void FaultResponse()
        {
            var xml        = @"<?xml version=""1.0"" ?> 
<methodResponse>
  <fault>
    <value>
      <struct>
        <member>
          <name>faultCode</name>
          <value><int>4</int></value>
        </member>
        <member>
          <name>faultString</name>
          <value><string>Too many parameters.</string></value>
        </member>
      </struct>
    </value>
  </fault>
</methodResponse>";
            var sr         = new StringReader(xml);
            var serializer = new XmlRpcSerializer();

            try
            {
                var response = serializer.DeserializeResponse(sr, typeof(void));
            }
            catch (XmlRpcFaultException fex)
            {
                Assert.AreEqual(fex.FaultCode, 4);
                Assert.AreEqual(fex.FaultString, "Too many parameters.");
            }
        }
示例#11
0
        public void FaultStringCode()
        {
            // Alex Hung reported that some servers, e.g. WordPress, return fault code
            // as a string
            var xml        = @"<?xml version=""1.0"" ?> 
<methodResponse>
  <fault>
    <value>
      <struct>
        <member>
          <name>FaultCode</name>
          <value><string>4</string></value>
        </member>
        <member>
          <name>FaultString</name>
          <value><string>Too many parameters.</string></value>
        </member>
      </struct>
    </value>
  </fault>
</methodResponse>";
            var sr         = new StringReader(xml);
            var serializer = new XmlRpcSerializer();

            try
            {
                var response = serializer.DeserializeResponse(sr, typeof(void));
            }
            catch (XmlRpcFaultException fex)
            {
                Assert.AreEqual(fex.FaultCode, 4);
                Assert.AreEqual(fex.FaultString, "Too many parameters.");
            }
        }
示例#12
0
        public void StructContainingArrayError()
        {
            string           xml        = @"<?xml version=""1.0"" encoding=""iso-8859-1""?>
 <methodResponse>
 <params>
 <param>
 <value>
 <struct>
 <member>
 <name>Categories</name>
 <value>
 <array>
 <data>
 <value>
 <struct>
 <member>
 <name>id</name>
 <value>
 <int>0</int>
 </value>
 </member>
 <member>
 <name>Title</name>
 <value>
 <string>Other</string>
 </value>
 </member>
 </struct>
 </value>
 <value>
 <struct>
 <member>
 <name>id</name>
 <value>
 <int>41</int>
 </value>
 </member>
 <member>
 <name>Title</name>
 <value>
 <string>Airplanes</string>
 </value>
 </member>
 </struct>
 </value>
 </data>
 </array>
 </value>
 </member>
 </struct>
 </value>
 </param>
 </params>
 </methodResponse>";
            StringReader     sr1        = new StringReader(xml);
            XmlRpcSerializer serializer = new XmlRpcSerializer();

            serializer.NonStandard = XmlRpcNonStandard.IgnoreDuplicateMembers;
            Assert.That(() => serializer.DeserializeResponse(sr1, typeof(Category[])), Throws.TypeOf <XmlRpcTypeMismatchException>());
        }
示例#13
0
        public void Yolanda()
        {
            string           xml        = @"<?xml version=""1.0"" encoding=""ISO-8859-1""?><methodResponse><params><param><value><array><data><value>addressbook</value><value>system</value></data></array></value></param></params></methodResponse>";
            StringReader     sr         = new StringReader(xml);
            XmlRpcSerializer serializer = new XmlRpcSerializer();
            XmlRpcResponse   response   = serializer.DeserializeResponse(sr, null);

            Object o = response.retVal;
        }
 private static XmlRpcResponse DeserializeResponse(XmlRpcSerializer xmlRpcSerializer,
                                                   string serializedResponse, Type returnValueType)
 {
     using (MemoryStream memoryStream =
                new MemoryStream(xmlRpcSerializer.Encoding.GetBytes(serializedResponse)))
     {
         return(xmlRpcSerializer.DeserializeResponse(memoryStream, returnValueType));
     } // using
 }
示例#15
0
        public void XmlRpcStructDuplicateMember()
        {
            string           xml        = @"<?xml version=""1.0"" encoding=""ISO-8859-1""?> 
<methodResponse>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>foo</name>
            <value>
              <string>this is a test</string>
            </value>
          </member>
          <member>
            <name>foo</name>
            <value>
              <string>duplicate this is a test</string>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodResponse>";
            StringReader     sr1        = new StringReader(xml);
            XmlRpcSerializer serializer = new XmlRpcSerializer();

            try
            {
                XmlRpcResponse response1 = serializer.DeserializeResponse(sr1, typeof(XmlRpcStruct));
                Assert.Fail("Ignored duplicate member");
            }
            catch (XmlRpcInvalidXmlRpcException)
            {
            }
            serializer.NonStandard = XmlRpcNonStandard.IgnoreDuplicateMembers;
            StringReader   sr2       = new StringReader(xml);
            XmlRpcResponse response2 = serializer.DeserializeResponse(sr2, typeof(XmlRpcStruct));
            XmlRpcStruct   dupMem    = (XmlRpcStruct)response2.retVal;

            Assert.IsTrue((string)dupMem["foo"] == "this is a test");
        }
示例#16
0
        /// <summary>
        /// Uploads the Image to SmugMug using HTTP Post.
        /// </summary>
        /// <param name="path">The full path to the image on disk.</param>
        /// <param name="AlbumID">The AlbumID for the Image to be added.</param>
        /// <returns>Throws an <see cref="SmugMugUploadException"/>
        /// if an error occurs trying to upload the Image.</remarks>
        public int Upload(string path, int AlbumID)
        {
            FileInfo file = new FileInfo(path);

            if (file.Exists == false)
            {
                throw new ArgumentException("Image does not exist: " + file.FullName);
            }

//			int byteCount = Convert.ToInt32(file.Length);
//			string md5sum = null;
//
//			using (FileStream fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read))
//			{
//
//				MD5 md5 = new MD5CryptoServiceProvider();
//				byte[] hash = md5.ComputeHash(fs);
//
//				StringBuilder buff = new StringBuilder();
//				foreach (byte hashByte in hash)
//				{
//					buff.Append(String.Format("{0:X1}", hashByte));
//				}
//				md5sum = buff.ToString();
//			}

            try
            {
                WebClient client = new WebClient();
                client.BaseAddress = "http://upload.smugmug.com";
                client.Headers.Add("Cookie:SMSESS=" + this.credentials.SessionID);

                NameValueCollection queryStringCollection = new NameValueCollection();
                queryStringCollection.Add("AlbumID", AlbumID.ToString());
                queryStringCollection.Add("Version", SMUGMUG_API_DEFAULT_VERSION);
//				queryStringCollection.Add("APIKey", SMUGMUG_API_KEY);
//				queryStringCollection.Add("ByteCount", byteCount.ToString());
//				queryStringCollection.Add("MD5Sum", md5sum);
                client.QueryString = queryStringCollection;

                byte[] responseArray = client.UploadFile("http://upload.smugmug.com/photos/xmladd.mg", "POST", file.FullName);
                string response      = Encoding.ASCII.GetString(responseArray);

                XmlRpcSerializer ser = new XmlRpcSerializer();
                XmlDocument      doc = new XmlDocument();
                doc.LoadXml(response);
                XmlRpcResponse rpcResponse = ser.DeserializeResponse(doc, typeof(XmlRpcInt));
                XmlRpcInt      imageID     = (XmlRpcInt)rpcResponse.retVal;
                return((int)imageID);
            }
            catch (Exception ex)
            {
                throw new SmugMugUploadException("Error uploading image: " + file.FullName, ex.InnerException);
            }
        }
示例#17
0
        public void StructDuplicateMember()
        {
            var xml        = @"<?xml version=""1.0"" encoding=""ISO-8859-1""?> 
<methodResponse>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>foo</name>
            <value>
              <string>this is a test</string>
            </value>
          </member>
          <member>
            <name>foo</name>
            <value>
              <string>duplicate this is a test</string>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodResponse>";
            var sr1        = new StringReader(xml);
            var serializer = new XmlRpcSerializer();

            try
            {
                var response1 = serializer.DeserializeResponse(sr1, typeof(DupMem));
                Assert.Fail("Ignored duplicate member");
            }
            catch (XmlRpcInvalidXmlRpcException) { }

            serializer.NonStandard = XmlRpcNonStandard.IgnoreDuplicateMembers;
            var sr2       = new StringReader(xml);
            var response2 = serializer.DeserializeResponse(sr2, typeof(DupMem));
            var dupMem    = (DupMem)response2.retVal;

            Assert.AreEqual(dupMem.foo, "this is a test");
        }
示例#18
0
        public void InvalidXML()
        {
            string       xml  = @"response>";
            Stream       stm  = new MemoryStream();
            StreamWriter wrtr = new StreamWriter(stm, Encoding.ASCII);

            wrtr.Write(xml);
            wrtr.Flush();
            stm.Position = 0;
            XmlRpcSerializer serializer = new XmlRpcSerializer();
            XmlRpcResponse   response   = serializer.DeserializeResponse(stm, typeof(int));
        }
 public void ISO_8869_1()
 {
     using (Stream stm = new FileStream("iso-8859-1_response.xml",
                                        FileMode.Open, FileAccess.Read)) {
         var serializer = new XmlRpcSerializer();
         var response
             = serializer.DeserializeResponse(stm, typeof(String));
         var ret = (String)response.retVal;
         var nnn = ret.Length;
         Assert.IsTrue(ret == "hæ hvað segirðu þá",
                       "retVal is 'hæ hvað segirðu þá'");
     }
 }
示例#20
0
        private async Task <TResult> GetResponse <TResult>(WebRequest http)
        {
            var response = await http.GetResponseAsync();

            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                var xdoc = new XmlDocument();
                xdoc.LoadXml(reader.ReadToEnd());

                var xmlRpcResponse = _serializer.DeserializeResponse(xdoc, typeof(TResult));
                return((TResult)xmlRpcResponse.retVal);
            }
        }
        public void InvalidXML()
        {
            var    xml  = @"response>";
            Stream stm  = new MemoryStream();
            var    wrtr = new StreamWriter(stm, Encoding.ASCII);

            wrtr.Write(xml);
            wrtr.Flush();
            stm.Position = 0;
            var serializer = new XmlRpcSerializer();

            Assert.Throws <XmlRpcIllFormedXmlException>(() => serializer.DeserializeResponse(stm, typeof(int)));
        }
示例#22
0
 public void ISO_8869_1()
 {
     using (Stream stm = new FileStream(Path.Combine(Utils.AssemblyDirectory, "iso-8859-1_response.xml"),
                                        FileMode.Open, FileAccess.Read))
     {
         XmlRpcSerializer serializer = new XmlRpcSerializer();
         XmlRpcResponse   response
             = serializer.DeserializeResponse(stm, typeof(String));
         String ret = (String)response.retVal;
         int    nnn = ret.Length;
         Assert.IsTrue(ret == "hæ hvað segirðu þá",
                       "retVal is 'hæ hvað segirðu þá'");
     }
 }
        public void ZeroByteContentAllowInvalidHTTPContent()
        {
            var    xml  = @"";
            Stream stm  = new MemoryStream();
            var    wrtr = new StreamWriter(stm, Encoding.ASCII);

            wrtr.Write(xml);
            wrtr.Flush();
            stm.Position = 0;
            var serializer = new XmlRpcSerializer();

            serializer.NonStandard = XmlRpcNonStandard.AllowInvalidHTTPContent;
            Assert.Throws <XmlRpcIllFormedXmlException>(() => serializer.DeserializeResponse(stm, typeof(int)));
        }
        public void InvalidXMLWithAllowInvalidHTTPContent()
        {
            var    xml  = @"response>";
            Stream stm  = new MemoryStream();
            var    wrtr = new StreamWriter(stm, Encoding.ASCII);

            wrtr.Write(xml);
            wrtr.Flush();
            stm.Position = 0;
            var serializer = new XmlRpcSerializer();

            serializer.NonStandard = XmlRpcNonStandard.AllowInvalidHTTPContent;
            var response = serializer.DeserializeResponse(stm, typeof(int));
        }
示例#25
0
        public void EmptyParamsVoidReturn()
        {
            var xml        = @"<?xml version=""1.0""?>
<methodResponse>
  <params/>
</methodResponse>
";
            var sr1        = new StringReader(xml);
            var serializer = new XmlRpcSerializer();
            var response   = serializer.DeserializeResponse(sr1,
                                                            typeof(void));

            Assert.IsNull(response.retVal);
        }
示例#26
0
        public void ZeroByteContentAllowInvalidHTTPContent()
        {
            string       xml  = @"";
            Stream       stm  = new MemoryStream();
            StreamWriter wrtr = new StreamWriter(stm, Encoding.ASCII);

            wrtr.Write(xml);
            wrtr.Flush();
            stm.Position = 0;
            XmlRpcSerializer serializer = new XmlRpcSerializer();

            serializer.NonStandard = XmlRpcNonStandard.AllowInvalidHTTPContent;
            XmlRpcResponse response = serializer.DeserializeResponse(stm, typeof(int));
        }
示例#27
0
        public void InvalidXMLWithAllowInvalidHTTPContent()
        {
            string       xml  = @"response>";
            Stream       stm  = new MemoryStream();
            StreamWriter wrtr = new StreamWriter(stm, Encoding.ASCII);

            wrtr.Write(xml);
            wrtr.Flush();
            stm.Position = 0;
            XmlRpcSerializer serializer = new XmlRpcSerializer();

            serializer.NonStandard = XmlRpcNonStandard.AllowInvalidHTTPContent;
            Assert.That(() => serializer.DeserializeResponse(stm, typeof(int)), Throws.TypeOf <XmlRpcIllFormedXmlException>());
        }
示例#28
0
        IMessage DeserializeMessage(
            IMethodCallMessage mcm,
            ITransportHeaders headers,
            Stream stream)
        {
            XmlRpcSerializer serializer = new XmlRpcSerializer();
            object           tp         = mcm.MethodBase;

            System.Reflection.MethodInfo mi = (System.Reflection.MethodInfo)tp;
            System.Type    t          = mi.ReturnType;
            XmlRpcResponse xmlRpcResp = serializer.DeserializeResponse(stream, t);
            IMessage       imsg       = new ReturnMessage(xmlRpcResp.retVal, null, 0, null, mcm);

            return(imsg);
        }
示例#29
0
        public void VoidReturnType()
        {
            var xml        = @"<?xml version=""1.0"" ?> 
<methodResponse>
  <params>
    <param>
      <value></value>
    </param>
  </params>
</methodResponse>";
            var sr         = new StringReader(xml);
            var serializer = new XmlRpcSerializer();
            var response   = serializer.DeserializeResponse(sr, typeof(void));

            Assert.IsTrue(response.retVal == null, "retval is null");
        }
示例#30
0
        public void ISO_8869_1()
        {
            var dllPath = System.Reflection.Assembly.GetExecutingAssembly().Location;

            using (var stm = File.Open(Path.Combine(Path.GetDirectoryName(dllPath), "iso-8859-1_response.xml"),
                                       FileMode.Open, FileAccess.Read))
            {
                var serializer = new XmlRpcSerializer();
                var response
                    = serializer.DeserializeResponse(stm, typeof(string));
                var ret = (string)response.retVal;
                var nnn = ret.Length;
                Assert.IsTrue(ret == "hæ hvað segirðu þá",
                              "retVal is 'hæ hvað segirðu þá'");
            }
        }