public ServiceHealthMessage(ServiceHealthSectionCollection healthInfo, string serviceName, int httpStatusCode) : base() { this.healthInfo = healthInfo; this.httpStatusCode = httpStatusCode; this.serviceName = serviceName; }
protected virtual ServiceHealthSectionCollection GetServiceHealthSections(ServiceHostBase serviceHost) { if (serviceHost == null) { throw new ArgumentNullException(nameof(serviceHost)); } ServiceHealthSectionCollection serviceHealthSections = new ServiceHealthSectionCollection(); ServiceHealthModel serviceHealthModel = new ServiceHealthModel(serviceHost, this.ServiceStartTime); #region Service Properties ServiceHealthSection serviceProperties = serviceHealthSections.CreateSection(SR.GetString(SR.ServiceHealthBehavior_WCFServiceProperties), "#0C5DA4", "#ffffff"); ServiceHealthDataCollection servicePropertiesCollection = serviceProperties.CreateElementsCollection(); servicePropertiesCollection.Add(SR.GetString(SR.ServiceHealthBehavior_ServiceName), serviceHealthModel.ServiceProperties.Name); servicePropertiesCollection.Add(SR.GetString(SR.ServiceHealthBehavior_State), FormatCommunicationState(serviceHealthModel.ServiceProperties.State)); servicePropertiesCollection.Add(SR.GetString(SR.ServiceHealthBehavior_ServiceType), serviceHealthModel.ServiceProperties.ServiceTypeName); servicePropertiesCollection.Add(SR.GetString(SR.ServiceHealthBehavior_InstanceContextMode), serviceHealthModel.ServiceProperties.InstanceContextMode?.ToString()); servicePropertiesCollection.Add(SR.GetString(SR.ServiceHealthBehavior_ConcurrencyMode), serviceHealthModel.ServiceProperties.ConcurrencyMode?.ToString()); servicePropertiesCollection.Add(SR.GetString(SR.ServiceHealthBehavior_BaseAddresses), serviceHealthModel.ServiceProperties.BaseAddresses); servicePropertiesCollection.Add(SR.GetString(SR.ServiceHealthBehavior_ServiceThrottles), FormatServiceThrottle(serviceHealthModel.ServiceProperties.ServiceThrottle)); servicePropertiesCollection.Add(SR.GetString(SR.ServiceHealthBehavior_ServiceBehaviors), serviceHealthModel.ServiceProperties.ServiceBehaviorNames); #endregion #region Process Information ServiceHealthSection processInformation = serviceHealthSections.CreateSection(SR.GetString(SR.ServiceHealthBehavior_ProcessInformation), "#2C4079", "#ffffff"); ServiceHealthDataCollection processInformationCollection = processInformation.CreateElementsCollection(); processInformationCollection.Add(SR.GetString(SR.ServiceHealthBehavior_ProcessName), serviceHealthModel.ProcessInformation.ProcessName); processInformationCollection.Add(SR.GetString(SR.ServiceHealthBehavior_ProcessBitness), serviceHealthModel.ProcessInformation.Bitness.ToString()); processInformationCollection.Add(SR.GetString(SR.ServiceHealthBehavior_ProcessRunningSince), serviceHealthModel.ProcessInformation.ProcessStartDate.ToString()); processInformationCollection.Add(SR.GetString(SR.ServiceHealthBehavior_ServiceRunningSince), serviceHealthModel.ProcessInformation.ServiceStartDate.ToString()); processInformationCollection.Add(SR.GetString(SR.ServiceHealthBehavior_Uptime), serviceHealthModel.ProcessInformation.Uptime.ToString(TimeSpanFormat)); processInformationCollection.Add(SR.GetString(SR.ServiceHealthBehavior_GCMode), serviceHealthModel.ProcessInformation.GCMode); processInformationCollection.Add(SR.GetString(SR.ServiceHealthBehavior_Threads), FormatThreads(serviceHealthModel.ProcessInformation.Threads)); #endregion #region Endpoints if (serviceHealthModel.ServiceEndpoints != null && serviceHealthModel.ServiceEndpoints.Length > 0) { ServiceHealthSection endpointsSection = serviceHealthSections.CreateSection(SR.GetString(SR.ServiceHealthBehavior_Endpoints), "#3e7185", "#ffffff"); foreach (ServiceHealthModel.ServiceEndpointModel serviceEndpoint in serviceHealthModel.ServiceEndpoints) { ServiceHealthDataCollection endpointCollection = endpointsSection.CreateElementsCollection(); endpointCollection.Add(SR.GetString(SR.ServiceHealthBehavior_Address), serviceEndpoint.Address); endpointCollection.Add(SR.GetString(SR.ServiceHealthBehavior_Binding), serviceEndpoint.BindingName); endpointCollection.Add(SR.GetString(SR.ServiceHealthBehavior_Contract), serviceEndpoint.ContractName); endpointCollection.Add(SR.GetString(SR.ServiceHealthBehavior_EndpointBehaviors), serviceEndpoint.BehaviorNames); } } #endregion #region Channel Dispatchers if (serviceHealthModel.ChannelDispatchers != null && serviceHealthModel.ChannelDispatchers.Length > 0) { ServiceHealthSection channelDispatcherSection = serviceHealthSections.CreateSection(SR.GetString(SR.ServiceHealthBehavior_ChannelDispatchers), "#406BE8", "#ffffff"); foreach (ServiceHealthModel.ChannelDispatcherModel channelDispatcher in serviceHealthModel.ChannelDispatchers) { ServiceHealthDataCollection channelDispatcherCollection = channelDispatcherSection.CreateElementsCollection(); channelDispatcherCollection.Add(SR.GetString(SR.ServiceHealthBehavior_ListenerUri), channelDispatcher.ListenerUri); channelDispatcherCollection.Add(SR.GetString(SR.ServiceHealthBehavior_ListenerState), FormatCommunicationState(channelDispatcher.ListenerState)); channelDispatcherCollection.Add(SR.GetString(SR.ServiceHealthBehavior_Binding), channelDispatcher.BindingName); channelDispatcherCollection.Add(SR.GetString(SR.ServiceHealthBehavior_State), FormatCommunicationState(channelDispatcher.State)); channelDispatcherCollection.Add(SR.GetString(SR.ServiceHealthBehavior_MessageEncoder), channelDispatcher.MessageEncoder); channelDispatcherCollection.Add(SR.GetString(SR.ServiceHealthBehavior_Contract), channelDispatcher.ContractName); channelDispatcherCollection.Add(SR.GetString(SR.ServiceHealthBehavior_IsSystemEndpoint), channelDispatcher.IsSystemEndpoint.ToString()); channelDispatcherCollection.Add(SR.GetString(SR.ServiceHealthBehavior_ChannelTimeouts), FormatCommunicationTimeouts(channelDispatcher.CommunicationTimeouts)); channelDispatcherCollection.Add(SR.GetString(SR.ServiceHealthBehavior_MessageInspectors), channelDispatcher.MessageInspectors); } } #endregion return(serviceHealthSections); }
public override void HandleHealthRequest(ServiceHostBase serviceHost, Message httpGetRequest, string[] queries, out Message replyMessage) { const string noContentStr = "noContent"; const string xmlStr = "xml"; if (serviceHost == null) { throw new ArgumentNullException(nameof(serviceHost)); } if (httpGetRequest == null) { throw new ArgumentNullException(nameof(httpGetRequest)); } if (queries == null) { throw new ArgumentNullException(nameof(queries)); } replyMessage = null; bool isXml = false; bool noContent = false; bool result; foreach (string q in queries) { if (TryParseBooleanQueryParameter(noContentStr, q, true, out result)) { noContent = result; } else if (TryParseBooleanQueryParameter(xmlStr, q, true, out result)) { isXml = result; } } HttpStatusCode httpStatusCode = GetHttpResponseCode(serviceHost, queries); if (this.HealthDetailsEnabled && !noContent) { if (isXml && HasXmlSupport) { XmlDocument doc = GetXmlDocument(serviceHost); if (doc != null) { replyMessage = new XmlDocumentMessage(doc); } } else { ServiceHealthSectionCollection healthInfo = GetServiceHealthSections(serviceHost); if (healthInfo != null && healthInfo.Count > 0) { string name = ServiceHealthBehavior.GetServiceName(serviceHost); replyMessage = new ServiceHealthMessage(healthInfo, name, (int)httpStatusCode); } } } if (replyMessage == null) { replyMessage = new EmptyMessage(); } AddHttpProperty(replyMessage, httpStatusCode, isXml); }