/// <include file='Avalara.AvaTax.Adapter.Doc.xml' path='adapter/common/members[@name="Constructor"]/*' /> public BaseSvc() { //this should be done first upon entering the assembly; expected that AddressSvc and TaxSvc will be // the only instantiated classes and therefore its safe to do this here. _avaLog = AvaLogger.GetLogger(); _avaLog.Debug(string.Format("Instantiating BaseSvc: {0}", _uniqueId)); string configFileName = Utilities.ConfigFileName(); if (configFileName != null && configFileName != "") { _config = (ServiceConfig)XmlSerializerSectionHandler.CreateFromXmlFile(configFileName, "ServiceConfig"); } if (_config == null) { //no config file or an invalid config file was found. //let's create a default one in case the consumer wants to fill in all fields manually _config = new ServiceConfig(); } }
internal object InvokeService(Type typeOfProxy, string methodName, object[] arg) { Object obj = null; Transaction transaction = null; try { MethodInfo method = typeOfProxy.GetMethod(methodName); if (method == null) { string msg = string.Format("Method '{0}' does not exist in type '{1}'.", methodName, typeOfProxy.ToString()); throw new ApplicationException(msg); } string service = typeOfProxy.Name.Substring(5); //set Url, Security Token, etc immediately prior to the service call this.SetServiceAccessProperties(); _avaLog.Debug("Copying Profile into proxy object"); FieldInfo field = typeOfProxy.GetField("ProfileValue"); this.Profile.CopyTo((ProxyProfile)field.GetValue(_svcProxy)); _avaLog.Debug("Copying Security into proxy object"); FieldInfo fieldSecurity = typeOfProxy.GetField("Security"); this.Security.CopyTo((ProxySecurity)fieldSecurity.GetValue(_svcProxy)); // BeginTransaction to log transaction details transaction = BeginTransaction(Profile.Machine, service, methodName); _avaLog.Debug(string.Format("Proxy.{0}", methodName)); Perf monitor = new Perf(); monitor.Start(); obj = method.Invoke(_svcProxy, arg); monitor.Stop(); if (transaction != null) { transaction.ClientDuration = monitor.ElapsedSeconds() * 1000;//monitor.Milliseconds; } _avaLog.Debug(string.Format("{0} (proxy method): {1}", methodName, monitor.ElapsedSeconds() * 1000)); } catch (Exception ex) { if (transaction != null) { transaction.SeverityLevelId = (byte)SeverityLevel.Exception; transaction.ErrorMessage = ex.Message; } _avaLog.Error(ex.Message); throw ex; } finally { EndTransaction((ProxyBaseResult)obj, transaction); } return(obj); }