public async Task <FabricTransportReplyMessage> RequestResponseAsync(
            FabricTransportRequestContext requestContext, byte[] headers, byte[] requestBody)
        {
            // We have Cancellation Token for Remoting layer , hence timeout is not used here.
            ServiceRemotingMessageHeaders messageHeaders = null;

            try
            {
                messageHeaders = ServiceRemotingMessageHeaders.Deserialize(this.serializer, headers);
            }
            catch (Exception e)
            {
                //This can only happen if there is issue in our product code like Message Corruption or changing headers format.
                ReleaseAssert.Failfast("DeSerialization failed  for RemotingMessageHeaders with reason {0} for the headers with length {1}", e, headers.Length);
            }

            var context = new FabricTransportServiceRemotingRequestContext(requestContext);

            byte[] replybody;
            try
            {
                replybody = await this.messageHandler.RequestResponseAsync(context, messageHeaders, requestBody);

                return(new FabricTransportReplyMessage(false, replybody));
            }
            catch (Exception e)
            {
                ServiceTrace.Source.WriteInfo("FabricTransportCommunicationHandler", "Exception While dispatching {0}",
                                              e);
                var remoteExceptionInformation = RemoteExceptionInformation.FromException(e);
                replybody = remoteExceptionInformation.Data;
                return(new FabricTransportReplyMessage(true, replybody));
            }
        }
        Task <byte[]> IServiceRemotingClient.RequestResponseAsync(ServiceRemotingMessageHeaders messageHeaders,
                                                                  byte[] requestBody)
        {
            var header = ServiceRemotingMessageHeaders.Serialize(this.serializer, messageHeaders);

            return(this.nativeClient.RequestResponseAsync(header, requestBody,
                                                          this.settings.OperationTimeout).ContinueWith(t =>
            {
                var retval = t.GetAwaiter().GetResult();
                if (retval.IsException)
                {
                    Exception e;
                    var isDeserialzied =
                        RemoteExceptionInformation.ToException(new RemoteExceptionInformation(retval.GetBody()),
                                                               out e);
                    if (isDeserialzied)
                    {
                        throw new AggregateException(e);
                    }
                    else
                    {
                        throw new ArgumentException(@"failed to deserialize and get remote exception",
                                                    "remoteExceptionInformation");
                    }
                }
                return retval.GetBody();
            }));
        }
Esempio n. 3
0
        async public Task <byte[]> RequestResponseAsync(ServiceRemotingMessageHeaders headers, byte[] requestBody)
        {
            try
            {
                return(await this.wcfClient.Channel.RequestResponseAsync(headers, requestBody).ContinueWith(
                           t => t.GetAwaiter().GetResult(),
                           TaskScheduler.Default));

                // the code above (TaskScheduler.Default) for dispatches the responses on different thread
                // so that if the user code blocks, we do not stop the response receive pump in WCF
            }
            catch (FaultException <RemoteExceptionInformation> faultException)
            {
                Exception remoteException;
                if (RemoteExceptionInformation.ToException(faultException.Detail, out remoteException))
                {
                    throw new AggregateException(remoteException);
                }

                throw new ServiceException(remoteException.GetType().FullName, string.Format(
                                               CultureInfo.InvariantCulture,
                                               Microsoft.ServiceFabric.Services.Wcf.SR.ErrorDeserializationFailure,
                                               remoteException.ToString()));
            }
        }
        Task <byte[]> IServiceRemotingClient.RequestResponseAsync(ServiceRemotingMessageHeaders messageHeaders,
                                                                  byte[] requestBody)
        {
            var header = ServiceRemotingMessageHeaders.Serialize(this.serializer, messageHeaders);

            return(this.nativeClient.RequestResponseAsync(header, requestBody,
                                                          this.settings.OperationTimeout).ContinueWith(t =>
            {
                var retval = t.GetAwaiter().GetResult();
                if (retval.IsException)
                {
                    Exception e;
                    var isDeserialzied =
                        RemoteExceptionInformation.ToException(new RemoteExceptionInformation(retval.GetBody()),
                                                               out e);

                    if (isDeserialzied)
                    {
                        throw new AggregateException(e);
                    }
                    else
                    {
                        throw new ServiceException(e.GetType().FullName, string.Format(
                                                       CultureInfo.InvariantCulture,
                                                       Remoting.SR.ErrorDeserializationFailure,
                                                       e.ToString()));
                    }
                }
                return retval.GetBody();
            }));
        }
