public void SerializeRequest(Stream stm, XmlRpcRequest request)
 {
     var xtw = XmlRpcXmlWriter.Create(stm, XmlRpcFormatSettings);
     xtw.WriteStartDocument();
     xtw.WriteStartElement(string.Empty, "methodCall", string.Empty);
     {
         var mappingActions = new MappingActions();
         mappingActions = GetTypeMappings(request.Mi, mappingActions);
         mappingActions = GetMappingActions(request.Mi, mappingActions);
         WriteFullElementString(xtw, "methodName", request.Method);
         if (request.Args.Length > 0 || UseEmptyParamsTag)
         {
             xtw.WriteStartElement("params");
             try
             {
                 if (!IsStructParamsMethod(request.Mi))
                     SerializeParams(xtw, request, mappingActions);
                 else
                     SerializeStructParams(xtw, request, mappingActions);
             }
             catch (XmlRpcUnsupportedTypeException ex)
             {
                 throw new XmlRpcUnsupportedTypeException(
                     ex.UnsupportedType,
                     string.Format(
                         "A parameter is of, or contains an instance of, type {0} which cannot be mapped to an XML-RPC type",
                         ex.UnsupportedType));
             }
             WriteFullEndElement(xtw);
         }
     }
     WriteFullEndElement(xtw);
     xtw.Flush();
 }
 public XmlRpcResponse Invoke(XmlRpcRequest request)
 {
   MethodInfo mi = null;
   if (request.mi != null)
   {
     mi = request.mi;
   }
   else
   {
     mi = this.GetType().GetMethod(request.method);
   }
   // exceptions thrown during an MethodInfo.Invoke call are
   // package as inner of 
   Object reto;
   try
   {
     reto = mi.Invoke(this, request.args);
   }
   catch(Exception ex)
   {
     if (ex.InnerException != null)
       throw ex.InnerException;
     throw ex;
   }
   // methods which have void return type always return integer 0
   // because XML-RPC doesn't support no return type (could use nil
   // but want to maintain backwards compatibility in this area)
   if (mi != null && mi.ReturnType == typeof(void))
     reto = 0;
   XmlRpcResponse response = new XmlRpcResponse(reto);
   return response;
 }
Beispiel #3
0
 public XmlRpcResponse Invoke(XmlRpcRequest request)
 {
     MethodInfo mi = null;
       if (request.mi != null)
       {
     mi = request.mi;
       }
       else
       {
     mi = this.GetType().GetMethod(request.method);
       }
       // exceptions thrown during an MethodInfo.Invoke call are
       // package as inner of
       Object reto;
       try
       {
     reto = mi.Invoke(this, request.args);
       }
       catch(Exception ex)
       {
     if (ex.InnerException != null)
       throw ex.InnerException;
     throw ex;
       }
       XmlRpcResponse response = new XmlRpcResponse(reto);
       return response;
 }
Beispiel #4
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);
    }
 //internal members
 internal XmlRpcAsyncResult(
     XmlRpcClientProtocol ClientProtocol,
     XmlRpcRequest XmlRpcReq,
     Encoding XmlEncoding,
     bool useEmptyParamsTag,
     bool useIndentation,
     int indentation,
     bool UseIntTag,
     bool UseStringTag,
     WebRequest Request,
     AsyncCallback UserCallback,
     object UserAsyncState,
     int retryNumber)
 {
     xmlRpcRequest = XmlRpcReq;
       clientProtocol = ClientProtocol;
       request = Request;
       userAsyncState = UserAsyncState;
       userCallback = UserCallback;
       _completedSynchronously = true;
       xmlEncoding = XmlEncoding;
       _useEmptyParamsTag = useEmptyParamsTag;
       _useIndentation = useIndentation;
       _indentation = indentation;
       this.UseIntTag = UseIntTag;
       this.UseStringTag = UseStringTag;
 }
