void DispatchEvent(EpoxyHeaders headers, EpoxyProtocol.MessageData messageData, ArraySegment <byte> layerData) { if (messageData.IsError) { logger.Site().Error( "{0} Received event with an error message. Only payload messages are allowed. Conversation ID: {1}", this, headers.conversation_id); return; } Task.Run( async() => { IMessage request = Message.FromPayload(Unmarshal.From(messageData.Data)); var totalTime = Stopwatch.StartNew(); var requestMetrics = Metrics.StartRequestMetrics(ConnectionMetrics); var receiveContext = new RelayEpoxyReceiveContext(this, ConnectionMetrics, requestMetrics); IBonded bondedLayerData = (layerData.Array == null) ? null : Unmarshal.From(layerData); ILayerStack layerStack; Error layerError = parentTransport.GetLayerStack(requestMetrics.request_id, out layerStack); if (layerError == null) { layerError = LayerStackUtils.ProcessOnReceive( layerStack, MessageType.EVENT, receiveContext, bondedLayerData, logger); } if (layerError != null) { logger.Site().Error( "{0}: Receiving event {1}/{2}.{3} failed due to layer error (Code: {4}, Message: {5}).", this, headers.conversation_id, headers.service_name, headers.method_name, layerError.error_code, layerError.message); return; } await serviceHost.DispatchEvent(headers.service_name, headers.method_name, receiveContext, request); Metrics.FinishRequestMetrics(requestMetrics, totalTime); metrics.Emit(requestMetrics); }); }