Пример #1
0
        static void GetRequestStreamCallback(IAsyncResult asyncResult)
        {
            XmlRpcAsyncResult clientResult
                = (XmlRpcAsyncResult)asyncResult.AsyncState;

            clientResult.CompletedSynchronously = asyncResult.CompletedSynchronously;
            try
            {
                Stream serStream = null;
                Stream reqStream = null;
                bool   logging   = (clientResult.ClientProtocol.RequestEvent != null);
                if (!logging)
                {
                    serStream             = reqStream
                                          = clientResult.Request.EndGetRequestStream(asyncResult);
                }
                else
                {
                    serStream = new MemoryStream(2000);
                }
                try
                {
                    XmlRpcRequest    req        = clientResult.XmlRpcRequest;
                    XmlRpcSerializer serializer = new XmlRpcSerializer();
                    if (clientResult.XmlEncoding != null)
                    {
                        serializer.XmlEncoding = clientResult.XmlEncoding;
                    }
                    serializer.UseEmptyParamsTag = clientResult.UseEmptyParamsTag;
                    serializer.UseIndentation    = clientResult.UseIndentation;
                    serializer.Indentation       = clientResult.Indentation;
                    serializer.UseIntTag         = clientResult.UseIntTag;
                    serializer.UseStringTag      = clientResult.UseStringTag;
                    serializer.SerializeRequest(serStream, req);
                    if (logging)
                    {
                        reqStream          = clientResult.Request.EndGetRequestStream(asyncResult);
                        serStream.Position = 0;
                        Util.CopyStream(serStream, reqStream);
                        reqStream.Flush();
                        serStream.Position = 0;
                        clientResult.ClientProtocol.OnRequest(
                            new XmlRpcRequestEventArgs(req.proxyId, req.number, serStream));
                    }
                }
                finally
                {
                    if (reqStream != null)
                    {
                        reqStream.Close();
                    }
                }
                clientResult.Request.BeginGetResponse(
                    new AsyncCallback(GetResponseCallback), clientResult);
            }
            catch (Exception ex)
            {
                ProcessAsyncException(clientResult, ex);
            }
        }
Пример #2
0
        //  private methods
        //
        void SerializeMessage(
            IMethodCallMessage mcm,
            ref ITransportHeaders headers,
            ref Stream stream)
        {
            ITransportHeaders reqHeaders = new TransportHeaders();

            reqHeaders["__Uri"]         = mcm.Uri;
            reqHeaders["Content-Type"]  = "text/xml; charset=\"utf-8\"";
            reqHeaders["__RequestVerb"] = "POST";

            MethodInfo    mi         = (MethodInfo)mcm.MethodBase;
            string        methodName = GetRpcMethodName(mi);
            XmlRpcRequest xmlRpcReq  = new XmlRpcRequest(methodName, mcm.InArgs);
            // TODO: possibly call GetRequestStream from next sink in chain?
            // TODO: SoapClientFormatter sink uses ChunkedStream - check why?
            Stream           stm        = new MemoryStream();
            XmlRpcSerializer serializer = new XmlRpcSerializer();

            serializer.SerializeRequest(stm, xmlRpcReq);
            stm.Position = 0;

            headers = reqHeaders;
            stream  = stm;
        }