Beispiel #6
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);
    }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="stm"></param>
 /// <param name="request"></param>
 public void SerializeRequest(Stream stm, XmlRpcRequest request)
 {
     XmlWriter xtw = XmlRpcXmlWriter.Create(stm, base.XmlRpcFormatSettings);
     xtw.WriteStartDocument();
     xtw.WriteStartElement("", "methodCall", "");
     {
         // TODO: use global action setting
         NullMappingAction mappingAction = NullMappingAction.Error;
         WriteFullElementString(xtw, "methodName", request.method);
         if (request.args.Length > 0 || UseEmptyParamsTag)
         {
             xtw.WriteStartElement("params");
             try
             {
                 if (!IsStructParamsMethod(request.mi))
                     SerializeParams(xtw, request, mappingAction);
                 else
                     SerializeStructParams(xtw, request, mappingAction);
             }
             catch (XmlRpcUnsupportedTypeException ex)
             {
                 throw new XmlRpcUnsupportedTypeException(ex.UnsupportedType,
                   String.Format("A parameter is of, or contains an instance of, "
                   + "type {0} which cannot be mapped to an XML-RPC type",
                   ex.UnsupportedType));
             }
             WriteFullEndElement(xtw);
         }
     }
     WriteFullEndElement(xtw);
     xtw.Flush();
 }
Beispiel #8
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>");
        }
 //internal members
 internal XmlRpcAsyncResult(
     XmlRpcClientProtocol ClientProtocol, 
     XmlRpcRequest XmlRpcReq, 
     XmlRpcFormatSettings xmlRpcFormatSettings,
     WebRequest Request, 
     AsyncCallback UserCallback, 
     object UserAsyncState)
 {
     XmlRpcRequest = XmlRpcReq;
     _clientProtocol = ClientProtocol;
     _request = Request;
     _userAsyncState = UserAsyncState;
     _userCallback = UserCallback;
     _completedSynchronously = true;
     XmlRpcFormatSettings = xmlRpcFormatSettings;
 }
Beispiel #10
0
   //internal members
   internal XmlRpcAsyncResult(
 XmlRpcClientProtocol ClientProtocol, 
 XmlRpcRequest XmlRpcReq, 
 XmlRpcFormatSettings xmlRpcFormatSettings,
 WebRequest Request, 
 AsyncCallback UserCallback, 
 object UserAsyncState, 
 int retryNumber)
   {
       xmlRpcRequest = XmlRpcReq;
         clientProtocol = ClientProtocol;
         request = Request;
         userAsyncState = UserAsyncState;
         userCallback = UserCallback;
         completedSynchronously = true;
         XmlRpcFormatSettings = xmlRpcFormatSettings;
   }
 void SerializeParams(XmlWriter xtw, XmlRpcRequest request,
   MappingActions mappingActions)
 {
   ParameterInfo[] pis = null;
   if (request.mi != null)
   {
     pis = request.mi.GetParameters();
   }
   for (int i = 0; i < request.args.Length; i++)
   {
     var paramMappingActions = pis == null ? mappingActions
       : GetMappingActions(pis[i], mappingActions);
     if (pis != null)
     {
       if (i >= pis.Length)
         throw new XmlRpcInvalidParametersException("Number of request "
           + "parameters greater than number of proxy method parameters.");
       if (i == pis.Length - 1
         && Attribute.IsDefined(pis[i], typeof(ParamArrayAttribute)))
       {
         Array ary = (Array)request.args[i];
         foreach (object o in ary)
         {
           //if (o == null)
           //  throw new XmlRpcNullParameterException(
           //    "Null parameter in params array");
           xtw.WriteStartElement("", "param", "");
           Serialize(xtw, o, paramMappingActions);
           WriteFullEndElement(xtw);
         }
         break;
       }
     }
     //if (request.args[i] == null)
     //{
     //  throw new XmlRpcNullParameterException(String.Format(
     //    "Null method parameter #{0}", i + 1));
     //}
     xtw.WriteStartElement("", "param", "");
     Serialize(xtw, request.args[i], paramMappingActions);
     WriteFullEndElement(xtw);
   }
 }
