예제 #1
0
        XmlRpcResponse ReadResponse(
            XmlRpcRequest req,
            WebResponse webResp,
            Stream respStm)
        {
            HttpWebResponse httpResp = (HttpWebResponse)webResp;

            if (httpResp.StatusCode != HttpStatusCode.OK)
            {
                // status 400 is used for errors caused by the client
                // status 500 is used for server errors (not server application
                // errors which are returned as fault responses)
                if (httpResp.StatusCode == HttpStatusCode.BadRequest)
                {
                    throw new XmlRpcException(httpResp.StatusDescription);
                }
                else
                {
                    throw new XmlRpcServerException(httpResp.StatusDescription);
                }
            }
            var deserializer = new XmlRpcResponseDeserializer();

            deserializer.NonStandard = _nonStandard;
            Type           retType = req.mi.ReturnType;
            XmlRpcResponse xmlRpcResp
                = deserializer.DeserializeResponse(respStm, req.ReturnType);

            return(xmlRpcResp);
        }
        public void AdvogatoProblem()
        {
            const string 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 deserializer = new XmlRpcResponseDeserializer();
            try
            {
                var response = deserializer.DeserializeResponse(sr, null);
                var o = response.RetVal;
                Assert.Fail("should have thrown XmlRpcInvalidXmlRpcException");
            }
            catch (XmlRpcInvalidXmlRpcException)
            {
            }
        }
예제 #3
0
    public void DeserializeResponseStructWithNil()
    {
      string xml = @"<?xml version=""1.0"" ?> 
<methodResponse>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>lowerBound</name>
            <value><nil/></value>
          </member>
          <member>
            <name>upperBound</name>
            <value><nil/></value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodResponse>";
      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcResponseDeserializer();
      XmlRpcResponse response = deserializer.DeserializeResponse(sr, typeof(ServerBounds));
      Assert.IsInstanceOf<ServerBounds>(response.retVal);
      ServerBounds bounds = response.retVal as ServerBounds;
      Assert.IsNull(bounds.lowerBound);
      Assert.IsNull(bounds.upperBound);
    }
예제 #4
0
        public void DeserializeResponseStructWithNil()
        {
            const string Xml =
                @"<?xml version=""1.0"" ?> 
<methodResponse>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>lowerBound</name>
            <value><nil/></value>
          </member>
          <member>
            <name>upperBound</name>
            <value><nil/></value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodResponse>";

            var sr           = new StringReader(Xml);
            var deserializer = new XmlRpcResponseDeserializer();
            var response     = deserializer.DeserializeResponse(sr, typeof(ServerBounds));

            response.RetVal.ShouldBeOfType <ServerBounds>();
            var bounds = response.RetVal as ServerBounds;

            bounds.lowerBound.ShouldBeNull();
            bounds.upperBound.ShouldBeNull();
        }
        public void AllowInvalidHTTPContentLeadingWhiteSpace()
        {
            const string 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 deserializer = new XmlRpcResponseDeserializer();
            deserializer.NonStandard = XmlRpcNonStandard.AllowInvalidHTTPContent;
            var response = deserializer.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");
        }
예제 #6
0
        private static IMessage DeserializeMessage(
            IMethodCallMessage mcm,
            Stream stream)
        {
            var deserializer = new XmlRpcResponseDeserializer();
            var tp           = mcm.MethodBase;
            var mi           = (MethodInfo)tp;
            var t            = mi.ReturnType;
            var xmlRpcResp   = deserializer.DeserializeResponse(stream, t);

            return(new ReturnMessage(xmlRpcResp.RetVal, null, 0, null, mcm));
        }
예제 #7
0
        IMessage DeserializeMessage(
            IMethodCallMessage mcm,
            ITransportHeaders headers,
            Stream stream)
        {
            var    deserializer = new XmlRpcResponseDeserializer();
            object tp           = mcm.MethodBase;

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

            return(imsg);
        }