Esempio n. 5
0
        /// <summary>
        ///		Initialize new instance with unpacked data.
        /// </summary>
        /// <param name="rpcError">
        ///		Metadata of error. If you specify null, <see cref="Core.RpcError.RemoteRuntimeError"/> is used.
        ///	</param>
        /// <param name="unpackedException">
        ///		Exception data from remote MessagePack-RPC server.
        ///	</param>
        /// <exception cref="SerializationException">
        ///		Cannot deserialize instance from <paramref name="unpackedException"/>.
        /// </exception>
        protected internal RpcException(RpcError rpcError, MessagePackObject unpackedException)
            : this(rpcError, unpackedException.GetString(messageKeyUtf8), unpackedException.GetString(debugInformationKeyUtf8))
        {
            if (unpackedException.IsDictionary)
            {
                if (unpackedException.AsDictionary().TryGetValue(remoteExceptionsUtf8, out var mayBeArray) && mayBeArray.IsArray)
                {
                    var array = mayBeArray.AsList();
                    remoteExceptions = new RemoteExceptionInformation[array.Count];
                    for (var i = 0; i < remoteExceptions.Length; i++)
                    {
                        if (array[i].IsList)
                        {
                            remoteExceptions[i] = new RemoteExceptionInformation(array[i].AsList());
                        }
                        else
                        {
                            // Unexpected type.
                            Debug.WriteLine("Unexepcted ExceptionInformation at {0}, type: {1}, value: \"{2}\".", i, array[i].UnderlyingType, array[i]);
                            remoteExceptions[i] = new RemoteExceptionInformation(new MessagePackObject[] { array[i] });
                        }
                    }
                }
            }

            RegisterSerializeObjectStateEventHandler();
        }
        public void FromExceptionTest()
        {
            // Arrange
            var       expectedLength = 944;
            Exception exception      = new Exception("Test Exception");

            // Act
            var result = RemoteExceptionInformation.FromException(exception);

            // Assert
            Assert.Equal(expectedLength, result.Data.Length);
        }
Esempio n. 7
0
 public async Task <byte[]> RequestResponseAsync(ServiceRemotingMessageHeaders headers, byte[] requestBody)
 {
     try
     {
         return(await this.messageHandler.RequestResponseAsync(
                    this.requestContext,
                    headers,
                    requestBody));
     }
     catch (Exception e)
     {
         throw new FaultException <RemoteExceptionInformation>(RemoteExceptionInformation.FromException(e));
     }
 }
        async public Task <byte[]> RequestResponseAsync(ServiceRemotingMessageHeaders headers, byte[] requestBody)
        {
            try
            {
                return(await this.wcfClient.Channel.RequestResponseAsync(headers, requestBody).ContinueWith(
                           t => t.GetAwaiter().GetResult(),
                           TaskScheduler.Default));

                // the code above (TaskScheduler.Default) for dispatches the responses on different thread
                // so that if the user code blocks, we do not stop the response receive pump in WCF
            }
            catch (FaultException <RemoteExceptionInformation> faultException)
            {
                Exception remoteException;
                if (RemoteExceptionInformation.ToException(faultException.Detail, out remoteException))
                {
                    throw remoteException;
                }

                throw;
            }
        }
Esempio n. 9
0
        public async Task <FabricTransportReplyMessage> RequestResponseAsync(
            FabricTransportRequestContext requestContext, byte[] headers, byte[] requestBody)
        {
            // We have Cancellation Token for Remoting layer , hence timeout is not used here.
            var messageHeaders = ServiceRemotingMessageHeaders.Deserialize(this.serializer, headers);
            var context        = new FabricTransportServiceRemotingRequestContext(requestContext);

            byte[] replybody;
            try
            {
                replybody = await this.messageHandler.RequestResponseAsync(context, messageHeaders, requestBody);

                return(new FabricTransportReplyMessage(false, replybody));
            }
            catch (Exception e)
            {
                ServiceTrace.Source.WriteInfo("FabricTransportCommunicationHandler", "Exception While dispatching {0}",
                                              e);
                var remoteExceptionInformation = RemoteExceptionInformation.FromException(e);
                replybody = remoteExceptionInformation.Data;
                return(new FabricTransportReplyMessage(true, replybody));
            }
        }