Beispiel #12
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);
        }
Beispiel #13
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);
    }
 public void SerializeRequest(Stream stm, XmlRpcRequest request)
 {
     XmlTextWriter xtw = new XmlTextWriter(stm, m_encoding);
     ConfigureXmlFormat(xtw);
     xtw.WriteStartDocument();
     xtw.WriteStartElement("", "methodCall", "");
     {
         // TODO: use global action setting
         MappingAction mappingAction = MappingAction.Error;
         if (request.xmlRpcMethod == null)
             xtw.WriteElementString("methodName", request.method);
         else
             xtw.WriteElementString("methodName", request.xmlRpcMethod);
         if (request.args.Length > 0 || UseEmptyParamsTag)
         {
             xtw.WriteStartElement("", "params", "");
             try
             {
                 if (!IsStructParamsMethod(request.mi))
                     SerializeParams(xtw, request, mappingAction);
                 else
                     SerializeStructParams(xtw, request, mappingAction);
             }
             catch (XmlRpcUnsupportedTypeException ex)
             {
                 throw new XmlRpcUnsupportedTypeException(ex.UnsupportedType,
                   String.Format("A parameter is of, or contains an instance of, "
                   + "type {0} which cannot be mapped to an XML-RPC type",
                   ex.UnsupportedType));
             }
             xtw.WriteEndElement();
         }
     }
     xtw.WriteEndElement();
     xtw.Flush();
 }
Beispiel #15
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);
    }
Beispiel #16
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);
    }
        //  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;
        }
Beispiel #18
0
        public object Invoke(
            Object clientObj,
            MethodInfo mi,
            params object[] parameters)
        {
#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
                {
                    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;
#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
                    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);
        }
Beispiel #19
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);
        }
 public void SerializeRequest(Stream stm, XmlRpcRequest request)
 {
     XmlTextWriter xtw = new XmlTextWriter(stm, m_encoding);
       ConfigureXmlFormat(xtw);
       xtw.WriteStartDocument();
       xtw.WriteStartElement("", "methodCall", "");
     {
       ParameterInfo[] pis = null;
       if (request.mi != null)
       {
     pis = request.mi.GetParameters();
       }
       // TODO: use global action setting
       MappingAction mappingAction = MappingAction.Error;
       if (request.xmlRpcMethod == null)
     xtw.WriteElementString("methodName", request.method);
       else
     xtw.WriteElementString("methodName", request.xmlRpcMethod);
       if (request.args.Length > 0 || UseEmptyParamsTag)
       {
     xtw.WriteStartElement("", "params", "");
     try
     {
       for (int i = 0; i < request.args.Length; i++)
       {
     if (pis != null)
     {
       if (i >= pis.Length)
         throw new XmlRpcInvalidParametersException("Number of request "
           + "parameters greater than number of proxy method parameters.");
       if (Attribute.IsDefined(pis[i], typeof(ParamArrayAttribute)))
       {
         Array ary = (Array)request.args[i];
         foreach (object o in ary)
         {
           if (o == null)
             throw new XmlRpcNullParameterException(
               "Null parameter in params array");
           xtw.WriteStartElement("", "param", "");
           Serialize(xtw, o, mappingAction);
           xtw.WriteEndElement();
         }
         break;
       }
     }
     if (request.args[i] == null)
     {
       throw new XmlRpcNullParameterException(String.Format(
         "Null method parameter #{0}", i + 1));
     }
     xtw.WriteStartElement("", "param", "");
     Serialize(xtw, request.args[i], mappingAction);
     xtw.WriteEndElement();
       }
     }
     catch (XmlRpcUnsupportedTypeException ex)
     {
       throw new XmlRpcUnsupportedTypeException(ex.UnsupportedType,
     String.Format("A parameter is of, or contains an instance of, "
     + "type {0} which cannot be mapped to an XML-RPC type",
     ex.UnsupportedType));
     }
     xtw.WriteEndElement();
       }
     }
       xtw.WriteEndElement();
       xtw.Flush();
 }
 XmlRpcResponse ReadResponse(
   XmlRpcRequest req,
   WebResponse webResp,
   Stream respStm)
 {
     HttpWebResponse httpResp = (HttpWebResponse)webResp;
     if (httpResp.StatusCode != HttpStatusCode.OK)
     {
         // status 400 is used for errors caused by the client
         // status 500 is used for server errors (not server application
         // errors which are returned as fault responses)
         if (httpResp.StatusCode == HttpStatusCode.BadRequest)
             throw new XmlRpcException(httpResp.StatusDescription);
         else
             throw new XmlRpcServerException(httpResp.StatusDescription);
     }
     var deserializer = new XmlRpcResponseDeserializer();
     deserializer.NonStandard = _nonStandard;
     Type retType = req.mi.ReturnType;
     XmlRpcResponse xmlRpcResp
       = deserializer.DeserializeResponse(respStm, retType);
     return xmlRpcResp;
 }
