예제 #1
0
        public void SerializeRequestNilParams()
        {
            var stm = new MemoryStream();
            var req = new XmlRpcRequest();
            req.Args = new Object[] { new object[] { 1, null, 2 } };
            req.Method = "NilParamsMethod";
            req.Mi = GetType().GetMethod("NilParamsMethod");
            var ser = new XmlRpcRequestSerializer();
            ser.Indentation = 4;
            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            var tr = new StreamReader(stm);
            tr.ReadToEnd().ShouldBe(
@"<?xml version=""1.0""?>
<methodCall>
    <methodName>NilParamsMethod</methodName>
    <params>
        <param>
            <value>
                <i4>1</i4>
            </value>
        </param>
        <param>
            <value>
                <nil />
            </value>
        </param>
        <param>
            <value>
                <i4>2</i4>
            </value>
        </param>
    </params>
</methodCall>");
        }
예제 #2
0
        public void SerializeRequest()
        {
            Stream        stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();

            req.Args   = new object[] { IntEnum.Two };
            req.Method = "Foo";
            var ser = new XmlRpcRequestSerializer();

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

            Assert.AreEqual(@"<?xml version=""1.0""?>
<methodCall>
  <methodName>Foo</methodName>
  <params>
    <param>
      <value>
        <i4>2</i4>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
        }
예제 #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");
      var ser = new XmlRpcRequestSerializer();
      ser.SerializeRequest(stm, req);
      stm.Position = 0;
      TextReader tr = new StreamReader(stm);
      string reqstr = tr.ReadToEnd();
      Assert.AreEqual(
        @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Foo</methodName>
  <params>
    <param>
      <value>
        <i4>1</i4>
      </value>
    </param>
    <param>
      <value>
        <string>one</string>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
    }
예제 #4
0
        public void SerializeRequestWithEnumStringParam()
        {
            Stream        stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();

            req.Args   = new object[] { IntEnum.Two };
            req.Method = "EnumMethod1";
            req.Mi     = this.GetType().GetMethod("EnumMethod1");
            var ser = new XmlRpcRequestSerializer();

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

            Assert.AreEqual(@"<?xml version=""1.0""?>
<methodCall>
  <methodName>EnumMethod1</methodName>
  <params>
    <param>
      <value>
        <string>Two</string>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
        }
예제 #5
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");
            var ser = new XmlRpcRequestSerializer();

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

            Assert.AreEqual(@"<?xml version=""1.0""?>
<methodCall>
  <methodName>Foo</methodName>
  <params>
    <param>
      <value>
        <i4>1</i4>
      </value>
    </param>
    <param>
      <value>
        <string>one</string>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
        }
예제 #6
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();
            var    serializer = new XmlRpcRequestSerializer();

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

            headers = reqHeaders;
            stream  = stm;
        }
예제 #7
0
    public void SerializeRequestNil()
    {
      Stream stm = new MemoryStream();
      XmlRpcRequest req = new XmlRpcRequest();
      req.args = new Object[] { null, 1234567 };
      req.method = "NilMethod";
      req.mi = this.GetType().GetMethod("NilMethod");
      var ser = new XmlRpcRequestSerializer();
      ser.Indentation = 4;
      ser.SerializeRequest(stm, req);
      stm.Position = 0;
      TextReader tr = new StreamReader(stm);
      string reqstr = tr.ReadToEnd();
      Assert.AreEqual(
        @"<?xml version=""1.0""?>
<methodCall>
    <methodName>NilMethod</methodName>
    <params>
        <param>
            <value>
                <nil />
            </value>
        </param>
        <param>
            <value>
                <i4>1234567</i4>
            </value>
        </param>
    </params>
</methodCall>", reqstr);
    }
예제 #8
0
        public void SerializeRequestNil()
        {
            var stm = new MemoryStream();
            var req = new XmlRpcRequest();

            req.Args   = new Object[] { null, 1234567 };
            req.Method = "NilMethod";
            req.Mi     = GetType().GetMethod("NilMethod");
            var ser = new XmlRpcRequestSerializer();

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

            tr.ReadToEnd().ShouldBe(
                @"<?xml version=""1.0""?>
<methodCall>
    <methodName>NilMethod</methodName>
    <params>
        <param>
            <value>
                <nil />
            </value>
        </param>
        <param>
            <value>
                <i4>1234567</i4>
            </value>
        </param>
    </params>
</methodCall>");
        }
예제 #9
0
        public void SerializeWithMappingOnType()
        {
            Stream        stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();

            req.Args   = new object[] { IntEnum.Four };
            req.Method = "Bar";
            var proxy = XmlRpcProxyGen.Create <TestMethods2>();

            req.Mi = proxy.GetType().GetMethod("Bar");
            var ser = new XmlRpcRequestSerializer();

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

            Assert.AreEqual(@"<?xml version=""1.0""?>
<methodCall>
  <methodName>Bar</methodName>
  <params>
    <param>
      <value>
        <string>Four</string>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
        }
예제 #10
0
        public void SerializeRequestStructArrayWithNil()
        {
            var stm = new MemoryStream();
            var req = new XmlRpcRequest();

            req.Args = new Object[] { new StructWithArray {
                                          ints = new int?[] { 1, null, 3 }
                                      } };
            req.Method = "NilMethod";
            req.Mi     = GetType().GetMethod("NilMethod");
            var ser = new XmlRpcRequestSerializer();

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

            tr.ReadToEnd().ShouldBe(
                @"<?xml version=""1.0""?>
<methodCall>
    <methodName>NilMethod</methodName>
    <params>
        <param>
            <value>
                <struct>
                    <member>
                        <name>ints</name>
                        <value>
                            <array>
                                <data>
                                    <value>
                                        <i4>1</i4>
                                    </value>
                                    <value>
                                        <nil />
                                    </value>
                                    <value>
                                        <i4>3</i4>
                                    </value>
                                </data>
                            </array>
                        </value>
                    </member>
                </struct>
            </value>
        </param>
    </params>
</methodCall>");
        }
예제 #11
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;
            }
        }
예제 #12
0
        public void SerializeMassimo()
        {
            object[]      param1 = new object[] { "test/Gain1", "Gain", 1, 1, new[] { 0.5 } };
            object[]      param2 = new object[] { "test/METER", "P1", 1, 1, new[] { -1.0 } };
            Stream        stm    = new MemoryStream();
            XmlRpcRequest req    = new XmlRpcRequest();

            req.Args   = new object[] { "IFTASK", new object[] { param1, param2 } };
            req.Method = "Send_Param";
            req.Mi     = this.GetType().GetMethod("Send_Param");
            var ser = new XmlRpcRequestSerializer();

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

            Assert.AreEqual(massimoRequest, reqstr);
        }
예제 #13
0
        public void SerializeRequestArrayWithNull()
        {
            var stm   = new MemoryStream();
            var req   = new XmlRpcRequest();
            var array = new [] { "AAA", null, "CCC" };

            req.Args   = new Object[] { array };
            req.Method = "ArrayMethod";
            req.Mi     = GetType().GetMethod("ArrayMethod");
            var ser = new XmlRpcRequestSerializer();

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

            tr.ReadToEnd().ShouldBe(
                @"<?xml version=""1.0""?>
<methodCall>
    <methodName>ArrayMethod</methodName>
    <params>
        <param>
            <value>
                <array>
                    <data>
                        <value>
                            <string>AAA</string>
                        </value>
                        <value>
                            <nil />
                        </value>
                        <value>
                            <string>CCC</string>
                        </value>
                    </data>
                </array>
            </value>
        </param>
    </params>
</methodCall>");
        }
예제 #14
0
        public void SerializeRequestStructWithNil()
        {
            var stm = new MemoryStream();
            var req = new XmlRpcRequest();

            req.Args   = new Object[] { new Bounds() };
            req.Method = "NilMethod";
            req.Mi     = GetType().GetMethod("NilMethod");
            var ser = new XmlRpcRequestSerializer();

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

            tr.ReadToEnd().ShouldBe(
                @"<?xml version=""1.0""?>
<methodCall>
    <methodName>NilMethod</methodName>
    <params>
        <param>
            <value>
                <struct>
                    <member>
                        <name>lowerBound</name>
                        <value>
                            <nil />
                        </value>
                    </member>
                    <member>
                        <name>upperBound</name>
                        <value>
                            <nil />
                        </value>
                    </member>
                </struct>
            </value>
        </param>
    </params>
</methodCall>");
        }
예제 #15
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");
            var ser = new XmlRpcRequestSerializer();

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

            Assert.AreEqual(@"<?xml version=""1.0""?>
<methodCall>
  <methodName>FooZeroParameters</methodName>
</methodCall>", reqstr);
        }
예제 #16
0
        public void Class()
        {
            Stream stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();
            TestClass arg = new TestClass();
            arg._int = 456;
            arg._string = "Test Class";
            req.Args = new object[] { arg };
            req.Method = "Foo";
            var ser = new XmlRpcRequestSerializer();
            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr = new StreamReader(stm);
            string reqstr = tr.ReadToEnd();

            Assert.AreEqual(@"<?xml version=""1.0""?>
            <methodCall>
              <methodName>Foo</methodName>
              <params>
            <param>
              <value>
            <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);
        }
예제 #17
0
        public void SerializeIntNoParams()
        {
            Stream        stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();

            req.Args   = new object[] { new[] { 1, 2, 3 } };
            req.Method = "BarNotParams";
            req.Mi     = typeof(IFoo).GetMethod("BarNotParams");
            var ser = new XmlRpcRequestSerializer();

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

            Assert.AreEqual(@"<?xml version=""1.0""?>
<methodCall>
  <methodName>BarNotParams</methodName>
  <params>
    <param>
      <value>
        <array>
          <data>
            <value>
              <i4>1</i4>
            </value>
            <value>
              <i4>2</i4>
            </value>
            <value>
              <i4>3</i4>
            </value>
          </data>
        </array>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
        }
예제 #18
0
        public void NoParams2()
        {
            Stream stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();
            req.Args = new object[0];
            req.Method = "system.pid";
            req.Mi = this.GetType().GetMethod("getPid");
            var ser = new XmlRpcRequestSerializer();
            ser.Indentation = 2;
            ser.UseIntTag = true;
            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>system.pid</methodName>
            </methodCall>", reqstr);
        }
예제 #19
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");
      var ser = new XmlRpcRequestSerializer();
      ser.SerializeRequest(stm, req);
      stm.Position = 0;
      TextReader tr = new StreamReader(stm);
      string reqstr = tr.ReadToEnd();
      Assert.AreEqual(
        @"<?xml version=""1.0""?>
<methodCall>
  <methodName>BarNotParams</methodName>
  <params>
    <param>
      <value>
        <array>
          <data>
            <value>
              <i4>1</i4>
            </value>
            <value>
              <i4>2</i4>
            </value>
            <value>
              <i4>3</i4>
            </value>
          </data>
        </array>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
    }
예제 #20
0
    public void SerializeRequestStructArrayWithNil()
    {
      Stream stm = new MemoryStream();
      XmlRpcRequest req = new XmlRpcRequest();
      req.args = new Object[] { new StructWithArray { ints = new int?[] { 1, null, 3 } } };
      req.method = "NilMethod";
      req.mi = this.GetType().GetMethod("NilMethod");
      var ser = new XmlRpcRequestSerializer();
      ser.Indentation = 4;
      ser.SerializeRequest(stm, req);
      stm.Position = 0;
      TextReader tr = new StreamReader(stm);
      string reqstr = tr.ReadToEnd();
      Assert.AreEqual(
        @"<?xml version=""1.0""?>
<methodCall>
    <methodName>NilMethod</methodName>
    <params>
        <param>
            <value>
                <struct>
                    <member>
                        <name>ints</name>
                        <value>
                            <array>
                                <data>
                                    <value>
                                        <i4>1</i4>
                                    </value>
                                    <value>
                                        <nil />
                                    </value>
                                    <value>
                                        <i4>3</i4>
                                    </value>
                                </data>
                            </array>
                        </value>
                    </member>
                </struct>
            </value>
        </param>
    </params>
</methodCall>", reqstr);
    }
예제 #21
0
 public void StructParamsWithParams()
 {
     Stream stm = new MemoryStream();
     XmlRpcRequest req = new XmlRpcRequest();
     req.Args = new object[] { 1234, "test", new[] { 10.1 } };
     req.Method = "FooWithParams";
     req.Mi = this.GetType().GetMethod("FooWithParams");
     var ser = new XmlRpcRequestSerializer();
     ser.Indentation = 2;
     ser.UseIntTag = true;
     ser.SerializeRequest(stm, req);
 }
        //  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();
            var serializer = new XmlRpcRequestSerializer();
            serializer.SerializeRequest(stm, xmlRpcReq);
            stm.Position = 0;

            headers = reqHeaders;
            stream = stm;
        }
예제 #23
0
        public object Invoke(
            Object clientObj,
            MethodInfo mi,
            params object[] parameters)
        {
#if (SILVERLIGHT)
            throw new NotSupportedException();
#else
            _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);
#if (!COMPACT_FRAMEWORK)
                SetClientCertificates(ClientCertificates, webReq);
#endif
                Stream serStream = null;
                Stream reqStream = null;
                bool   logging   = (RequestEvent != null);
                if (!logging)
                {
                    serStream = reqStream = webReq.GetRequestStream();
                }
                else
                {
                    serStream = new MemoryStream(2000);
                }
                try
                {
                    var serializer = new XmlRpcRequestSerializer(XmlRpcFormatSettings);
                    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 (!COMPACT_FRAMEWORK && !FX1_0)
                    respStm = MaybeDecompressStream((HttpWebResponse)webResp,
                                                    respStm);
#endif
                    if (!logging)
                    {
                        deserStream = respStm;
                    }
                    else
                    {
                        deserStream = new MemoryStream(2000);
                        Util.CopyStream(respStm, deserStream);
                        deserStream.Flush();
                        deserStream.Position = 0;
                    }
                    if (logging)
                    {
                        OnResponse(new XmlRpcResponseEventArgs(req.proxyId, req.number,
                                                               deserStream));
                        deserStream.Position = 0;
                    }
                    XmlRpcResponse resp = ReadResponse(req, webResp, deserStream);
                    reto = resp.retVal;
                }
                finally
                {
                    if (respStm != null)
                    {
                        respStm.Close();
                    }
                }
            }
            finally
            {
                if (webReq != null)
                {
                    webReq = null;
                }
            }
            return(reto);
#endif
        }
예제 #24
0
        public void LFString()
        {
            Stream stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();
            req.Args = new object[] { "\n" };
            req.Method = "Foo";
            var ser = new XmlRpcRequestSerializer();
            ser.UseStringTag = true;
            ser.Indentation = 4;
            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr = new StreamReader(stm);
            string reqstr = tr.ReadToEnd();

            Assert.AreEqual(@"<?xml version=""1.0""?>
            <methodCall>
            <methodName>Foo</methodName>
            <params>
            <param>
            <value>
                " + "<string>\n</string>" + @"
            </value>
            </param>
            </params>
            </methodCall>", reqstr);
        }
예제 #25
0
 public void RecursiveMemberTest()
 {
     Stream stm = new MemoryStream();
     XmlRpcRequest req = new XmlRpcRequest();
     var example = new RecursiveMember
                       {
                           Level = "1",
                           childExample =
                               new RecursiveMember
                                   {
                                       Level = "2",
                                       childExample =
                                           new RecursiveMember { Level = "3", }
                                   }
                       };
     req.Args = new object[] { example };
     req.Method = "Foo";
     var ser = new XmlRpcRequestSerializer();
     ser.UseStringTag = 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>
     <struct>
       <member>
     <name>Level</name>
     <value>1</value>
       </member>
       <member>
     <name>childExample</name>
     <value>
       <struct>
         <member>
           <name>Level</name>
           <value>2</value>
         </member>
         <member>
           <name>childExample</name>
           <value>
             <struct>
               <member>
                 <name>Level</name>
                 <value>3</value>
               </member>
             </struct>
           </value>
         </member>
       </struct>
     </value>
       </member>
     </struct>
       </value>
     </param>
       </params>
     </methodCall>", reqstr);
 }
예제 #26
0
 public void PropertyMemberName()
 {
     Stream stm = new MemoryStream();
     XmlRpcRequest req = new XmlRpcRequest();
     req.Args = new object[] { new TestPropertyMemberName { Title1 = "abc", Title2 = "def" } };
     req.Method = "Foo";
     var ser = new XmlRpcRequestSerializer();
     ser.UseStringTag = true;
     ser.Indentation = 2;
     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>title2</name>
     <value>
       <string>def</string>
     </value>
       </member>
       <member>
     <name>title1</name>
     <value>
       <string>abc</string>
     </value>
       </member>
     </struct>
       </value>
     </param>
       </params>
     </methodCall>", reqstr);
 }
예제 #27
0
 public void NullMappingNil()
 {
     Stream stm = new MemoryStream();
     XmlRpcRequest req = new XmlRpcRequest();
     req.Args = new object[] { new NullMappingNilStruct() };
     req.Method = "Foo";
     var ser = new XmlRpcRequestSerializer();
     ser.SerializeRequest(stm, req);
     stm.Position = 0;
     TextReader tr = new StreamReader(stm);
     string reqstr = tr.ReadToEnd();
     Assert.AreEqual(@"<?xml version=""1.0""?>
     <methodCall>
       <methodName>Foo</methodName>
       <params>
     <param>
       <value>
     <struct>
       <member>
     <name>s</name>
     <value>
       <nil />
     </value>
       </member>
       <member>
     <name>i</name>
     <value>
       <nil />
     </value>
       </member>
     </struct>
       </value>
     </param>
       </params>
     </methodCall>", reqstr);
 }
예제 #28
0
        public void ZeroLengthBas64()
        {
            Stream stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();
            req.Args = new object[] { new byte[0] };
            req.Method = "Foo";
            var ser = new XmlRpcRequestSerializer();
            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr = new StreamReader(stm);
            string reqstr = tr.ReadToEnd();

            Assert.AreEqual(@"<?xml version=""1.0""?>
            <methodCall>
              <methodName>Foo</methodName>
              <params>
            <param>
              <value>
            <base64 />
              </value>
            </param>
              </params>
            </methodCall>", reqstr);
        }
    public void SerializeWithMappingOnInterface()
    {
      Stream stm = new MemoryStream();
      XmlRpcRequest req = new XmlRpcRequest();
      req.args = new Object[] 
      { 
        IntEnum.Zero,
        new IntEnum[] { IntEnum.One, IntEnum.Two },
        new ItfEnumClass
        { 
          IntEnum = ItfEnum.One, 
          intEnum = ItfEnum.Two,
          IntEnums = new ItfEnum[] { ItfEnum.One, ItfEnum.Two },
          intEnums = new ItfEnum[] { ItfEnum.Three, ItfEnum.Four },
        } 
      };
      req.method = "MappingOnMethod";
      req.mi = this.GetType().GetMethod("MappingOnMethod");
      var ser = new XmlRpcRequestSerializer();
      ser.SerializeRequest(stm, req);
      stm.Position = 0;
      TextReader tr = new StreamReader(stm);
      string reqstr = tr.ReadToEnd();

      Assert.AreEqual(
        @"<?xml version=""1.0""?>
<methodCall>
  <methodName>MappingOnMethod</methodName>
  <params>
    <param>
      <value>
        <string>Zero</string>
      </value>
    </param>
    <param>
      <value>
        <array>
          <data>
            <value>
              <string>One</string>
            </value>
            <value>
              <string>Two</string>
            </value>
          </data>
        </array>
      </value>
    </param>
    <param>
      <value>
        <struct>
          <member>
            <name>IntEnum</name>
            <value>
              <string>One</string>
            </value>
          </member>
          <member>
            <name>IntEnums</name>
            <value>
              <array>
                <data>
                  <value>
                    <string>One</string>
                  </value>
                  <value>
                    <string>Two</string>
                  </value>
                </data>
              </array>
            </value>
          </member>
          <member>
            <name>intEnum</name>
            <value>
              <string>Two</string>
            </value>
          </member>
          <member>
            <name>intEnums</name>
            <value>
              <array>
                <data>
                  <value>
                    <string>Three</string>
                  </value>
                  <value>
                    <string>Four</string>
                  </value>
                </data>
              </array>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
    }
예제 #30
0
        public void DefaultFormatting()
        {
            Stream stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();
            req.Args = new object[] { 1234567 };
            req.Method = "Foo";
            var ser = new XmlRpcRequestSerializer();
            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr = new StreamReader(stm);
            string reqstr = tr.ReadToEnd();

            Assert.AreEqual(@"<?xml version=""1.0""?>
            <methodCall>
              <methodName>Foo</methodName>
              <params>
            <param>
              <value>
            <i4>1234567</i4>
              </value>
            </param>
              </params>
            </methodCall>", reqstr);
        }
예제 #31
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;
                    var           serializer = new XmlRpcRequestSerializer();
                    if (clientResult.XmlRpcFormatSettings.XmlEncoding != null)
                    {
                        serializer.XmlEncoding = clientResult.XmlRpcFormatSettings.XmlEncoding;
                    }
                    serializer.UseEmptyElementTags = clientResult.XmlRpcFormatSettings.UseEmptyElementTags;
                    serializer.UseEmptyParamsTag   = clientResult.XmlRpcFormatSettings.UseEmptyParamsTag;
                    serializer.UseIndentation      = clientResult.XmlRpcFormatSettings.UseIndentation;
                    serializer.Indentation         = clientResult.XmlRpcFormatSettings.Indentation;
                    serializer.UseIntTag           = clientResult.XmlRpcFormatSettings.UseIntTag;
                    serializer.UseStringTag        = clientResult.XmlRpcFormatSettings.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);
            }
        }
예제 #32
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="clientObj"></param>
        /// <param name="mi"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public object Invoke(
          Object clientObj,
          MethodInfo mi,
          params object[] parameters)
        {
#if (SILVERLIGHT)
      throw new NotSupportedException();
#else

#if (!COMPACT_FRAMEWORK)
            _responseHeaders = null;
            _responseCookies = null;
#endif
            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);
#if (!COMPACT_FRAMEWORK)
                SetClientCertificates(ClientCertificates, webReq);
#endif
                Stream serStream = null;
                Stream reqStream = null;
                bool logging = (RequestEvent != null);
                if (!logging)
                    serStream = reqStream = webReq.GetRequestStream();
                else
                    serStream = new MemoryStream(2000);
                try
                {
                    var serializer = new XmlRpcRequestSerializer(XmlRpcFormatSettings);
                    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;
#if (!COMPACT_FRAMEWORK)
                _responseCookies = webResp.Cookies;
                _responseHeaders = webResp.Headers;
#endif
                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;
                    }
#if (!COMPACT_FRAMEWORK && !FX1_0)
                    deserStream = MaybeDecompressStream((HttpWebResponse)webResp,
                      deserStream);
#endif
                    if (logging)
                    {
                        OnResponse(new XmlRpcResponseEventArgs(req.proxyId, req.number,
                          deserStream));
                        deserStream.Position = 0;
                    }
                    XmlRpcResponse resp = ReadResponse(req, webResp, deserStream);
                    reto = resp.retVal;
                }
                finally
                {
                    if (respStm != null)
                        respStm.Close();
                }
            }
            finally
            {
                if (webReq != null)
                    webReq = null;
            }
            return reto;
#endif
        }
예제 #33
0
 public void SerializeMassimo()
 {
   object[] param1 = new object[] { "test/Gain1", "Gain", 1, 1, 
                                    new double[] { 0.5 } };
   object[] param2 = new object[] { "test/METER", "P1", 1, 1, 
                                    new double[] { -1.0 } };
   Stream stm = new MemoryStream();
   XmlRpcRequest req = new XmlRpcRequest();
   req.args = new Object[] { "IFTASK", 
     new object[] { param1, param2 } };
   req.method = "Send_Param";
   req.mi = this.GetType().GetMethod("Send_Param");
   var ser = new XmlRpcRequestSerializer();
   ser.SerializeRequest(stm, req);
   stm.Position = 0;
   TextReader tr = new StreamReader(stm);
   string reqstr = tr.ReadToEnd();
   Assert.AreEqual(massimoRequest, reqstr);
 }
예제 #34
0
        public void StructParams()
        {
            Stream stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();
            req.Args = new object[] { 1234, "test", 10.1 };
            req.Method = "Foo";
            req.Mi = this.GetType().GetMethod("Foo");
            var ser = new XmlRpcRequestSerializer();
            ser.Indentation = 2;
            ser.UseIntTag = true;
            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>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);
        }
예제 #35
0
        public void XmlRpcMember()
        {
            Stream stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();
            req.Args = new object[] { new Struct2 { member1 = 1, member4 = 4 } };
            req.Method = "Foo";
            var ser = new XmlRpcRequestSerializer();
            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr = new StreamReader(stm);
            string reqstr = tr.ReadToEnd();

            Assert.AreEqual(@"<?xml version=""1.0""?>
            <methodCall>
              <methodName>Foo</methodName>
              <params>
            <param>
              <value>
            <struct>
              <member>
            <name>member_4</name>
            <value>
              <i4>4</i4>
            </value>
              </member>
              <member>
            <name>member_1</name>
            <value>
              <i4>1</i4>
            </value>
              </member>
            </struct>
              </value>
            </param>
              </params>
            </methodCall>", reqstr);
        }
예제 #36
0
    public void SerializeRequest()
    {
      Stream stm = new MemoryStream();
      XmlRpcRequest req = new XmlRpcRequest();
      req.args = new Object[] { IntEnum.Two };
      req.method = "Foo";
      var ser = new XmlRpcRequestSerializer();
      ser.SerializeRequest(stm, req);
      stm.Position = 0;
      TextReader tr = new StreamReader(stm);
      string reqstr = tr.ReadToEnd();

      Assert.AreEqual(
        @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Foo</methodName>
  <params>
    <param>
      <value>
        <i4>2</i4>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
    }
예제 #37
0
        public void StructParamsGetInfo()
        {
            Stream stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();
            req.Args = new object[] { "Bob Dylan", "abcd1234" };
            req.Method = "artist.getInfo";
            req.Mi = this.GetType().GetMethod("getInfo");
            var ser = new XmlRpcRequestSerializer();
            ser.Indentation = 2;
            ser.UseIntTag = true;
            ser.SerializeRequest(stm, req);
            stm.Position = 0;
            TextReader tr = new StreamReader(stm);
            string 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);
        }
예제 #38
0
    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;
      }
    }
예제 #39
0
    public void SerializeRequestArrayWithNull()
    {
      Stream stm = new MemoryStream();
      XmlRpcRequest req = new XmlRpcRequest();
      string[] array = new string[] { "AAA", null, "CCC" };
      req.args = new Object[] { array };
      req.method = "ArrayMethod";
      req.mi = this.GetType().GetMethod("ArrayMethod");
      var ser = new XmlRpcRequestSerializer();
      ser.Indentation = 4;
      ser.SerializeRequest(stm, req);
      stm.Position = 0;
      TextReader tr = new StreamReader(stm);
      string reqstr = tr.ReadToEnd();
      Assert.AreEqual(
        @"<?xml version=""1.0""?>
<methodCall>
    <methodName>ArrayMethod</methodName>
    <params>
        <param>
            <value>
                <array>
                    <data>
                        <value>
                            <string>AAA</string>
                        </value>
                        <value>
                            <nil />
                        </value>
                        <value>
                            <string>CCC</string>
                        </value>
                    </data>
                </array>
            </value>
        </param>
    </params>
</methodCall>", reqstr);
    }
예제 #40
0
 public void NonSerializedWithInvalidType()
 {
     Stream stm = new MemoryStream();
     XmlRpcRequest req = new XmlRpcRequest();
     req.Args = new object[] { new Struct5 { ds = new System.Data.DataSet(), y = 1234 } };
     req.Method = "Foo";
     var ser = new XmlRpcRequestSerializer();
     ser.SerializeRequest(stm, req);
     stm.Position = 0;
     TextReader tr = new StreamReader(stm);
     string reqstr = tr.ReadToEnd();
     Assert.AreEqual(@"<?xml version=""1.0""?>
     <methodCall>
       <methodName>Foo</methodName>
       <params>
     <param>
       <value>
     <struct>
       <member>
     <name>y</name>
     <value>
       <i4>1234</i4>
     </value>
       </member>
     </struct>
       </value>
     </param>
       </params>
     </methodCall>", reqstr);
 }
예제 #41
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");
      var ser = new XmlRpcRequestSerializer();
      ser.UseEmptyParamsTag = false;
      ser.SerializeRequest(stm, req);
      stm.Position = 0;
      TextReader tr = new StreamReader(stm);
      string reqstr = tr.ReadToEnd();
      Assert.AreEqual(
        @"<?xml version=""1.0""?>
<methodCall>
  <methodName>FooZeroParameters</methodName>
</methodCall>", reqstr);
    }
예제 #42
0
        public void NoIndentation()
        {
            Stream stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();
            req.Args = new object[] { 1234567 };
            req.Method = "Foo";
            var ser = new XmlRpcRequestSerializer();
            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);
        }
예제 #43
0
    public void SerializeWithMappingOnType()
    {
      Stream stm = new MemoryStream();
      XmlRpcRequest req = new XmlRpcRequest();
      req.args = new object[] { IntEnum.Four };
      req.method = "Bar";
      var proxy = XmlRpcProxyGen.Create<TestMethods2>();
      req.mi = proxy.GetType().GetMethod("Bar");
      var ser = new XmlRpcRequestSerializer();
      ser.SerializeRequest(stm, req);
      stm.Position = 0;
      TextReader tr = new StreamReader(stm);
      string reqstr = tr.ReadToEnd();
      Assert.AreEqual(
        @"<?xml version=""1.0""?>
<methodCall>
  <methodName>Bar</methodName>
  <params>
    <param>
      <value>
        <string>Four</string>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
    }
예제 #44
0
        public void SerializeWithMappingOnInterface()
        {
            Stream        stm = new MemoryStream();
            XmlRpcRequest req = new XmlRpcRequest();

            req.Args = new Object[]
            {
                IntEnum.Zero,
                new IntEnum[] { IntEnum.One, IntEnum.Two },
                new ItfEnumClass
                {
                    IntEnum  = ItfEnum.One,
                    intEnum  = ItfEnum.Two,
                    IntEnums = new ItfEnum[] { ItfEnum.One, ItfEnum.Two },
                    intEnums = new ItfEnum[] { ItfEnum.Three, ItfEnum.Four },
                }
            };
            req.Method = "MappingOnMethod";
            req.Mi     = this.GetType().GetMethod("MappingOnMethod");
            var ser = new XmlRpcRequestSerializer();

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

            Assert.AreEqual(
                @"<?xml version=""1.0""?>
<methodCall>
  <methodName>MappingOnMethod</methodName>
  <params>
    <param>
      <value>
        <string>Zero</string>
      </value>
    </param>
    <param>
      <value>
        <array>
          <data>
            <value>
              <string>One</string>
            </value>
            <value>
              <string>Two</string>
            </value>
          </data>
        </array>
      </value>
    </param>
    <param>
      <value>
        <struct>
          <member>
            <name>IntEnum</name>
            <value>
              <string>One</string>
            </value>
          </member>
          <member>
            <name>IntEnums</name>
            <value>
              <array>
                <data>
                  <value>
                    <string>One</string>
                  </value>
                  <value>
                    <string>Two</string>
                  </value>
                </data>
              </array>
            </value>
          </member>
          <member>
            <name>intEnum</name>
            <value>
              <string>Two</string>
            </value>
          </member>
          <member>
            <name>intEnums</name>
            <value>
              <array>
                <data>
                  <value>
                    <string>Three</string>
                  </value>
                  <value>
                    <string>Four</string>
                  </value>
                </data>
              </array>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
        }
예제 #45
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;
             var serializer = new XmlRpcRequestSerializer();
             if (clientResult.XmlRpcFormatSettings.XmlEncoding != null)
                 serializer.XmlEncoding = clientResult.XmlRpcFormatSettings.XmlEncoding;
             serializer.UseEmptyElementTags = clientResult.XmlRpcFormatSettings.UseEmptyElementTags;
             serializer.UseEmptyParamsTag = clientResult.XmlRpcFormatSettings.UseEmptyParamsTag;
             serializer.UseIndentation = clientResult.XmlRpcFormatSettings.UseIndentation;
             serializer.Indentation = clientResult.XmlRpcFormatSettings.Indentation;
             serializer.UseIntTag = clientResult.XmlRpcFormatSettings.UseIntTag;
             serializer.UseStringTag = clientResult.XmlRpcFormatSettings.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);
     }
 }
예제 #46
0
    public void SerializeRequestWithEnumStringParam()
    {
      Stream stm = new MemoryStream();
      XmlRpcRequest req = new XmlRpcRequest();
      req.args = new Object[] { IntEnum.Two };
      req.method = "EnumMethod1";
      req.mi = this.GetType().GetMethod("EnumMethod1");
      var ser = new XmlRpcRequestSerializer();
      ser.SerializeRequest(stm, req);
      stm.Position = 0;
      TextReader tr = new StreamReader(stm);
      string reqstr = tr.ReadToEnd();

      Assert.AreEqual(
        @"<?xml version=""1.0""?>
<methodCall>
  <methodName>EnumMethod1</methodName>
  <params>
    <param>
      <value>
        <string>Two</string>
      </value>
    </param>
  </params>
</methodCall>", reqstr);
    }