0
votes

I finally started reading about SOA and am giving WCF a shot along with Azure cloud services. One thing I find particularly difficult is debugging. Say I create a service and deploy it to the web as an Azure cloud service and have errors, how do I check what those errors are? I currently have a service that accepts a plain old POCO and then adds data to two Azure databases. My operation contract method returns a bool indicating whether the CRUD statements failed or passed. I keep getting a false bool back but have no way of stepping into code or logging each code line with a logging method.

  public bool SubmitSupportRequest(SupportRequestPacket packet)
    {
        bool status;

        //convert SupportRequestPacket to entities
        var ameeEntity = new AccuDb_Entities.SupportTicket();
        var preferedEntity = new AccuDb_Entities.Support_Requests();
        //ameeEntity will be depreciated soon. Moving all support requests to Accu_Db (second entity)

        ameeEntity.Client = packet.Client;
        ameeEntity.Date = packet.Date;
        ameeEntity.Description = packet.Description;
        ameeEntity.FirstName = !string.IsNullOrEmpty(packet.FirstName) ? packet.FirstName : "None Provided";
        ameeEntity.Ip = !string.IsNullOrEmpty(packet.IP) ? packet.IP : "None Provided";
        ameeEntity.LastName = !string.IsNullOrEmpty(packet.LastName) ? packet.LastName : "None Provided";
        ameeEntity.MachineName = packet.MachineName;
        ameeEntity.ProblemFrequency = packet.ProblemFrequency;
        ameeEntity.TypeOfProblem = packet.TypeOfProblem;

        preferedEntity.Client = packet.Client;
        preferedEntity.Date = packet.Date;
        preferedEntity.Description = packet.Description;
        preferedEntity.FirstName = !string.IsNullOrEmpty(packet.FirstName) ? packet.FirstName : "None Provided";
        preferedEntity.Ip = !string.IsNullOrEmpty(packet.IP) ? packet.IP : "None Provided";
        preferedEntity.LastName = !string.IsNullOrEmpty(packet.LastName) ? packet.LastName : "None Provided";
        preferedEntity.MachineName = packet.MachineName;
        preferedEntity.ProblemFrequency = packet.ProblemFrequency;
        preferedEntity.TypeOfProblem = packet.TypeOfProblem;

        using (var tempContext = new AccuDb_Entities.ameesupporttickets_dbEntities())
        {
            try
            {
                tempContext.SupportTickets.Add(ameeEntity);
                tempContext.SaveChanges();
                status = true;
            }
            catch
            {
                status = false;
                return status;
            }

        }

        using (var context = new AccuDb_Entities.Accu_DbEntities())
        {
            try
            {
                context.Support_Requests.Add(preferedEntity);
                context.SaveChanges();
                status = true;
            }
            catch
            {
                status = false;
            }
        }

        return status;
    }
1

1 Answers

2
votes

It's a very broad question so hard to give a specific question without writing a very long article.

If you are using Cloud Services (which it sounds like you are) then you configure various Diagnostics logging and also log shipping of trace logs in the Cloud project. You can then configure a trace listener in web.config that will ship everything you log with Trace.Write etc into Azure Table Storage every minute or two, depending on your configuration, like so:

<system.diagnostics>
   <trace>
      <listeners>
         <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, 
            Microsoft.WindowsAzure.Diagnostics, 
            Version=2.3.0.0, 
            Culture=neutral, 
            PublicKeyToken=31bf3856ad364e35"
            name="AzureDiagnostics">
            <filter type="" />
         </add>
      </listeners>
   </trace>
</system.diagnostics>​

You can then read those logs directly in table storage or use a tool like Cerebrate to get in a prettier format. This would enable you to output as much info as you like as the code gets executed.

One note is that you can play around with different levels, so you can log the messages as Verbose and you can change which message level is transferred to table storage in config; This means you can leave the logging calls in your code after debugging and just switch the transfer level up to Information or Warning to avoid seeing the detailed messages in table storage.

If you also switch on some diagnostics monitoring and the site logging you can get various other stats into table storage as well.

As with any "normal" WCF debugging, you can switch on a number of WCF specific dump options in Web.config, which will generate trace files on disk. You can then RDP into your cloud service to retrieve those files (I am making the assumption you are familiar with WCF, apologies if not).

Depending on your Visual Studio version you may also be able to deploy with intellitrace enabled and then you can download those files and play them back in Visual Studio.

I am sorry for being rather vague, it's quite a big subject and you need to spend some time working with it to make proper sense.

Oh, and if you look at Azure Web Sites, it's all different in there (though arguably nicer as you can do tail logging).

As an aside, if you building a brand new SOA system, you may want to look at using Web API to build a RESTful service rather than using WCF. Just sayin' :)