Beispiel #22
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
        }
Beispiel #23
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);
            }
        }
Beispiel #24
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);
    }
    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);
    }
Beispiel #26
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);
 }
Beispiel #27
0
        public XmlRpcRequest DeserializeRequest(XmlReader rdr, Type svcType)
        {
            try
            {
                XmlRpcRequest      request = new XmlRpcRequest();
                IEnumerator <Node> iter    = new XmlRpcParser().ParseRequest(rdr).GetEnumerator();

                iter.MoveNext();
                string methodName = (iter.Current as MethodName).Name;
                request.method = methodName;

                request.mi = null;
                ParameterInfo[] pis = null;
                if (svcType != null)
                {
                    // retrieve info for the method which handles this XML-RPC method
                    XmlRpcServiceInfo svcInfo
                               = XmlRpcServiceInfo.CreateServiceInfo(svcType);
                    request.mi = svcInfo.GetMethodInfo(request.method);
                    // if a service type has been specified and we cannot find the requested
                    // method then we must throw an exception
                    if (request.mi == null)
                    {
                        string msg = String.Format("unsupported method called: {0}",
                                                   request.method);
                        throw new XmlRpcUnsupportedMethodException(msg);
                    }
                    // method must be marked with XmlRpcMethod attribute
                    Attribute attr = Attribute.GetCustomAttribute(request.mi,
                                                                  typeof(XmlRpcMethodAttribute));
                    if (attr == null)
                    {
                        throw new XmlRpcMethodAttributeException(
                                  "Method must be marked with the XmlRpcMethod attribute.");
                    }
                    pis = request.mi.GetParameters();
                }

                bool gotParams = iter.MoveNext();
                if (!gotParams)
                {
                    if (svcType != null)
                    {
                        if (pis.Length == 0)
                        {
                            request.args = new object[0];
                            return(request);
                        }
                        else
                        {
                            throw new XmlRpcInvalidParametersException(
                                      "Method takes parameters and params element is missing.");
                        }
                    }
                    else
                    {
                        request.args = new object[0];
                        return(request);
                    }
                }

                int paramsPos = pis != null?GetParamsPos(pis) : -1;

                Type paramsType = null;
                if (paramsPos != -1)
                {
                    paramsType = pis[paramsPos].ParameterType.GetElementType();
                }
                int minParamCount = pis == null ? int.MaxValue
          : (paramsPos == -1 ? pis.Length : paramsPos);
                MappingStack  mappingStack  = new MappingStack("request");
                MappingAction mappingAction = MappingAction.Error;
                var           objs          = new List <object>();
                var           paramsObjs    = new List <object>();
                int           paramCount    = 0;


                while (iter.MoveNext())
                {
                    paramCount++;
                    if (svcType != null && paramCount > minParamCount && paramsPos == -1)
                    {
                        throw new XmlRpcInvalidParametersException(
                                  "Request contains too many param elements based on method signature.");
                    }
                    if (paramCount <= minParamCount)
                    {
                        if (svcType != null)
                        {
                            mappingStack.Push(String.Format("parameter {0}", paramCount));
                            // TODO: why following commented out?
                            //          parseStack.Push(String.Format("parameter {0} mapped to type {1}",
                            //            i, pis[i].ParameterType.Name));
                            var obj = MapValueNode(iter,
                                                   pis[paramCount - 1].ParameterType, mappingStack, mappingAction);
                            objs.Add(obj);
                        }
                        else
                        {
                            mappingStack.Push(String.Format("parameter {0}", paramCount));
                            var obj = MapValueNode(iter, null, mappingStack, mappingAction);
                            objs.Add(obj);
                        }
                        mappingStack.Pop();
                    }
                    else
                    {
                        mappingStack.Push(String.Format("parameter {0}", paramCount + 1));
                        var paramsObj = MapValueNode(iter, paramsType, mappingStack, mappingAction);
                        paramsObjs.Add(paramsObj);
                        mappingStack.Pop();
                    }
                }

                if (svcType != null && paramCount < minParamCount)
                {
                    throw new XmlRpcInvalidParametersException(
                              "Request contains too few param elements based on method signature.");
                }

                if (paramsPos != -1)
                {
                    Object[] args = new Object[1];
                    args[0] = paramCount - minParamCount;
                    Array varargs = (Array)Activator.CreateInstance(pis[paramsPos].ParameterType, args);
                    for (int i = 0; i < paramsObjs.Count; i++)
                    {
                        varargs.SetValue(paramsObjs[i], i);
                    }
                    objs.Add(varargs);
                }
                request.args = objs.ToArray();
                return(request);
            }
            catch (XmlException ex)
            {
                NPx.Log.Error(ex.ToString());
                throw new XmlRpcIllFormedXmlException("Request contains invalid XML", ex);
            }
        }
 XmlRpcRequest MakeXmlRpcRequest(WebRequest webReq, MethodInfo mi,
   object[] parameters, object clientObj, string xmlRpcMethod,
   Guid proxyId)
 {
     webReq.Method = "POST";
     webReq.ContentType = "text/xml";
     string rpcMethodName = XmlRpcTypeInfo.GetRpcMethodName(mi);
     XmlRpcRequest req = new XmlRpcRequest(rpcMethodName, parameters, mi,
       xmlRpcMethod, proxyId);
     return req;
 }
