public void SerializeRequest(Stream stm, XmlRpcRequest request)
 {
     XmlWriter xtw = XmlRpcXmlWriter.Create(stm, base.XmlRpcFormatSettings);
     xtw.WriteStartDocument();
     xtw.WriteStartElement("", "methodCall", "");
     {
         var mappingActions = new MappingActions();
         mappingActions = GetTypeMappings(request.mi, mappingActions);
         mappingActions = GetMappingActions(request.mi.GetType().GetTypeInfo(), 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();
 }
        //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 SerializeStructParams(XmlWriter xtw, XmlRpcRequest request,
		  MappingActions mappingActions)
        {
            ParameterInfo[] 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 (pis[request.args.Length - 1].GetCustomAttribute<ParamArrayAttribute>() != null)
            {
                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);
        }
        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].GetType().GetTypeInfo(), 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
                      && pis[i].GetCustomAttribute<ParamArrayAttribute>() != null)
                    {
                        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);
            }
        }