Exemple #1
0
        /// <summary>
        /// Serializes a reply message from a specified message version, array of parameters, and a return value.
        /// </summary>
        /// <param name="messageVersion">
        /// The SOAP message version.
        /// </param>
        /// <param name="parameters">
        /// The out parameters.
        /// </param>
        /// <param name="result">
        /// The return value.
        /// </param>
        /// <returns>
        /// The serialized reply message.
        /// </returns>
        public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result)
        {
            // An AMF operation
            if (OperationContext.Current.IncomingMessageProperties.ContainsKey(MessagingHeaders.InvokerMessageBody))
            {
                var requestMessage =
                    (AmfMessage)OperationContext.Current.IncomingMessageProperties[MessagingHeaders.InvokerMessageBody];

                // An RPC operation
                if (OperationContext.Current.IncomingMessageProperties.ContainsKey(MessagingHeaders.RemotingMessage))
                {
                    var rpcMessage =
                        (RemotingMessage)
                        OperationContext.Current.IncomingMessageProperties[MessagingHeaders.RemotingMessage];
                    AcknowledgeMessage acknowledge = AmfOperationUtil.BuildAcknowledgeMessage(rpcMessage);
                    acknowledge.Body = result;

                    result = acknowledge;
                }

                var replyHeaders = new Dictionary <string, AmfHeader>();
                var replyMessage = new AmfMessage
                {
                    Data     = result,
                    Target   = AmfOperationUtil.CreateResultReplyTarget(requestMessage),
                    Response = string.Empty
                };

                return(new AmfGenericMessage(replyHeaders, replyMessage));
            }

            throw new OperationCanceledException(Errors.AmfGenericOperationFormatter_SerializeReply_InvalidOperation);
        }
Exemple #2
0
        /// <summary>
        /// Handle command message: a clinet ping.
        /// </summary>
        private AmfGenericMessage HandleClientPing(AmfGenericMessage request, CommandMessage message)
        {
            var acknowledge = AmfOperationUtil.BuildAcknowledgeMessage(message);

            acknowledge.Headers = new Dictionary <string, object>
            {
                { CommandMessageHeader.MessagingVersion, Capabilities.MessagingVersion }
            };

            return(AmfOperationUtil.BuildMessageReply(request, acknowledge));
        }
Exemple #3
0
        public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            //An internal server error occured
            if (OperationContext.Current == null)
            {
                return;
            }

            //An AMF operation
            if (OperationContext.Current.IncomingMessageProperties.ContainsKey(MessagingHeaders.InvokerMessageBody))
            {
                var replyHeaders = new Dictionary <string, AmfHeader>();
                var replyMessage = new AmfMessage {
                    Response = string.Empty
                };

                var requestMessage = (AmfMessage)OperationContext.Current.IncomingMessageProperties[MessagingHeaders.InvokerMessageBody];

                //An RPC operation
                if (OperationContext.Current.IncomingMessageProperties.ContainsKey(MessagingHeaders.RemotingMessage))
                {
                    var rpcMessage  = (RemotingMessage)OperationContext.Current.IncomingMessageProperties[MessagingHeaders.RemotingMessage];
                    var acknowledge = AmfOperationUtil.BuildErrorMessage(rpcMessage);
                    if (acknowledge.Headers == null)
                    {
                        acknowledge.Headers = new Dictionary <string, object>();
                    }

                    if (error is AmfOperationNotFoundException)
                    {
                        acknowledge.Headers[AmfMessageHeader.StatusCode] = (int)HttpStatusCode.NotFound;
                    }
                    else
                    {
                        acknowledge.Headers[AmfMessageHeader.StatusCode] = (int)HttpStatusCode.BadRequest;
                    }

                    acknowledge.FaultCode = ErrorMessageFaultCode.DeliveryInDoubt;

                    acknowledge.FaultString = error.Message;

                    if (_capabilities.ExceptionDetailInFaults)
                    {
                        acknowledge.FaultDetail = error.StackTrace;
                    }

                    //Get FaultException's detail object, if any
                    if (error is FaultException)
                    {
                        var type = error.GetType();

                        if (type.IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(FaultException <>)))
                        {
                            acknowledge.ExtendedData = type.GetProperty("Detail").GetValue(error, null);
                        }
                    }

                    replyMessage.Target = AmfOperationUtil.CreateStatusReplyTarget(requestMessage);
                    replyMessage.Data   = acknowledge;
                }

                fault = new AmfGenericMessage(replyHeaders, replyMessage);
            }
        }