Example #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);
        }
 public static AmfMessage GetInvokeReleaseStreamErrorNotFound(AmfMessage request)
 {
     return(GenericMessageFactory.GetInvokeError(request.ChannelId, request.StreamId, request.InvokeId, Variant.Get(), Variant.GetMap(new VariantMapHelper
     {
         { Defines.RM_INVOKE_PARAMS_RESULT_LEVEL, Defines.RM_INVOKE_PARAMS_RESULT_LEVEL_ERROR },
         { Defines.RM_INVOKE_PARAMS_RESULT_CODE, "NetConnection.Call.Failed" },
         { Defines.RM_INVOKE_PARAMS_RESULT_DESCRIPTION, "Specified stream not found in call to releaseStream" }
     })));
 }
Example #3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="headers">AMF headers.</param>
 /// <param name="message">AMF message.</param>
 public AmfGenericMessage(IDictionary <string, AmfHeader> headers, AmfMessage message)
     : base(headers)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     _amfMessage = message;
 }
Example #4
0
        /// <summary>
        /// Build a message reply.
        /// </summary>
        /// <param name="request">Request message.</param>
        /// <param name="body">Reply message's body.</param>
        static public AmfGenericMessage BuildMessageReply(AmfGenericMessage request, object body)
        {
            var replyHeaders = new Dictionary <string, AmfHeader>();
            var replyMessage = new AmfMessage
            {
                Target   = CreateResultReplyTarget(request.AmfMessage),
                Response = string.Empty,
                Data     = body
            };

            return(new AmfGenericMessage(replyHeaders, replyMessage));
        }
Example #5
0
 internal static AmfMessage GetInvokeConnectError(AmfMessage message, string description, string level = Defines.RM_INVOKE_PARAMS_RESULT_LEVEL_ERROR, string code = Defines.RM_INVOKE_PARAMS_RESULT_CODE_NETCONNECTIONCONNECTREJECTED)
 {
     return(GetInvokeConnectError(message.ChannelId, message.StreamId, message.InvokeId, level, code,
                                  description));
 }
Example #6
0
        public static AmfMessage GetInvokeConnectResult(AmfMessage request, string level = Defines.RM_INVOKE_PARAMS_RESULT_LEVEL_STATUS, string code = Defines.RM_INVOKE_PARAMS_RESULT_CODE_NETCONNECTIONCONNECTSUCCESS, string description = Defines.RM_INVOKE_PARAMS_RESULT_DESCRIPTION_CONNECTIONSUCCEEDED)
        {
            double objectEncoding = (int)request.InvokeParam[0][Defines.RM_INVOKE_PARAMS_RESULT_OBJECTENCODING];

            return(GetInvokeConnectResult(request.ChannelId, request.StreamId, request.InvokeId, level, code, description, objectEncoding));
        }
        public static AmfMessage GetInvokeCreateStreamResult(AmfMessage request, double createdStreamId)

        {
            return(GetInvokeCreateStreamResult(request.ChannelId, request.StreamId,
                                               request.Body[Defines.RM_INVOKE, Defines.RM_INVOKE_ID], createdStreamId));
        }
 public static AmfMessage GetInvokeOnStatusStreamPublishBadName(AmfMessage request, string streamName)
 {
     return(GetInvokeOnStatusStreamPublishBadName(request.ChannelId, request.StreamId, request.InvokeId, streamName));
 }
Example #9
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);
            }
        }
Example #10
0
 /// <summary>
 /// Create a status message's reply target.
 /// </summary>
 /// <param name="requestMessage">Request message.</param>
 static public string CreateStatusReplyTarget(AmfMessage requestMessage)
 {
     return(string.Format(OperationFaultTarget, requestMessage.Response ?? string.Empty));
 }