public Stream Invoke(Stream requestStream)
 {
     try
       {
     XmlRpcSerializer serializer = new XmlRpcSerializer();
     Type type = this.GetType();
     XmlRpcServiceAttribute serviceAttr = (XmlRpcServiceAttribute)
       Attribute.GetCustomAttribute(this.GetType(),
       typeof(XmlRpcServiceAttribute));
     if (serviceAttr != null)
     {
       if (serviceAttr.XmlEncoding != null)
     serializer.XmlEncoding = Encoding.GetEncoding(serviceAttr.XmlEncoding);
       serializer.UseIntTag = serviceAttr.UseIntTag;
       serializer.UseStringTag = serviceAttr.UseStringTag;
       serializer.UseIndentation = serviceAttr.UseIndentation;
       serializer.Indentation = serviceAttr.Indentation;
       serializer.AppendTimezoneOffset = serviceAttr.AppendTimezoneOffset; // JB Change
     }
     XmlRpcRequest xmlRpcReq
       = serializer.DeserializeRequest(requestStream, this.GetType());
     XmlRpcResponse xmlRpcResp = Invoke(xmlRpcReq);
     Stream responseStream = new MemoryStream();
     serializer.SerializeResponse(responseStream, xmlRpcResp);
     responseStream.Seek(0, SeekOrigin.Begin);
     return responseStream;
       }
       catch (Exception ex)
       {
     XmlRpcFaultException fex;
     if (ex is XmlRpcException)
       fex = new XmlRpcFaultException(0, ((XmlRpcException)ex).Message);
     else if (ex is XmlRpcFaultException)
       fex = (XmlRpcFaultException)ex;
     else
       fex = new XmlRpcFaultException(0, ex.Message);
     XmlRpcSerializer serializer = new XmlRpcSerializer();
     Stream responseStream = new MemoryStream();
     serializer.SerializeFaultResponse(responseStream, fex);
     responseStream.Seek(0, SeekOrigin.Begin);
     return responseStream;
       }
 }
        public void SerializeFaultResponse(
            Stream stm,
            XmlRpcFaultException faultEx)
        {
            FaultStruct fs;
              fs.faultCode = faultEx.FaultCode;
              fs.faultString = faultEx.FaultString;

              XmlTextWriter xtw = new XmlTextWriter(stm, m_encoding);
              ConfigureXmlFormat(xtw);
              xtw.WriteStartDocument();
              xtw.WriteStartElement("", "methodResponse", "");
              xtw.WriteStartElement("", "fault", "");
              Serialize(xtw, fs, MappingAction.Error);
              xtw.WriteEndElement();
              xtw.WriteEndElement();
              xtw.Flush();
        }
        public ServerProcessing ProcessMessage(
            IServerChannelSinkStack sinkStack,
            IMessage requestMsg,
            ITransportHeaders requestHeaders,
            Stream requestStream,
            out IMessage responseMsg,
            out ITransportHeaders responseHeaders,
            out Stream responseStream
            )
        {
            // use presence of SOAPAction header to determine if this is a SOAP
              // request - if so pass onto next sink in chain
              string soapAction = (string) requestHeaders["SOAPAction"];
              if (soapAction != null)
              {
            return m_next.ProcessMessage(sinkStack, requestMsg, requestHeaders,
              requestStream, out responseMsg, out responseHeaders,
              out responseStream);
              }

              // for time being assume we have an XML-RPC request (need to improve
              // this in case there are other non-SOAP formatters in the chain)
              try
              {
            MethodCall mthdCall = DeserializeRequest(requestHeaders, requestStream);
            sinkStack.Push(this, mthdCall);
            // forward to next sink in chain - pass request stream as null to
            // indicate that we have deserialized the request
            m_next.ProcessMessage(sinkStack, mthdCall, requestHeaders, null,
              out responseMsg, out responseHeaders, out responseStream);
            SerializeResponse(responseMsg, ref responseHeaders, ref responseStream);
              }
              catch (Exception ex)
              {
            responseMsg = new ReturnMessage(ex, (IMethodCallMessage)requestMsg);
            responseStream = new MemoryStream();
            XmlRpcFaultException fex = new XmlRpcFaultException(0, ex.Message);
            XmlRpcSerializer serializer = new XmlRpcSerializer();
            serializer.SerializeFaultResponse(responseStream,
              (XmlRpcFaultException)fex);
            responseHeaders = new TransportHeaders();
              }
              return ServerProcessing.Complete;
        }