예제 #8
0
    public void DeserializeResponseNilMethod()
    {
      string xml = @"<?xml version=""1.0"" ?> 
<methodResponse>
  <params>
    <param>
      <value><nil /></value>
    </param>
  </params>
</methodCall>";
      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcResponseDeserializer();
      XmlRpcResponse response = deserializer.DeserializeResponse(sr, this.GetType());

      Assert.IsNull(response.retVal, "return value is null");
    }
예제 #9
0
        public void DeserializeResponseNilMethod()
        {
            const string Xml =
                @"<?xml version=""1.0"" ?> 
<methodResponse>
  <params>
    <param>
      <value><nil /></value>
    </param>
  </params>
</methodCall>";

            var sr           = new StringReader(Xml);
            var deserializer = new XmlRpcResponseDeserializer();
            var response     = deserializer.DeserializeResponse(sr, GetType());

            response.RetVal.ShouldBeNull();
        }
예제 #10
0
    public void IntegerNullType()
    {
      string xml = @"<?xml version=""1.0"" ?> 
<methodResponse>
  <params>
    <param>
      <value><int>12345</int></value>
    </param>
  </params>
</methodResponse>";
      StringReader sr = new StringReader(xml);
      var deserializer = new XmlRpcResponseDeserializer();
      XmlRpcResponse response = deserializer.DeserializeResponse(sr, null);

      Object 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");
    }
예제 #11
0
        public void Deserialize()
        {
            string         xml          = @"<?xml version=""1.0"" encoding=""iso-8859-1""?>
<methodResponse>
  <params>
    <param>
      <value>
        <i4>2</i4>
      </value>
    </param>
  </params>
</methodResponse>";
            StringReader   sr1          = new StringReader(xml);
            var            deserializer = new XmlRpcResponseDeserializer();
            XmlRpcResponse response     = deserializer.DeserializeResponse(sr1, typeof(IntEnum));
            IntEnum        ret          = (IntEnum)response.RetVal;

            Assert.AreEqual(IntEnum.Two, ret);
        }
        public void ReturnNestedStruct()
        {
            const string Xml =
            @"<?xml version=""1.0"" encoding=""ISO-8859-1""?>
            <methodResponse>
              <params>
            <param>
              <value>
            <struct>
              <member>
            <name>Version</name>
            <value><string>1.6</string></value>
              </member>
              <member>
            <name>Record</name>
            <value>
              <struct>
                <member>
                  <name>FirstName</name>
                  <value>Joe</value></member>
                <member>
                  <name>LastName</name>
                  <value>Test</value>
                </member>
              </struct>
            </value>
              </member>
            </struct>
              </value>
            </param>
              </params>
            </methodResponse>";

            var sr = new StringReader(Xml);
            var deserializer = new XmlRpcResponseDeserializer();
            var response = deserializer.DeserializeResponse(sr, typeof(MyStruct));

            var o = response.RetVal;
            Assert.IsTrue(o is MyStruct, "retval is MyStruct");
            var mystr = (MyStruct)o;
            Assert.AreEqual(mystr.Version, "1.6", "version is 1.6");
            Assert.IsTrue(mystr.Record.FirstName == "Joe", "firstname is Joe");
            Assert.IsTrue(mystr.Record.LastName == "Test", "lastname is Test");
        }
        public void ReturnStructAsObject()
        {
            const string 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>
              <member>
            <name>key4</name>
            <value>
              <string>this is a test 2</string>
            </value>
              </member>
            </struct>
              </value>
            </param>
              </params>
            </methodResponse>";

            var sr = new StringReader(Xml);
            var deserializer = new XmlRpcResponseDeserializer();
            var response = deserializer.DeserializeResponse(sr, typeof(object));

            var o = response.RetVal;
            var ret = (string)((XmlRpcStruct)o)["key3"];
            Assert.AreEqual("this is a test", ret);
            var ret2 = (string)((XmlRpcStruct)o)["key4"];
            Assert.AreEqual("this is a test 2", ret2);
        }
        public void MissingStructMember()
        {
            const string 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 deserializer = new XmlRpcResponseDeserializer();
            try
            {
                deserializer.DeserializeResponse(sr, typeof(BillStruct));
                Assert.Fail("Should detect missing struct member");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception)
            {
            }
        }
 public void OneByteContentAllowInvalidHTTPContent()
 {
     const string Xml = @"<";
     Stream stm = new MemoryStream();
     var wrtr = new StreamWriter(stm, Encoding.ASCII);
     wrtr.Write(Xml);
     wrtr.Flush();
     stm.Position = 0;
     var deserializer = new XmlRpcResponseDeserializer();
     deserializer.NonStandard = XmlRpcNonStandard.AllowInvalidHTTPContent;
     deserializer.DeserializeResponse(stm, typeof(int));
 }
        public void FaultResponse()
        {
            const string 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 deserializer = new XmlRpcResponseDeserializer();
            try
            {
                deserializer.DeserializeResponse(sr, typeof(void));
            }
            catch (XmlRpcFaultException fex)
            {
                Assert.AreEqual(fex.FaultCode, 4);
                Assert.AreEqual(fex.FaultString, "Too many parameters.");
            }
        }
        public void MinDateTimeStrict()
        {
            const string Xml =
            @"<?xml version=""1.0"" ?>
            <methodResponse>
              <params>
            <param>
              <value><dateTime.iso8601>00000000T00:00:00</dateTime.iso8601></value>
            </param>
              </params>
            </methodResponse>";

            var sr = new StringReader(Xml);
            var deserializer = new XmlRpcResponseDeserializer
            {
                NonStandard = XmlRpcNonStandard.AllowNonStandardDateTime
            };
            try
            {
                deserializer.DeserializeResponse(sr, typeof(DateTime));
                Assert.Fail("dateTime 00000000T00:00:00 invalid when strict");
            }
            catch (XmlRpcInvalidXmlRpcException)
            {
            }
        }
 public void EmptyParamsVoidReturn()
 {
     const string Xml =
     @"<?xml version=""1.0""?>
     <methodResponse>
       <params/>
     </methodResponse>
     ";
     var sr1 = new StringReader(Xml);
     var deserializer = new XmlRpcResponseDeserializer();
     var response = deserializer.DeserializeResponse(sr1, typeof(void));
     Assert.IsNull(response.RetVal);
 }