Пример #3
0
        public void SerializeObjectParams()
        {
            Stream        stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();

            req.args   = new Object[] { new object[] { 1, "one" } };
            req.method = "Foo";
            req.mi     = typeof(IFoo).GetMethod("Foo");
            XmlRpcSerializer ser = new XmlRpcSerializer();

            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr     = new StreamReader(stm);
            string     reqstr = tr.ReadToEnd();

            Assert.AreEqual(
                @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Foo</methodName>
  <params>
    <param>
      <value>
        <i4>1</i4>
      </value>
    </param>
    <param>
      <value>
        <string>one</string>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
        }
Пример #4
0
        public void StringDefaultTag()
        {
            Stream stm = new MemoryStream();
            var    req = new XmlRpcRequest();

            req.args = new Object[] {
                "string default tag"
            };
            req.method = "Foo";
            var ser = new XmlRpcSerializer();

            ser.Indentation = 4;
            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr     = new StreamReader(stm);
            var        reqstr = tr.ReadToEnd();

            Assert.AreEqual(
                @"<?xml version=""1.0""?>
<methodCall>
    <methodName>Foo</methodName>
    <params>
        <param>
            <value>
                <string>string default tag</string>
            </value>
        </param>
    </params>
</methodCall>", reqstr);
        }
Пример #5
0
        public void SerializeMassimo()
        {
            var param1 = new object[]
            {
                "test/Gain1", "Gain", 1, 1,
                new[] { 0.5 }
            };
            var param2 = new object[]
            {
                "test/METER", "P1", 1, 1,
                new[] { -1.0 }
            };
            Stream stm = new MemoryStream();
            var    req = new XmlRpcRequest();

            req.args = new object[]
            {
                "IFTASK",
                new object[] { param1, param2 }
            };
            req.method = "Send_Param";
            req.mi     = GetType().GetMethod("Send_Param");
            var ser = new XmlRpcSerializer();

            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr     = new StreamReader(stm);
            var        reqstr = tr.ReadToEnd();

            Assert.AreEqual(massimoRequest, reqstr);
        }
Пример #6
0
        public void NonSerializedClass()
        {
            Stream        stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();

            req.args   = new Object[] { new Class4() };
            req.method = "Foo";
            XmlRpcSerializer ser = new XmlRpcSerializer();

            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr     = new StreamReader(stm);
            string     reqstr = tr.ReadToEnd();

            Assert.AreEqual(
                @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Foo</methodName>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>y</name>
            <value>
              <i4>0</i4>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
        }
Пример #7
0
        public void UseInt()
        {
            Stream stm = new MemoryStream();
            var    req = new XmlRpcRequest();

            req.args = new Object[] {
                1234
            };
            req.method = "Foo";
            var ser = new XmlRpcSerializer();

            ser.Indentation = 4;
            ser.UseIntTag   = true;
            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr     = new StreamReader(stm);
            var        reqstr = tr.ReadToEnd();

            Assert.AreEqual(
                @"<?xml version=""1.0""?>
<methodCall>
    <methodName>Foo</methodName>
    <params>
        <param>
            <value>
                <int>1234</int>
            </value>
        </param>
    </params>
</methodCall>", reqstr);
        }
Пример #8
0
        public void DefaultFormatting()
        {
            Stream stm = new MemoryStream();
            var    req = new XmlRpcRequest();

            req.args = new Object[] {
                1234567
            };
            req.method = "Foo";
            var ser = new XmlRpcSerializer();

            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr     = new StreamReader(stm);
            var        reqstr = tr.ReadToEnd();

            Assert.AreEqual(
                @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Foo</methodName>
  <params>
    <param>
      <value>
        <i4>1234567</i4>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
        }
Пример #9
0
        public void NullParameter()
        {
            Stream        stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();

            req.args   = new Object[] { null };
            req.method = "Foo";
            XmlRpcSerializer ser = new XmlRpcSerializer();

            Assert.That(() => ser.SerializeRequest(stm, req), Throws.TypeOf <XmlRpcNullParameterException>());
        }
Пример #10
0
        public void NullParameter()
        {
            Stream        stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();

            req.args   = new Object[] { null };
            req.method = "Foo";
            XmlRpcSerializer ser = new XmlRpcSerializer();

            ser.SerializeRequest(stm, req);
        }
Пример #11
0
        public void StructParams()
        {
            Stream stm = new MemoryStream();
            var    req = new XmlRpcRequest();

            req.args = new Object[] {
                1234,
                "test",
                10.1
            };
            req.method = "Foo";
            req.mi     = GetType().GetMethod("Foo");
            var ser = new XmlRpcSerializer();

            ser.Indentation = 2;
            ser.UseIntTag   = true;
            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr     = new StreamReader(stm);
            var        reqstr = tr.ReadToEnd();

            Assert.AreEqual(
                @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Foo</methodName>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>x</name>
            <value>
              <int>1234</int>
            </value>
          </member>
          <member>
            <name>y</name>
            <value>
              <string>test</string>
            </value>
          </member>
          <member>
            <name>z</name>
            <value>
              <double>10.1</double>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
        }
        public void 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";
                            XmlRpcSerializer ser = new XmlRpcSerializer();
                            ser.SerializeRequest(stm, req);
                            stm.Position = 0;

                            XmlRpcSerializer serializer = new XmlRpcSerializer();
                            XmlRpcRequest    request    = serializer.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;
            }
        }
        private static void AssertSerializedRequest(XmlRpcSerializer xmlRpcSerializer,
                                                    XmlRpcRequest request, string serializedRequest)
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                xmlRpcSerializer.SerializeRequest(request, memoryStream);

                string actualSerializedRequest =
                    xmlRpcSerializer.Encoding.GetString(memoryStream.ToArray());

                Assert.AreEqual(serializedRequest, actualSerializedRequest);
            } // using
        }
Пример #14
0
        public void StructParamsTooManyParams()
        {
            Stream        stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();

            req.args   = new Object[] { 1234, "test", 10.1, "lopol" };
            req.method = "Foo";
            req.mi     = this.GetType().GetMethod("Foo");
            XmlRpcSerializer ser = new XmlRpcSerializer();

            ser.Indentation = 2;
            ser.UseIntTag   = true;
            Assert.That(() => ser.SerializeRequest(stm, req), Throws.TypeOf <XmlRpcInvalidParametersException>());
        }
Пример #15
0
        public void StructParamsTooManyParams()
        {
            Stream        stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();

            req.args   = new Object[] { 1234, "test", 10.1, "lopol" };
            req.method = "Foo";
            req.mi     = this.GetType().GetMethod("Foo");
            XmlRpcSerializer ser = new XmlRpcSerializer();

            ser.Indentation = 2;
            ser.UseIntTag   = true;
            ser.SerializeRequest(stm, req);
        }
Пример #16
0
 private Task SendRequest(XmlRpcRequest request, WebRequest http)
 {
     return(Task.Run(() =>
     {
         using (var serialized = new MemoryStream())
         {
             _serializer.SerializeRequest(serialized, request);
             http.ContentLength = serialized.Length;
             var outStream = http.GetRequestStream();
             serialized.Seek(0, SeekOrigin.Begin);
             serialized.CopyTo(outStream);
             outStream.Close();
         }
     }));
 }
Пример #17
0
        public void StructParamsGetInfo()
        {
            Stream stm = new MemoryStream();
            var    req = new XmlRpcRequest();

            req.args = new Object[] {
                "Bob Dylan",
                "abcd1234"
            };
            req.method = "artist.getInfo";
            req.mi     = GetType().GetMethod("getInfo");
            var ser = new XmlRpcSerializer();

            ser.Indentation = 2;
            ser.UseIntTag   = true;
            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr     = new StreamReader(stm);
            var        reqstr = tr.ReadToEnd();

            Assert.AreEqual(
                @"<?xml version=""1.0""?>
<methodCall>
  <methodName>artist.getInfo</methodName>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>artist</name>
            <value>
              <string>Bob Dylan</string>
            </value>
          </member>
          <member>
            <name>api_key</name>
            <value>
              <string>abcd1234</string>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
        }
Пример #18
0
        public void Class()
        {
            Stream stm = new MemoryStream();
            var    req = new XmlRpcRequest();
            var    arg = new TestClass();

            arg._int    = 456;
            arg._string = "Test Class";
            req.args    = new Object[] {
                arg
            };
            req.method = "Foo";
            var ser = new XmlRpcSerializer();

            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr     = new StreamReader(stm);
            var        reqstr = tr.ReadToEnd();

            Assert.AreEqual(
                @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Foo</methodName>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>_int</name>
            <value>
              <i4>456</i4>
            </value>
          </member>
          <member>
            <name>_string</name>
            <value>
              <string>Test Class</string>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
        }
Пример #19
0
        public void StructParamsWithParams()
        {
            Stream stm = new MemoryStream();
            var    req = new XmlRpcRequest();

            req.args = new Object[] {
                1234,
                "test",
                new[] {
                    10.1
                }
            };
            req.method = "FooWithParams";
            req.mi     = GetType().GetMethod("FooWithParams");
            var ser = new XmlRpcSerializer();

            ser.Indentation = 2;
            ser.UseIntTag   = true;
            ser.SerializeRequest(stm, req);
        }
Пример #20
0
        public void NoIndentation()
        {
            Stream        stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();

            req.args   = new Object[] { 1234567 };
            req.method = "Foo";
            XmlRpcSerializer ser = new XmlRpcSerializer();

            ser.UseIndentation = false;
            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr     = new StreamReader(stm);
            string     reqstr = tr.ReadToEnd();

            Assert.AreEqual(
                "<?xml version=\"1.0\"?><methodCall><methodName>Foo</methodName>" +
                "<params><param><value><i4>1234567</i4></value></param></params>" +
                "</methodCall>", reqstr);
        }
Пример #21
0
        public void SerializeIntNoParams()
        {
            Stream        stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();

            req.args   = new object[] { new int[] { 1, 2, 3 } };
            req.method = "BarNotParams";
            req.mi     = typeof(IFoo).GetMethod("BarNotParams");
            XmlRpcSerializer ser = new XmlRpcSerializer();

            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr     = new StreamReader(stm);
            string     reqstr = tr.ReadToEnd();

            Assert.AreEqual(
                @"<?xml version=""1.0""?>
<methodCall>
  <methodName>BarNotParams</methodName>
  <params>
    <param>
      <value>
        <array>
          <data>
            <value>
              <i4>1</i4>
            </value>
            <value>
              <i4>2</i4>
            </value>
            <value>
              <i4>3</i4>
            </value>
          </data>
        </array>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
        }
Пример #22
0
        public void SerializeZeroParametersNoParams()
        {
            Stream        stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();

            req.args   = new Object[0];
            req.method = "FooZeroParameters";
            req.mi     = typeof(IFoo).GetMethod("FooZeroParameters");
            XmlRpcSerializer ser = new XmlRpcSerializer();

            ser.UseEmptyParamsTag = false;
            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr     = new StreamReader(stm);
            string     reqstr = tr.ReadToEnd();

            Assert.AreEqual(
                @"<?xml version=""1.0""?>
<methodCall>
  <methodName>FooZeroParameters</methodName>
</methodCall>", reqstr);
        }
Пример #23
0
        public void SerializeIntParams()
        {
            Stream stm = new MemoryStream();
            var    req = new XmlRpcRequest();

            req.args   = new object[] { new[] { 1, 2, 3 } };
            req.method = "Bar";
            req.mi     = typeof(IFoo).GetMethod("Bar");
            var ser = new XmlRpcSerializer();

            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr     = new StreamReader(stm);
            var        reqstr = tr.ReadToEnd();

            Assert.AreEqual(
                @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Bar</methodName>
  <params>
    <param>
      <value>
        <i4>1</i4>
      </value>
    </param>
    <param>
      <value>
        <i4>2</i4>
      </value>
    </param>
    <param>
      <value>
        <i4>3</i4>
      </value>
    </param>
  </params>
</methodCall>".Replace("\r\n", Environment.NewLine), reqstr);
        }
Пример #24
0
        public void SerializeObjectNoParams()
        {
            Stream stm = new MemoryStream();
            var    req = new XmlRpcRequest();

            req.args   = new object[] { new object[] { 1, "one" } };
            req.method = "FooNotParams";
            req.mi     = typeof(IFoo).GetMethod("FooNotParams");
            var ser = new XmlRpcSerializer();

            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr     = new StreamReader(stm);
            var        reqstr = tr.ReadToEnd();

            Assert.AreEqual(
                @"<?xml version=""1.0""?>
<methodCall>
  <methodName>FooNotParams</methodName>
  <params>
    <param>
      <value>
        <array>
          <data>
            <value>
              <i4>1</i4>
            </value>
            <value>
              <string>one</string>
            </value>
          </data>
        </array>
      </value>
    </param>
  </params>
</methodCall>"
                .Replace("\r\n", Environment.NewLine), reqstr);
        }
Пример #25
0
        public void SerializeZeroParameters()
        {
            Stream stm = new MemoryStream();
            var    req = new XmlRpcRequest();

            req.args   = new object[0];
            req.method = "FooZeroParameters";
            req.mi     = typeof(IFoo).GetMethod("FooZeroParameters");
            var ser = new XmlRpcSerializer();

            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr     = new StreamReader(stm);
            var        reqstr = tr.ReadToEnd();

            Assert.AreEqual(
                @"<?xml version=""1.0""?>
<methodCall>
  <methodName>FooZeroParameters</methodName>
  <params />
</methodCall>"
                .Replace("\r\n", Environment.NewLine), reqstr);
        }
Пример #26
0
        public void StructOrderTest()
        {
            byte[] testb = new Byte[]
            {
                121, 111, 117, 32, 99, 97, 110, 39, 116, 32, 114, 101, 97, 100,
                32, 116, 104, 105, 115, 33
            };

            Struct1 str1 = new Struct1();

            str1.mi   = 34567;
            str1.ms   = "another test string";
            str1.mb   = true;
            str1.md   = 8765.123;
            str1.mdt  = new DateTime(2002, 7, 6, 11, 25, 37);
            str1.mb64 = testb;
            str1.ma   = new int[] { 1, 2, 3, 4, 5 };

            Stream        stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();

            req.args   = new Object[] { str1 };
            req.method = "Foo";
            XmlRpcSerializer ser = new XmlRpcSerializer();

            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr     = new StreamReader(stm);
            string     reqstr = tr.ReadToEnd();

            Assert.Less(reqstr.IndexOf(">mi</"), reqstr.IndexOf(">ms</"));
            Assert.Less(reqstr.IndexOf(">ms</"), reqstr.IndexOf(">mb</"));
            Assert.Less(reqstr.IndexOf(">mb</"), reqstr.IndexOf(">md</"));
            Assert.Less(reqstr.IndexOf(">md</"), reqstr.IndexOf(">mdt</"));
            Assert.Less(reqstr.IndexOf(">mdt</"), reqstr.IndexOf(">mb64</"));
            Assert.Less(reqstr.IndexOf(">mb64</"), reqstr.IndexOf(">ma</"));
        }
Пример #27
0
        public object Invoke(
            Object clientObj,
            MethodInfo mi,
            params object[] parameters)
        {
            _responseHeaders = null;
            _responseCookies = null;

            WebRequest webReq = null;
            object     reto   = null;

            try
            {
                string useUrl = GetEffectiveUrl(clientObj);
                webReq = GetWebRequest(new Uri(useUrl));
                XmlRpcRequest req = MakeXmlRpcRequest(webReq, mi, parameters,
                                                      clientObj, _xmlRpcMethod, _id);
                SetProperties(webReq);
                SetRequestHeaders(_headers, webReq);
                SetClientCertificates(_clientCertificates, webReq);

                Stream serStream = null;
                Stream reqStream = null;
                bool   logging   = (RequestEvent != null);
                if (!logging)
                {
                    serStream = reqStream = webReq.GetRequestStream();
                }
                else
                {
                    serStream = new MemoryStream(2000);
                }
                try
                {
                    XmlRpcSerializer serializer = new XmlRpcSerializer();
                    if (_xmlEncoding != null)
                    {
                        serializer.XmlEncoding = _xmlEncoding;
                    }
                    serializer.UseIndentation    = _useIndentation;
                    serializer.Indentation       = _indentation;
                    serializer.NonStandard       = _nonStandard;
                    serializer.UseStringTag      = _useStringTag;
                    serializer.UseIntTag         = _useIntTag;
                    serializer.UseEmptyParamsTag = _useEmptyParamsTag;
                    serializer.SerializeRequest(serStream, req);
                    if (logging)
                    {
                        reqStream          = webReq.GetRequestStream();
                        serStream.Position = 0;
                        Util.CopyStream(serStream, reqStream);
                        reqStream.Flush();
                        serStream.Position = 0;
                        OnRequest(new XmlRpcRequestEventArgs(req.proxyId, req.number,
                                                             serStream));
                    }
                }
                finally
                {
                    if (reqStream != null)
                    {
                        reqStream.Close();
                    }
                }
                HttpWebResponse webResp = GetWebResponse(webReq) as HttpWebResponse;

                _responseCookies = webResp.Cookies;
                _responseHeaders = webResp.Headers;

                Stream respStm = null;
                Stream deserStream;
                logging = (ResponseEvent != null);
                try
                {
                    respStm = webResp.GetResponseStream();
                    if (!logging)
                    {
                        deserStream = respStm;
                    }
                    else
                    {
                        deserStream = new MemoryStream(2000);
                        Util.CopyStream(respStm, deserStream);
                        deserStream.Flush();
                        deserStream.Position = 0;
                    }

                    deserStream = MaybeDecompressStream((HttpWebResponse)webResp,
                                                        deserStream);

                    try
                    {
                        XmlRpcResponse resp = ReadResponse(req, webResp, deserStream, null);
                        reto = resp.retVal;
                    }
                    finally
                    {
                        if (logging)
                        {
                            deserStream.Position = 0;
                            OnResponse(new XmlRpcResponseEventArgs(req.proxyId, req.number,
                                                                   deserStream));
                        }
                    }
                }
                finally
                {
                    if (respStm != null)
                    {
                        respStm.Close();
                    }
                }
            }
            finally
            {
                if (webReq != null)
                {
                    webReq = null;
                }
            }
            return(reto);
        }
Пример #28
0
        public void RecursiveArrayMemberTest()
        {
            Stream stm     = new MemoryStream();
            var    req     = new XmlRpcRequest();
            var    example = new RecursiveArrayMember {
                Level         = "1",
                childExamples = new[] {
                    new RecursiveArrayMember {
                        Level         = "1-1",
                        childExamples = new[] {
                            new RecursiveArrayMember {
                                Level         = "1-1-1",
                                childExamples = new RecursiveArrayMember[] {}
                            },
                            new RecursiveArrayMember {
                                Level         = "1-1-2",
                                childExamples = new RecursiveArrayMember[] {}
                            }
                        }
                    },
                    new RecursiveArrayMember {
                        Level         = "1-2",
                        childExamples = new[] {
                            new RecursiveArrayMember {
                                Level         = "1-2-1",
                                childExamples = new RecursiveArrayMember[] {}
                            },
                            new RecursiveArrayMember {
                                Level         = "1-2-2",
                                childExamples = new RecursiveArrayMember[] {}
                            }
                        }
                    }
                }
            };

            req.args = new Object[] {
                example
            };
            req.method = "Foo";
            var ser = new XmlRpcSerializer();

            ser.UseStringTag = false;
            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr     = new StreamReader(stm);
            var        reqstr = tr.ReadToEnd();

            Assert.AreEqual(
                @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Foo</methodName>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>Level</name>
            <value>1</value>
          </member>
          <member>
            <name>childExamples</name>
            <value>
              <array>
                <data>
                  <value>
                    <struct>
                      <member>
                        <name>Level</name>
                        <value>1-1</value>
                      </member>
                      <member>
                        <name>childExamples</name>
                        <value>
                          <array>
                            <data>
                              <value>
                                <struct>
                                  <member>
                                    <name>Level</name>
                                    <value>1-1-1</value>
                                  </member>
                                  <member>
                                    <name>childExamples</name>
                                    <value>
                                      <array>
                                        <data />
                                      </array>
                                    </value>
                                  </member>
                                </struct>
                              </value>
                              <value>
                                <struct>
                                  <member>
                                    <name>Level</name>
                                    <value>1-1-2</value>
                                  </member>
                                  <member>
                                    <name>childExamples</name>
                                    <value>
                                      <array>
                                        <data />
                                      </array>
                                    </value>
                                  </member>
                                </struct>
                              </value>
                            </data>
                          </array>
                        </value>
                      </member>
                    </struct>
                  </value>
                  <value>
                    <struct>
                      <member>
                        <name>Level</name>
                        <value>1-2</value>
                      </member>
                      <member>
                        <name>childExamples</name>
                        <value>
                          <array>
                            <data>
                              <value>
                                <struct>
                                  <member>
                                    <name>Level</name>
                                    <value>1-2-1</value>
                                  </member>
                                  <member>
                                    <name>childExamples</name>
                                    <value>
                                      <array>
                                        <data />
                                      </array>
                                    </value>
                                  </member>
                                </struct>
                              </value>
                              <value>
                                <struct>
                                  <member>
                                    <name>Level</name>
                                    <value>1-2-2</value>
                                  </member>
                                  <member>
                                    <name>childExamples</name>
                                    <value>
                                      <array>
                                        <data />
                                      </array>
                                    </value>
                                  </member>
                                </struct>
                              </value>
                            </data>
                          </array>
                        </value>
                      </member>
                    </struct>
                  </value>
                </data>
              </array>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
        }