Esempio n. 1
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();
            }));
        }
        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();
            }));
        }
        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;
            }
        }