예제 #19
0
    public void Deserialize()
    {
      string xml =
@"<?xml version=""1.0"" encoding=""iso-8859-1""?>
<methodResponse>
  <params>
    <param>
      <value>
        <i4>2</i4>
      </value>
    </param>
  </params>
</methodResponse>";
      StringReader sr1 = new StringReader(xml);
      var deserializer = new XmlRpcResponseDeserializer();
      XmlRpcResponse response = deserializer.DeserializeResponse(sr1,
        typeof(IntEnum));
      IntEnum ret = (IntEnum)response.retVal;
      Assert.AreEqual(IntEnum.Two, ret);
    }
        public void EmptyValueReturn()
        {
            const string Xml =
            @"<?xml version=""1.0"" ?>
            <methodResponse>
              <params>
            <param>
              <value/>
            </param>
              </params>
            </methodResponse>";

            var sr = new StringReader(Xml);
            var deserializer = new XmlRpcResponseDeserializer();
            var response = deserializer.DeserializeResponse(sr, typeof(string));
            var s = (string)response.RetVal;
            Assert.IsTrue(s == string.Empty, "retval is empty string");
        }
 IMessage DeserializeMessage(
   IMethodCallMessage mcm,
   ITransportHeaders headers,
   Stream stream)
 {
     var deserializer = new XmlRpcResponseDeserializer();
     object tp = mcm.MethodBase;
     System.Reflection.MethodInfo mi = (System.Reflection.MethodInfo)tp;
     System.Type t = mi.ReturnType;
     XmlRpcResponse xmlRpcResp = deserializer.DeserializeResponse(stream, t);
     IMessage imsg = new ReturnMessage(xmlRpcResp.retVal, null, 0, null, mcm);
     return imsg;
 }
