private async Task <XRpcMethodResponse> DispatchAsync(XRpcMethodCall request) { var context = new XmlRpcContext { Url = Url, ControllerContext = ControllerContext, HttpContext = HttpContext, RpcMethodCall = request }; try { foreach (var handler in _xmlRpcHandlers) { await handler.ProcessAsync(context); } } catch (Exception e) { // if a core exception is raised, report the error message, otherwise signal a 500 context.RpcMethodResponse = context.RpcMethodResponse ?? new XRpcMethodResponse(); context.RpcMethodResponse.Fault = new XRpcFault(0, e.Message); } return(context.RpcMethodResponse); }
public ActionResult ServiceEndpoint(XRpcMethodCall methodCall) { Logger.Debug("XmlRpc methodName {0}", methodCall.MethodName); var methodResponse = Dispatch(methodCall); if (methodResponse == null) { throw new HttpException(500, "TODO: xmlrpc fault"); } var settings = new XmlWriterSettings { Encoding = Encoding.UTF8, OmitXmlDeclaration = false, Indent = true }; // save to an intermediate MemoryStream to preserve the encoding declaration using (var stream = new MemoryStream()) { using (XmlWriter w = XmlWriter.Create(stream, settings)) { var result = _writer.MapMethodResponse(methodResponse); result.Save(w); } var content = Encoding.UTF8.GetString(stream.ToArray()); return(Content(content, "text/xml")); } }
public async Task <IActionResult> ServiceEndpoint([ModelBinder(BinderType = typeof(MethodCallModelBinder))] XRpcMethodCall methodCall) { if (Logger.IsEnabled(LogLevel.Debug)) { Logger.LogDebug("XmlRpc methodName {0}", methodCall.MethodName); } var methodResponse = await DispatchAsync(methodCall); if (methodResponse == null) { return(StatusCode(500, "TODO: xmlrpc fault")); } var settings = new XmlWriterSettings { Encoding = Encoding.UTF8, OmitXmlDeclaration = false, Indent = true }; // save to an intermediate MemoryStream to preserve the encoding declaration using (var stream = new MemoryStream()) { using (XmlWriter w = XmlWriter.Create(stream, settings)) { var result = _writer.MapMethodResponse(methodResponse); result.Save(w); } var content = Encoding.UTF8.GetString(stream.ToArray()); return(Content(content, "text/xml")); } }
public ActionResult ServiceEndpoint(XRpcMethodCall methodCall) { Logger.Debug("XmlRpc methodName {0}", methodCall.MethodName); var methodResponse = Dispatch(methodCall); if (methodResponse == null) { throw new HttpException(500, "TODO: xmlrpc fault"); } var content = _writer.MapMethodResponse(methodResponse).ToString(); return(Content(content, "text/xml")); }
private XRpcMethodResponse Dispatch(XRpcMethodCall request) { var context = new XmlRpcContext { ControllerContext = ControllerContext, HttpContext = HttpContext, Request = request }; try { foreach (var handler in _xmlRpcHandlers) { handler.Process(context); } } catch (OrchardCoreException e) { // if a core exception is raised, report the error message, otherwise signal a 500 context.Response = context.Response ?? new XRpcMethodResponse(); context.Response.Fault = new XRpcFault(0, e.LocalizedMessage.ToString()); } return(context.Response); }