0

I've following code snippet of one of my window service and that is importing data in Dynamics CRM, say contacts. and that is throwing exception. I've written exception in the following. It is really serious and provoke many issues to my sales team. I am really seeking assistance from experts

 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)
Mohsin Tester
  • 35
  • 1
  • 8
  • Have you tried this: http://stackoverflow.com/questions/10340591/how-to-narrow-down-to-the-actual-issue-when-you-receive-a-generic-soapexception – Tony Hinkle Feb 25 '16 at 15:48
  • Where is the code snippet you talked about? are you able to connect to the server? As it stands, this question has no information to help give you guidance other than a generic SOAP error. – Joseph Duty Feb 25 '16 at 21:16
  • well, we have gone through code snippet and try to do debug and import very smartly. But now we are considering the update the service and add exception handling properly. but I don't have idea which kinda exceptions the window services normally throw. – Mohsin Tester Feb 26 '16 at 11:19

1 Answers1

0

This is not exactly "on-point" to your question but it will solve the problem of not being able to properly log the exception. It is the code I use in my CRM applications (except for plugins/workflows running in the CRM sandbox) to get all the details of an Exception object.

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

Credit to: 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}";
            }
        }
    }
}
Community
  • 1
  • 1
Nicknow
  • 7,154
  • 3
  • 22
  • 38