/// <summary> /// Sends an error response to a query request. /// </summary> public void Error(ResError error) { try { RawResponse(JsonUtils.Serialize(new ErrorDto(error))); } catch (Exception ex) { Service.OnError("Error serializing error query response: {0}", ex.Message); RawResponse(ResService.ResponseInternalError); } }
internal void Result(object result) { try { RawResponse(JsonUtils.Serialize(new ResultDto(result))); } catch (Exception ex) { Service.OnError("Error serializing result query response: {0}", ex.Message); RawResponse(ResService.ResponseInternalError); } }
/// <summary> /// Sends a successful resource response to a request. /// </summary> /// <param name="resourceID">Resource ID.</param> public void Resource(string resourceID) { var rid = new Ref(resourceID); if (!rid.IsValid()) { throw new ArgumentException(String.Format("Invalid resource ID: {0}", resourceID)); } try { byte[] data = JsonUtils.Serialize(new ResourceDto(rid)); RawResponse(data); } catch (Exception ex) { Service.OnError("Error serializing success response: {0}", ex.Message); Error(new ResError(ex)); } }
/// <summary> /// Sends a successful result response to a request. /// </summary> /// <param name="result">Result object. May be null.</param> public void Ok(object result) { if (result == null) { RawResponse(ResService.ResponseSuccess); } else { try { byte[] data = JsonUtils.Serialize(new ResultDto(result)); RawResponse(data); } catch (Exception ex) { Service.OnError("Error serializing success response: {0}", ex.Message); Error(new ResError(ex)); } } }