I've implemented a class to perform a couple of tasks through a web service. I'll be really keen if you can take a look at, give me your professional opinion.
using MWM.NavisionWebService.WebReferenceTest;
using NLog;
using System;
using System.Net;
using System.Configuration;
namespace MWM.NavisionWebService
{
public class WebServiceAccess : IDisposable
{
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
private readonly string _user;
private readonly string _pass;
private readonly NSO _nsoWebService;
public WebServiceAccess()
{
_nsoWebService = new NSO { Credentials = GetCredentials() };
_user = ConfigurationManager.AppSettings["CghWebServiceUserName"];
_pass = ConfigurationManager.AppSettings["CghWebServicePassword"];
}
public void UpdateTechnician(string serviceOrderId, string technicianErpId)
{
try
{
int errorCode = _nsoWebService.UpdateResource(serviceOrderId, technicianErpId);
if (errorCode != 0)
HandleErrors(errorCode);
else
_logger.Trace(String.Format("Navision Technician updated to {0} for service order {1}.", technicianErpId, serviceOrderId));
}
catch (Exception ex)
{
_logger.Error("Error updating a technician in Navision. Error: " + ex.Message);
throw;
}
}
public void UpdateAppointmentDate(string serviceOrderId, DateTime startDate)
{
try
{
int errorCode = _nsoWebService.UpdateTime(serviceOrderId, startDate, startDate);
if (errorCode != 0)
HandleErrors(errorCode);
else
_logger.Trace(String.Format("Navision appointment updated to {0} for service order {1}.", startDate, serviceOrderId));
}
catch (Exception ex)
{
_logger.Error("Error updating an appointment in Navision. Error: " + ex.Message);
throw;
}
}
private ICredentials GetCredentials()
{
return new NetworkCredential(_user, _pass);
}
private void HandleErrors(int errorCode)
{
_logger.Error("Error updating Navision through the web service. Code: " + errorCode + " Message: " + GetErrorCodeDescription(errorCode));
}
private string GetErrorCodeDescription(int errorCode)
{
switch (errorCode)
{
case 0:
return "OK";
case 1:
return "Could not find CCC Order No.";
case 51:
return "Could not write table.";
default:
return "Error code not found.";
}
}
public void Dispose()
{
// Dispose from unmanaged resources
_nsoWebService.Dispose();
}
}
}
Dispose()
method does enough. \$\endgroup\$