public string SerializeRequestToString(XmlRpcRequest request)
        {
            var       ms  = new MemoryStream();
            XmlWriter xtw = XmlRpcXmlWriter.Create(ms, 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();


            return(global::System.Text.Encoding.UTF8.GetString(ms.ToArray()));
        }
Пример #2
0
        public void SerializeFaultResponse(
            Stream stm,
            XmlRpcFaultException faultEx)
        {
            FaultStruct fs;

            fs.faultCode   = faultEx.FaultCode;
            fs.faultString = faultEx.FaultString;
            XmlWriter xtw = XmlRpcXmlWriter.Create(stm, XmlRpcFormatSettings);

            xtw.WriteStartDocument();
            xtw.WriteStartElement("", "methodResponse", "");
            xtw.WriteStartElement("", "fault", "");
            Serialize(xtw, fs, new MappingActions {
                NullMappingAction = NullMappingAction.Error
            });
            WriteFullEndElement(xtw);
            WriteFullEndElement(xtw);
            xtw.Flush();
        }