Exemplo n.º 1
0
        public static void ServiceThrowsExceptionDetailsIncludedInFault()
        {
            string exceptionMessage    = "This is the exception message";
            string stackTraceTopMethod = "   at ErrorHandling.ThrowingService.Echo(String echo)";

            System.ServiceModel.ChannelFactory <ISimpleService> factory = DispatcherHelper.CreateChannelFactory <ThrowingDetailInFaultService, ISimpleService>(
                (services) =>
            {
                services.AddSingleton(new ThrowingDetailInFaultService(new Exception(exceptionMessage)));
            });
            factory.Open();
            ISimpleService channel = factory.CreateChannel();

            ((System.ServiceModel.IClientChannel)channel).Open();
            System.ServiceModel.FaultException <System.ServiceModel.ExceptionDetail> exceptionThrown = Assert.Throws <System.ServiceModel.FaultException <System.ServiceModel.ExceptionDetail> >(() =>
            {
                _ = channel.Echo("hello");
            });
            Assert.NotNull(exceptionThrown);
            Assert.NotNull(exceptionThrown.Detail);
            Assert.True(exceptionThrown.Code.IsReceiverFault);
            System.ServiceModel.ExceptionDetail detail = exceptionThrown.Detail;
            Assert.Equal(exceptionMessage, detail.Message);
            Assert.StartsWith(stackTraceTopMethod, detail.StackTrace);
            Assert.Equal("InternalServiceFault", exceptionThrown.Code.SubCode.Name);
            ((System.ServiceModel.Channels.IChannel)channel).Close();
            factory.Close();
            TestHelper.CloseServiceModelObjects((System.ServiceModel.Channels.IChannel)channel, factory);
        }
Exemplo n.º 2
0
        public static string FormatExceptionInfo(this System.ServiceModel.ExceptionDetail detail)
        {
            var sb = new System.Text.StringBuilder();

            sb.Append(detail.Type);
            if (!string.IsNullOrEmpty(detail.Message))
            {
                sb.Append(": ");
                sb.Append(detail.Message);
            }
            if (detail.InnerException != null)
            {
                sb.Append(Environment.NewLine);
                sb.Append("---> ");
                sb.Append(detail.InnerException.FormatExceptionInfo());
                sb.Append(Environment.NewLine);
                sb.Append("   --- End of inner exception stack trace ---");
            }
            if (detail.StackTrace != null)
            {
                sb.Append(Environment.NewLine);
                sb.Append(detail.StackTrace);
            }

            return(sb.ToString());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the data from specified <see cref="Message"/> object.
        /// </summary>
        /// <typeparam name="T">Type of returned object with data.</typeparam>
        /// <param name="data">The <see cref="Message"/> with data.</param>
        /// <returns>Object with data.</returns>
        public static T GetData <T>(Message data)
        {
            RoboFramework.Tools.RandomLogHelper.GetLog().Debug("SynchronizationHelper::T GetData<T>(Message data)");
            using (data)
            {
                if (data == null)
                {
                    return(default(T));
                }

                if (data.IsFault == true)
                {
                    MessageFault fault = MessageFault.CreateFault(data, 500000);
                    if (fault.HasDetail)
                    {
                        System.ServiceModel.ExceptionDetail excDet = fault.GetDetail <System.ServiceModel.ExceptionDetail>();
                        Type      excType = String.IsNullOrEmpty(excDet.Type) ? null : Type.GetType(excDet.Type);
                        Exception e       = (excType == null) ? new Exception() : (Exception)Activator.CreateInstance(excType);

                        FieldInfo innerExceptionField = typeof(Exception).GetField("_innerException", BindingFlags.NonPublic | BindingFlags.Instance);
                        FieldInfo messageField        = typeof(Exception).GetField("_message", BindingFlags.NonPublic | BindingFlags.Instance);
                        FieldInfo stackTraceField     = typeof(Exception).GetField("_remoteStackTraceString", BindingFlags.NonPublic | BindingFlags.Instance);
                        innerExceptionField.SetValue(e, excDet.InnerException);
                        messageField.SetValue(e, excDet.Message);
                        stackTraceField.SetValue(e, excDet.StackTrace);
                        throw e;
                    }
                }

                return(data.GetBody <T>());
            }
        }
Exemplo n.º 4
0
 public System.Threading.Tasks.Task OnAddCompletedAsync(int result, System.ServiceModel.ExceptionDetail error)
 {
     return(base.Channel.OnAddCompletedAsync(result, error));
 }
Exemplo n.º 5
0
 public void OnAddCompleted(int result, System.ServiceModel.ExceptionDetail error)
 {
     base.Channel.OnAddCompleted(result, error);
 }