自定义窗口服务引发异常:服务器无法处理请求

本文关键字:服务器 处理 请求 异常 窗口 服务 自定义 | 更新日期: 2023-09-27 18:36:15

我遵循了我的一个窗口服务的代码片段,那就是在Dynamics CRM中导入数据,联系人说。 这是抛出异常。我在下面写了例外。这真的很严重,给我的销售团队带来了许多问题。我真的在寻求专家的帮助

 An error has occured with the myService:
Exception Message: Server was unable to process request.
Inner Exception: 
Date Time: 2/24/2016 7:55:11 PM
Stack Trace:    at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at STGDepositServ.CrmSdk.CrmService.Create(BusinessEntity entity)
   at STGDepositServ.STGDepositServ.timer1_Elapsed(Object sender, ElapsedEventArgs e)

自定义窗口服务引发异常:服务器无法处理请求

这对您的问题并不完全"切中要害",但它将解决无法正确记录异常的问题。这是我在CRM应用程序中使用的代码(在CRM沙箱中运行的插件/工作流除外)来获取Exception对象的所有详细信息。

https://gist.github.com/nicknow/dc0748dc631e43b26158

信用来源:如何获取日志记录的额外异常详细信息?

namespace nicknow.Logging
{
    static class NonSandboxedExceptionLogging
    {
        ///From the example at https://stackoverflow.com/a/12827271/394978
        /// <summary>
        /// This utility method can be used for retrieving extra details from exception objects. Cannot be used in code running in the Dynamics CRM Sandbox
        /// </summary>
        /// <param name="e">Exception.</param>
        /// <param name="indent">Optional parameter. String used for text indent.</param>
        /// <returns>String with as much details was possible to get from exception.</returns>
        public static string GetExtendedExceptionDetails(object e, string indent = null)
        {
            // we want to be robust when dealing with errors logging
            try
            {
                var sb = new StringBuilder(indent);
                sb.AppendLine("NonSandboxedExceptionLogging");
                // it's good to know the type of exception
                sb.AppendLine($"Type: {e.GetType().FullName}");
                // fetch instance level properties that we can read
                var props = e.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.CanRead);
                foreach (var p in props)
                {
                    try
                    {
                        var v = p.GetValue(e, null);
                        // in case of Fault contracts we'd like to know what Detail contains
                        if (e is FaultException && p.Name == "Detail")
                        {
                            sb.AppendLine($"{indent}{p.Name}:");
                            sb.AppendLine(GetExtendedExceptionDetails(v, $"  {indent}"));// recursive call
                        }
                        // Usually this is InnerException
                        else if (v is Exception)
                        {
                            sb.AppendLine($"{indent}{p.Name}:");
                            sb.AppendLine(GetExtendedExceptionDetails(v as Exception, $"  {indent}"));// recursive call
                        }
                        // some other property
                        else
                        {
                            sb.AppendLine($"{indent}{p.Name}: '{v}'");
                            // Usually this is Data property
                            if (v is IDictionary)
                            {
                                var d = v as IDictionary;
                                sb.AppendLine($"{"  " + indent}Count={d.Count}");
                                foreach (DictionaryEntry kvp in d)
                                {
                                    sb.AppendLine($"{"  " + indent}[{kvp.Key}]:[{kvp.Value}]");
                                }
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        sb.AppendLine($"GetExtendedExceptionDetails: Exception during logging of property {p.Name}: {exception.Message}");
                    }
                }
                return sb.ToString();
            }
            catch (Exception exception)
            {
                //log or swallow here
                return $"GetExtendedExceptionDetails: Exception during logging of Exception message: {exception.Message}";
            }
        }
    }
}