Beispiel #29
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);
    }
 public XmlRpcRequest DeserializeRequest(XmlDocument xdoc, Type svcType)
 {
     XmlRpcRequest request = new XmlRpcRequest();
       XmlNode callNode = xdoc.SelectSingleNode("./methodCall");
       if (callNode == null)
       {
     throw new XmlRpcInvalidXmlRpcException(
       "Request XML not valid XML-RPC - missing methodCall element.");
       }
       XmlNode methodNode = callNode.SelectSingleNode("./methodName");
       if (methodNode == null)
       {
     throw new XmlRpcInvalidXmlRpcException(
       "Request XML not valid XML-RPC - missing methodName element.");
       }
       request.method = methodNode.FirstChild.Value;
       if (request.method == "")
       {
     throw new XmlRpcInvalidXmlRpcException(
       "Request XML not valid XML-RPC - empty methodName.");
       }
       request.mi = null;
       ParameterInfo[] pis = new ParameterInfo[0];
       if (svcType != null)
       {
     // retrieve info for the method which handles this XML-RPC method
     XmlRpcServiceInfo svcInfo
       = XmlRpcServiceInfo.CreateServiceInfo(svcType);
     request.mi = svcInfo.GetMethodInfo(request.method);
     // if a service type has been specified and we cannot find the requested
     // method then we must throw an exception
     if (request.mi == null)
     {
       string msg = String.Format("unsupported method called: {0}",
                               request.method);
       throw new XmlRpcUnsupportedMethodException(msg);
     }
     // method must be marked with XmlRpcMethod attribute
     Attribute attr = Attribute.GetCustomAttribute(request.mi,
       typeof(XmlRpcMethodAttribute));
     if (attr == null)
     {
       throw new XmlRpcMethodAttributeException(
     "Method must be marked with the XmlRpcMethod attribute.");
     }
     pis = request.mi.GetParameters();
       }
       XmlNode paramsNode = callNode.SelectSingleNode("./params");
       if (paramsNode == null)
       {
     if (svcType != null)
     {
       if (pis.Length == 0)
       {
     request.args = new object[0];
     return request;
       }
       else
       {
     throw new XmlRpcInvalidParametersException(
       "Method takes parameters and params element is missing.");
       }
     }
     else
     {
       request.args = new object[0];
       return request;
     }
       }
       XmlNodeList paramNodes = paramsNode.SelectNodes("./param");
       int paramsPos = GetParamsPos(pis);
       if (paramNodes.Count < paramsPos)
       {
     throw new XmlRpcInvalidParametersException(
       "Method takes parameters and there is incorrect number of param "
     + "elements.");
       }
       ParseStack parseStack = new ParseStack("request");
       // TODO: use global action setting
       MappingAction mappingAction = MappingAction.Error;
       int paramObjCount = (paramsPos == -1 ?paramNodes.Count : paramsPos + 1);
       Object[] paramObjs = new Object[paramObjCount];
       // parse ordinary parameters
       int ordinaryParams = (paramsPos == -1 ?paramNodes.Count :paramsPos);
       for (int i = 0; i < ordinaryParams; i++)
       {
     XmlNode paramNode = paramNodes[i];
     XmlNode valueNode = paramNode.SelectSingleNode("./value");
     if (valueNode == null)
       throw new XmlRpcInvalidXmlRpcException("Missing value element.");
     XmlNode node = valueNode.SelectSingleNode("./*");
     if (node == null)
       node = valueNode.FirstChild;
     if (svcType != null)
     {
       parseStack.Push(String.Format("parameter {0}", i + 1));
       // TODO: why following commented out?
     //          parseStack.Push(String.Format("parameter {0} mapped to type {1}",
     //            i, pis[i].ParameterType.Name));
       paramObjs[i] = ParseValue(node, pis[i].ParameterType, parseStack,
     mappingAction);
     }
     else
     {
       parseStack.Push(String.Format("parameter {0}", i));
       paramObjs[i] = ParseValue(node, null, parseStack, mappingAction);
     }
     parseStack.Pop();
       }
       // parse params parameters
       if (paramsPos != -1)
       {
     Type paramsType = pis[paramsPos].ParameterType.GetElementType();
     Object[] args = new Object[1];
     args[0] = paramNodes.Count - paramsPos;
     Array varargs = (Array)CreateArrayInstance(pis[paramsPos].ParameterType,
       args);
     for (int i = 0; i < varargs.Length; i++)
     {
       XmlNode paramNode = paramNodes[i + paramsPos];
       XmlNode valueNode = paramNode.SelectSingleNode("value");
       if (valueNode == null)
     throw new XmlRpcInvalidXmlRpcException("Missing value element.");
       XmlNode node = valueNode.SelectSingleNode("./*");
       if (node == null)
     node = valueNode.FirstChild;
       parseStack.Push(String.Format("parameter {0}", i + 1 + paramsPos));
       varargs.SetValue(ParseValue(node, paramsType, parseStack,
     mappingAction), i);
       parseStack.Pop();
     }
     paramObjs[paramsPos] = varargs;
       }
       request.args = paramObjs;
       return request;
 }
        public XmlRpcRequest DeserializeRequest(XmlReader rdr, Type svcType)
        {
            try
              {
            XmlRpcRequest request = new XmlRpcRequest();
            IEnumerator<Node> iter = new XmlRpcParser().ParseRequest(rdr).GetEnumerator();

            iter.MoveNext();
            string methodName = (iter.Current as MethodName).Name;
            request.method = methodName;

            request.mi = null;
            ParameterInfo[] pis = null;
            if (svcType != null)
            {
              // retrieve info for the method which handles this XML-RPC method
              XmlRpcServiceInfo svcInfo
            = XmlRpcServiceInfo.CreateServiceInfo(svcType);
              request.mi = svcInfo.GetMethodInfo(request.method);
              // if a service type has been specified and we cannot find the requested
              // method then we must throw an exception
              if (request.mi == null)
              {
            string msg = String.Format("unsupported method called: {0}",
                                        request.method);
            throw new XmlRpcUnsupportedMethodException(msg);
              }
              // method must be marked with XmlRpcMethod attribute
              Attribute attr = Attribute.GetCustomAttribute(request.mi,
            typeof(XmlRpcMethodAttribute));
              if (attr == null)
              {
            throw new XmlRpcMethodAttributeException(
              "Method must be marked with the XmlRpcMethod attribute.");
              }
              pis = request.mi.GetParameters();
            }

            bool gotParams = iter.MoveNext();
            if (!gotParams)
            {
              if (svcType != null)
              {
            if (pis.Length == 0)
            {
              request.args = new object[0];
              return request;
            }
            else
            {
              throw new XmlRpcInvalidParametersException(
                "Method takes parameters and params element is missing.");
            }
              }
              else
              {
            request.args = new object[0];
            return request;
              }
            }

            int paramsPos = pis != null ? GetParamsPos(pis) : -1;
            Type paramsType = null;
            if (paramsPos != -1)
              paramsType = pis[paramsPos].ParameterType.GetElementType();
            int minParamCount = pis == null ? int.MaxValue
              : (paramsPos == -1 ? pis.Length : paramsPos);
            MappingStack mappingStack = new MappingStack("request");
            MappingAction mappingAction = MappingAction.Error;
            var objs = new List<object>();
            var paramsObjs = new List<object>();
            int paramCount = 0;

            while (iter.MoveNext())
            {
              paramCount++;
              if (svcType != null && paramCount > minParamCount && paramsPos == -1)
            throw new XmlRpcInvalidParametersException(
              "Request contains too many param elements based on method signature.");
              if (paramCount <= minParamCount)
              {
            if (svcType != null)
            {
              mappingStack.Push(String.Format("parameter {0}", paramCount));
              // TODO: why following commented out?
              //          parseStack.Push(String.Format("parameter {0} mapped to type {1}",
              //            i, pis[i].ParameterType.Name));
              var obj = MapValueNode(iter,
                pis[paramCount - 1].ParameterType, mappingStack, mappingAction);
              objs.Add(obj);
            }
            else
            {
              mappingStack.Push(String.Format("parameter {0}", paramCount));
              var obj = MapValueNode(iter, null, mappingStack, mappingAction);
              objs.Add(obj);
            }
            mappingStack.Pop();
              }
              else
              {
            mappingStack.Push(String.Format("parameter {0}", paramCount + 1));
            var paramsObj = MapValueNode(iter, paramsType, mappingStack, mappingAction);
            paramsObjs.Add(paramsObj);
            mappingStack.Pop();
              }
            }

            if (svcType != null && paramCount < minParamCount)
              throw new XmlRpcInvalidParametersException(
            "Request contains too few param elements based on method signature.");

            if (paramsPos != -1)
            {
              Object[] args = new Object[1];
              args[0] = paramCount - minParamCount;
              Array varargs = (Array)Activator.CreateInstance(pis[paramsPos].ParameterType, args);
              for (int i = 0; i < paramsObjs.Count; i++)
            varargs.SetValue(paramsObjs[i], i);
              objs.Add(varargs);
            }
            request.args = objs.ToArray();
            return request;
              }
              catch (XmlException ex)
              {
            throw new XmlRpcIllFormedXmlException("Request contains invalid XML", ex);
              }
        }
        void SerializeStructParams(
            XmlWriter xtw, 
            XmlRpcRequest request,
            MappingActions mappingActions)
        {
            var pis = request.Mi.GetParameters();
            if (request.Args.Length > pis.Length)
                throw new XmlRpcInvalidParametersException(
                    "Number of request parameters greater than number of proxy method parameters.");

            if (Attribute.IsDefined(pis[request.Args.Length - 1],
                typeof(ParamArrayAttribute)))
            {
                throw new XmlRpcInvalidParametersException(
                    "params parameter cannot be used with StructParams.");
            }

            xtw.WriteStartElement("", "param", "");
            xtw.WriteStartElement("", "value", "");
            xtw.WriteStartElement("", "struct", "");
            for (int i = 0; i < request.Args.Length; i++)
            {
                if (request.Args[i] == null)
                {
                    throw new XmlRpcNullParameterException(
                        string.Format(
                            "Null method parameter #{0}",
                            i + 1));
                }

                xtw.WriteStartElement("", "member", "");
                WriteFullElementString(xtw, "name", pis[i].Name);
                Serialize(xtw, request.Args[i], mappingActions);
                WriteFullEndElement(xtw);
            }
            WriteFullEndElement(xtw);
            WriteFullEndElement(xtw);
            WriteFullEndElement(xtw);
        }
    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;
      }
    }
        void SerializeParams(
            XmlWriter xtw, 
            XmlRpcRequest request,
            MappingActions mappingActions)
        {
            ParameterInfo[] pis = null;
            if (request.Mi != null)
                pis = request.Mi.GetParameters();

            for (var i = 0; i < request.Args.Length; i++)
            {
                var paramMappingActions = pis == null
                    ? mappingActions
                    : GetMappingActions(pis[i], mappingActions);

                if (pis != null)
                {
                    if (i >= pis.Length)
                        throw new XmlRpcInvalidParametersException(
                            "Number of request parameters greater than number of proxy method parameters.");

                    if (i == pis.Length - 1 && Attribute.IsDefined(pis[i], typeof(ParamArrayAttribute)))
                    {
                        var ary = (Array)request.Args[i];
                        foreach (var o in ary)
                        {
                            xtw.WriteStartElement("", "param", "");
                            Serialize(xtw, o, paramMappingActions);
                            WriteFullEndElement(xtw);
                        }
                        break;
                    }
                }
                xtw.WriteStartElement("", "param", "");
                Serialize(xtw, request.Args[i], paramMappingActions);
                WriteFullEndElement(xtw);
            }
        }
 Header[] GetChannelHeaders(
   ITransportHeaders requestHeaders,
   XmlRpcRequest xmlRpcReq,
   Type svcType) 
 {
   string requestUri = (string) requestHeaders["__RequestUri"];
   XmlRpcServiceInfo svcInfo = XmlRpcServiceInfo.CreateServiceInfo(svcType);
   ArrayList hdrList = new ArrayList();
   hdrList.Add(new Header("__Uri", requestUri));
   hdrList.Add(new Header("__TypeName", svcType.AssemblyQualifiedName));
   hdrList.Add(new Header("__MethodName", 
     svcInfo.GetMethodName(xmlRpcReq.method)));
   hdrList.Add(new Header("__Args", xmlRpcReq.args));
   return (Header[])hdrList.ToArray(typeof(Header));
 }