public XmlRpcResponse DeserializeResponse(XmlDocument xdoc, Type returnType)
 {
     XmlRpcResponse response = new XmlRpcResponse();
       Object retObj = null;
       XmlNode methodResponseNode = SelectSingleNode(xdoc, "methodResponse");
       if (methodResponseNode == null)
       {
     throw new XmlRpcInvalidXmlRpcException(
       "Response XML not valid XML-RPC - missing methodResponse element.");
       }
       // check for fault response
       XmlNode faultNode = SelectSingleNode(methodResponseNode, "fault");
       if (faultNode != null)
       {
     ParseStack parseStack = new ParseStack("fault response");
     // TODO: use global action setting
     MappingAction mappingAction = MappingAction.Error;
     XmlRpcFaultException faultEx = ParseFault(faultNode, parseStack,
       mappingAction);
     throw faultEx;
       }
       XmlNode paramsNode = SelectSingleNode(methodResponseNode, "params");
       if (paramsNode == null && returnType != null)
       {
     if (returnType == typeof(void))
       return new XmlRpcResponse(null);
     else
       throw new XmlRpcInvalidXmlRpcException(
     "Response XML not valid XML-RPC - missing params element.");
       }
       XmlNode paramNode = SelectSingleNode(paramsNode, "param");
       if (paramNode == null && returnType != null)
       {
     if (returnType == typeof(void))
       return new XmlRpcResponse(null);
     else
       throw new XmlRpcInvalidXmlRpcException(
     "Response XML not valid XML-RPC - missing params element.");
       }
       XmlNode valueNode = SelectSingleNode(paramNode, "value");
       if (valueNode == null)
       {
     throw new XmlRpcInvalidXmlRpcException(
       "Response XML not valid XML-RPC - missing value element.");
       }
       if (returnType == typeof(void))
       {
     retObj = null;
       }
       else
       {
     ParseStack parseStack = new ParseStack("response");
     // TODO: use global action setting
     MappingAction mappingAction = MappingAction.Error;
     XmlNode node = SelectValueNode(valueNode);
     retObj = ParseValue(node, returnType, parseStack, mappingAction);
       }
       response.retVal = retObj;
       return response;
 }
 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;
 }
        public void SerializeResponse(Stream stm, XmlRpcResponse response)
        {
            Object ret = response.retVal;
              if (ret is XmlRpcFaultException)
              {
            SerializeFaultResponse(stm, (XmlRpcFaultException)ret);
            return;
              }

              XmlTextWriter xtw = new XmlTextWriter(stm, m_encoding);
              ConfigureXmlFormat(xtw);
              xtw.WriteStartDocument();
              xtw.WriteStartElement("", "methodResponse", "");
              xtw.WriteStartElement("", "params", "");
              // "void" methods actually return an empty string value
              if (ret == null)
              {
            ret = "";
              }
              xtw.WriteStartElement("", "param", "");
              // TODO: use global action setting
              MappingAction mappingAction = MappingAction.Error;
              try
              {
            Serialize(xtw, ret, mappingAction);
              }
              catch (XmlRpcUnsupportedTypeException ex)
              {
            throw new XmlRpcInvalidReturnType(string.Format(
              "Return value 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.WriteEndElement();
              xtw.Flush();
        }
        void SerializeResponse(
            IMessage responseMsg,
            ref ITransportHeaders responseHeaders,
            ref Stream responseStream)
        {
            XmlRpcSerializer serializer = new XmlRpcSerializer();
              responseStream = new MemoryStream();
              responseHeaders = new TransportHeaders();

              ReturnMessage retMsg = (ReturnMessage)responseMsg;
              if (retMsg.Exception == null)
              {
            XmlRpcResponse xmlRpcResp = new XmlRpcResponse(retMsg.ReturnValue);
            serializer.SerializeResponse(responseStream, xmlRpcResp);
              }
              else if (retMsg.Exception is XmlRpcFaultException)
              {
            serializer.SerializeFaultResponse(responseStream,
              (XmlRpcFaultException)retMsg.Exception);
              }
              else
              {
            serializer.SerializeFaultResponse(responseStream,
              new XmlRpcFaultException(1, retMsg.Exception.Message));
              }
              responseHeaders["Content-Type"] = "text/xml; charset=\"utf-8\"";
        }