我已经关注了我的一个窗口服务的代码片段,并且正在导入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)
答案 0 :(得分:0)
这不是你的问题的“点”,但它将解决无法正确记录异常的问题。这是我在CRM应用程序中使用的代码(除了在CRM沙箱中运行的插件/工作流),以获取Exception
对象的所有详细信息。
https://gist.github.com/nicknow/dc0748dc631e43b26158
感谢:How to get extra exception details for logging?
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}";
}
}
}
}