예제 #22
0
        public void DeserializeResponseStructWithNil()
        {
            const string Xml =
            @"<?xml version=""1.0"" ?>
            <methodResponse>
              <params>
            <param>
              <value>
            <struct>
              <member>
            <name>lowerBound</name>
            <value><nil/></value>
              </member>
              <member>
            <name>upperBound</name>
            <value><nil/></value>
              </member>
            </struct>
              </value>
            </param>
              </params>
            </methodResponse>";

            var sr = new StringReader(Xml);
            var deserializer = new XmlRpcResponseDeserializer();
            var response = deserializer.DeserializeResponse(sr, typeof(ServerBounds));
            response.RetVal.ShouldBeOfType<ServerBounds>();
            var bounds = response.RetVal as ServerBounds;
            bounds.lowerBound.ShouldBeNull();
            bounds.upperBound.ShouldBeNull();
        }
        public void IntegerIncorrectType()
        {
            try
            {
                const string Xml =
            @"<?xml version=""1.0"" ?>
            <methodResponse>
              <params>
            <param>
              <value><int>12345</int></value>
            </param>
              </params>
            </methodResponse>";

                var sr = new StringReader(Xml);
                var deserializer = new XmlRpcResponseDeserializer();
                deserializer.DeserializeResponse(sr, typeof(string));
                Assert.Fail("Should throw XmlRpcTypeMismatchException");
            }
            catch (XmlRpcTypeMismatchException)
            {
            }
        }
        public void Gabe()
        {
            const string Xml =
            @"<?xml version=""1.0"" encoding=""UTF-8""?><methodResponse><params><param><value><struct><member><name>response</name><value><struct><member><name>result</name><value><array><data><value><struct><member><name>state</name><value><string>CO</string></value></member><member><name>latitude</name><value><double>39.74147878</double></value></member><member><name>add1</name><value><string>110 16th St.</string></value></member><member><name>add2</name><value><string /></value></member><member><name>image_map</name><value><array><data><value><string>rect</string></value><value><int>290</int></value><value><int>190</int></value><value><int>309</int></value><value><int>209</int></value></data></array></value></member><member><name>city</name><value><string>Denver</string></value></member><member><name>fax</name><value><string>303-623-1111</string></value></member><member><name>name</name><value><boolean>0"
            + "</boolean></value></member><member><name>longitude</name><value><double>-104.9874159</double></value></member><member><name>georesult</name><value><string>10 W2GIADDRESS</string></value></member><member><name>zip</name><value><string>80202</string></value></member><member><name>hours</name><value><string>Mon-Sun 10am-6pm</string></value></member><member><name>dealerid</name><value><string>545</string></value></member><member><name>phone</name><value><string>303-623-5050</string></value></member></struct></value></data></array></value></member><member><name>map_id</name><value><string>a5955239d080dfbb7002fd063aa7b47e0d</string></value></member><member><name>map</name><value><struct><member><name>zoom_level</name><value><int>3</int></value></member><member><name>image_type</name><value><string>image/png</string></value></member><member><name>miles</name><value><double>1.75181004463519</double></value></member><member><name>kilometers</name><value><double>2.81926498447338"
            + "</double></value></member><member><name>scalebar</name><value><int>1</int></value></member><member><name>content</name><value><string>http://mapserv.where2getit.net/maptools/mapserv.cgi/a5955239d080dfbb7002fd063aa7b47e0d.png</string></value></member><member><name>scale</name><value><int>26000</int></value></member><member><name>map_style</name><value><string>default</string></value></member><member><name>size</name><value><array><data><value><int>600</int></value><value><int>400</int></value></data></array></value></member><member><name>content_type</name><value><string>text/uri-list</string></value></member><member><name>buffer</name><value><double>0.01</double></value></member><member><name>center</name><value><struct><member><name>georesult</name><value><string>AUTOBBOX</string></value></member><member><name>latitude</name><value><double>39.74147878</double></value></member><member><name>longitude</name><value><double>-104.9874159</double></value></member></struct></value></member></struct></value></member><member><name>result_count</name><value><int>1</int></value></member><member><name>image_map</name><value><boolean>1</boolean></value></member><member><name>result_total_count</name><value><int>1</int></value></member></struct></value></member><member><name>times</name><value><struct><member><name>csys</name><value><int>0</int></value></member><member><name>cusr</name><value><int>0</int></value></member><member><name>sys</name><value><int>0</int></value></member><member><name>usr</name><value><double>0.0200000000000005"
            + "</double></value></member><member><name>wallclock</name><value><double>2.547471</double></value></member></struct></value></member><member><name>request</name><value><struct><member><name>state</name><value><string>CO</string></value></member><member><name>%sort</name><value><array><data /></array></value></member><member><name>%id</name><value><string>4669b341d87be7f450b4bf0dc4cd0a1e</string></value></member><member><name>city</name><value><string>denver</string></value></member><member><name>%limit</name><value><int>10</int></value></member><member><name>%offset</name><value><int>0</int></value></member></struct></value></member></struct></value></param></params></methodResponse>";

            var sr = new StringReader(Xml);
            var deserializer = new XmlRpcResponseDeserializer();
            var response = deserializer.DeserializeResponse(sr, typeof(XmlRpcStruct));

            var response_struct = (XmlRpcStruct)response.RetVal;
            var _response = (XmlRpcStruct)response_struct["response"];
            var results = (Array)_response["result"];
            Assert.AreEqual(results.Length, 1);
        }
        public void Donhrobjartz_XmlRpcStructNonMemberStructChild()
        {
            const string 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 deserializer = new XmlRpcResponseDeserializer();
            deserializer.NonStandard = XmlRpcNonStandard.IgnoreDuplicateMembers;
            var response = deserializer.DeserializeResponse(sr1, typeof(XmlRpcStruct));
            var ret = (XmlRpcStruct)response.RetVal;
            Assert.AreEqual(ret.Count, 1);
        }
        public void JoseProblem()
        {
            const string Xml =
            @"<?xml version='1.0'?>
            <methodResponse>
            <params>
            <param>
            <value><int>12</int></value>
            </param>
            </params>

            </methodResponse>";

            var sr = new StringReader(Xml);
            var deserializer = new XmlRpcResponseDeserializer();
            var response = deserializer.DeserializeResponse(sr, typeof(int));

            var o = response.RetVal;
            Assert.IsTrue(o is int, "retval is int");
            var myint = (int)o;
            Assert.AreEqual(myint, 12, "int is 12");
        }
        public void Donhrobjartz_XmlRpcStructMemberDupValue()
        {
            const 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>";

            var sr1 = new StringReader(Xml);
            var deserializer = new XmlRpcResponseDeserializer();
            deserializer.NonStandard = XmlRpcNonStandard.IgnoreDuplicateMembers;
            var response = deserializer.DeserializeResponse(sr1, typeof(XmlRpcStruct));
            var ret = (XmlRpcStruct)response.RetVal;
        }
        public void MinDateTime4NotStrict()
        {
            const string Xml =
            @"<?xml version=""1.0"" ?>
            <methodResponse>
              <params>
            <param>
              <value><dateTime.iso8601>0000-00-00T00:00:00Z</dateTime.iso8601></value>
            </param>
              </params>
            </methodResponse>";

            var sr = new StringReader(Xml);
            var deserializer = new XmlRpcResponseDeserializer();
            deserializer.NonStandard = XmlRpcNonStandard.MapZerosDateTimeToMinValue;
            var response = deserializer.DeserializeResponse(sr, typeof(DateTime));

            var o = response.RetVal;
            Assert.IsTrue(o is DateTime, "retval is string");
            Assert.AreEqual((DateTime)o, DateTime.MinValue, "DateTime.MinValue");
        }
        public void IntegerWithType()
        {
            const string Xml =
            @"<?xml version=""1.0"" ?>
            <methodResponse>
              <params>
            <param>
              <value><int>12345</int></value>
            </param>
              </params>
            </methodResponse>";

            var sr = new StringReader(Xml);
            var deserializer = new XmlRpcResponseDeserializer();
            var response = deserializer.DeserializeResponse(sr, 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");
        }
        public void FaultStringCodeWithAllowStringFaultCode()
        {
            // Alex Hung reported that some servers, e.g. WordPress, return fault code
            // as a string
            const string 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 deserializer = new XmlRpcResponseDeserializer { NonStandard = XmlRpcNonStandard.AllowStringFaultCode };
            try
            {
                deserializer.DeserializeResponse(sr, typeof(void));
                Assert.Fail("Expected fault exception to be thrown");
            }
            catch (XmlRpcFaultException fex)
            {
                Assert.AreEqual(fex.FaultCode, 4);
                Assert.AreEqual(fex.FaultString, "Too many parameters.");
            }
        }
예제 #31
0
        public void DeserializeResponseNilMethod()
        {
            const string Xml =
            @"<?xml version=""1.0"" ?>
            <methodResponse>
              <params>
            <param>
              <value><nil /></value>
            </param>
              </params>
            </methodCall>";

            var sr = new StringReader(Xml);
            var deserializer = new XmlRpcResponseDeserializer();
            var response = deserializer.DeserializeResponse(sr, GetType());

            response.RetVal.ShouldBeNull();
        }
        public void InvalidHTTPContentLeadingWhiteSpace()
        {
            const string 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 deserializer = new XmlRpcResponseDeserializer();
            deserializer.DeserializeResponse(stm, typeof(int));
        }
 private static IMessage DeserializeMessage(
     IMethodCallMessage mcm,
     Stream stream)
 {
     var deserializer = new XmlRpcResponseDeserializer();
     var tp = mcm.MethodBase;
     var mi = (MethodInfo)tp;
     var t = mi.ReturnType;
     var xmlRpcResp = deserializer.DeserializeResponse(stream, t);
     return new ReturnMessage(xmlRpcResp.RetVal, null, 0, null, mcm);
 }
 public void InvalidXML()
 {
     const string Xml = @"response>";
     Stream stm = new MemoryStream();
     var wrtr = new StreamWriter(stm, Encoding.ASCII);
     wrtr.Write(Xml);
     wrtr.Flush();
     stm.Position = 0;
     var deserializer = new XmlRpcResponseDeserializer();
     deserializer.DeserializeResponse(stm, typeof(int));
 }
예제 #35
0
 XmlRpcResponse ReadResponse(
   XmlRpcRequest req,
   WebResponse webResp,
   Stream respStm)
 {
     HttpWebResponse httpResp = (HttpWebResponse)webResp;
     if (httpResp.StatusCode != HttpStatusCode.OK)
     {
         // status 400 is used for errors caused by the client
         // status 500 is used for server errors (not server application
         // errors which are returned as fault responses)
         if (httpResp.StatusCode == HttpStatusCode.BadRequest)
             throw new XmlRpcException(httpResp.StatusDescription);
         else
             throw new XmlRpcServerException(httpResp.StatusDescription);
     }
     var deserializer = new XmlRpcResponseDeserializer();
     deserializer.NonStandard = _nonStandard;
     Type retType = req.mi.ReturnType;
     XmlRpcResponse xmlRpcResp
       = deserializer.DeserializeResponse(respStm, retType);
     return xmlRpcResp;
 }
 public void ISO_8869_1()
 {
     using (var stm = new FileStream("testdocuments/iso-8859-1_response.xml", FileMode.Open, FileAccess.Read))
     {
         var deserializer = new XmlRpcResponseDeserializer();
         var response = deserializer.DeserializeResponse(stm, typeof(string));
         var ret = (string)response.RetVal;
         Assert.IsTrue(ret == "hæ hvað segirðu þá", "retVal is 'hæ hvað segirðu þá'");
     }
 }