/// <summary>Create a instance of <see cref="Message" /> from an exception. This is sent as the response.</summary> /// <param name="exception">Exception to process</param> /// <returns>An instance of <see cref="Message" /> class.</returns> private Message CreateMessageFromUnhandledException(Exception exception) { string exceptionMessage = WebUtil.GetExceptionMessage(exception); SyncServiceTracer.TraceError(exceptionMessage); return(_syncConfiguration.UseVerboseErrors ? CreateExceptionMessage(HttpStatusCode.InternalServerError, exceptionMessage) : CreateExceptionMessage(HttpStatusCode.InternalServerError, Strings.InternalServerError)); }
/// <summary> /// Static constructor. /// </summary> static SyncService() { // Ensure that <T> has the SyncScope attribute on it. //Note: Early validation check to fail quickly if things are not correct. if (!Attribute.IsDefined(typeof(T), typeof(SyncScopeAttribute))) { throw SyncServiceException.CreateInternalServerError(Strings.TemplateClassNotMarkedWithSyncScopeAttribute); } SyncServiceTracer.TraceVerbose("SyncService initialized!"); }
/// <summary> /// Delegate passed into the custom body writer to form the outgoing response. /// </summary> /// <param name="writer"></param> /// <param name="syncWriter"></param> private static void WriteResponse(XmlDictionaryWriter writer, SyncWriter syncWriter) { try { syncWriter.WriteFeed(writer); } catch (Exception exception) { // An exception at this point seems to be unrecoverable but ideally we should not hit exceptions since we are only // writing to the XmlDictionaryWriter. SyncServiceTracer.TraceError("Exception in WriteResponse method. Details: {0}", WebUtil.GetExceptionMessage(exception)); } }
private void ProcessSyncServiceException(SyncServiceException syncServiceException) { string exceptionMessage = WebUtil.GetExceptionMessage(syncServiceException); SyncServiceTracer.TraceWarning(exceptionMessage); _outgoingMessage = _syncConfiguration.UseVerboseErrors ? CreateExceptionMessage((HttpStatusCode)syncServiceException.StatusCode, exceptionMessage) : CreateExceptionMessage((HttpStatusCode)syncServiceException.StatusCode, syncServiceException.Message); // Add the "Allow" HTTP header if present._outgoingMessage.Properties[HttpResponseMessageProperty.Name]. if (!String.IsNullOrEmpty(syncServiceException.ResponseAllowHeader) && null != _outgoingMessage.Properties[HttpResponseMessageProperty.Name]) { ((HttpResponseMessageProperty)_outgoingMessage.Properties[HttpResponseMessageProperty.Name]). Headers.Add("Allow", syncServiceException.ResponseAllowHeader); } }