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\""; }
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; } 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 string Invoke(Stream requestStream) { try { var xmlRpcSerializer = new XmlRpcSerializer(); var xmlRpcServiceAttribute = (XmlRpcServiceAttribute)Attribute.GetCustomAttribute(this.GetType(), typeof(XmlRpcServiceAttribute)); if (xmlRpcServiceAttribute != null) { if (xmlRpcServiceAttribute.XmlEncoding != null) { xmlRpcSerializer.XmlEncoding = Encoding.GetEncoding(xmlRpcServiceAttribute.XmlEncoding); } xmlRpcSerializer.UseIntTag = xmlRpcServiceAttribute.UseIntTag; xmlRpcSerializer.UseStringTag = xmlRpcServiceAttribute.UseStringTag; xmlRpcSerializer.UseIndentation = xmlRpcServiceAttribute.UseIndentation; xmlRpcSerializer.Indentation = xmlRpcServiceAttribute.Indentation; } var bodyStream = new StreamReader(requestStream); bodyStream.BaseStream.Seek(0, SeekOrigin.Begin); var request = xmlRpcSerializer.DeserializeRequest(bodyStream, this.GetType()); var response = Invoke(request); Stream stream = new MemoryStream(); xmlRpcSerializer.SerializeResponse(stream, response); stream.Seek(0L, SeekOrigin.Begin); var reader = new StreamReader(stream); return(reader.ReadToEnd()); } catch (Exception ex) { loggingDataService.AddEvent(new EventDataItem(EventCodes.Error, ex.Message, "XmlRpcManager.Invoke")); var faultEx = (!(ex is XmlRpcException)) ? ((!(ex is XmlRpcFaultException)) ? new XmlRpcFaultException(0, ex.Message) : ((XmlRpcFaultException)ex)) : new XmlRpcFaultException(0, ((XmlRpcException)ex).Message); var xmlRpcSerializer2 = new XmlRpcSerializer(); Stream stream2 = new MemoryStream(); xmlRpcSerializer2.SerializeFaultResponse(stream2, faultEx); stream2.Seek(0L, SeekOrigin.Begin); var reader2 = new StreamReader(stream2); return(reader2.ReadToEnd()); } }
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); }
public Stream Invoke(Stream requestStream) { try { var serializer = new XmlRpcSerializer(); var serviceAttr = this.GetAttribute <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; } XmlRpcRequest xmlRpcReq = serializer.DeserializeRequest(requestStream, 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, ex.Message); } else { var exception = ex as XmlRpcFaultException; fex = exception ?? new XmlRpcFaultException(0, ex.Message); } var serializer = new XmlRpcSerializer(); Stream responseStream = new MemoryStream(); serializer.SerializeFaultResponse(responseStream, fex); responseStream.Seek(0, SeekOrigin.Begin); return(responseStream); } }
Stream CreateExceptionResponse(Exception exception) { XmlRpcFaultException fex; if (exception is XmlRpcException) { fex = new XmlRpcFaultException(0, ((XmlRpcException)exception).Message); } else if (exception is XmlRpcFaultException) { fex = (XmlRpcFaultException)exception; } else { fex = new XmlRpcFaultException(0, exception.Message); } var serializer = new XmlRpcSerializer(); var responseStream = new MemoryStream(); serializer.SerializeFaultResponse(responseStream, fex); responseStream.Seek(0, SeekOrigin.Begin); return(responseStream); }