WebService.cs

Create the following class

public static class GlobalEnumerations 
{
   public enum en_SERVICE_ENVIRON_TYPE
   {
      NOTDEFINED, TESTING, PRODUCTION
   }

   public enum en_SERVICE_EXCEPTION
   {
      zUnableToReturnDataFromThisXML,
      zUnableToRetrieveAnyData,
      zOther
   }
}
//-----------------------------------------------------------------------
public class BET_ServiceInfo
{
   public string Property_ServiceName { get; set; }
   public GlobalEnumerations.enSERVICE_ENVIRON_TYPE Property_EnvironmentFrom { get; set; }
   public GlobalEnumerations.enSERVICE_ENVIRON_TYPE Property_EnvironmentTo { get; set; }
}
//-----------------------------------------------------------------------
public class BET_WebService
{
   public string Property_ServiceName { get; set; }
   public string Property_ServiceAddress { get; set; }
   public object Property_ClientProxyOrURL { get; set; }
   public System.Collections.ArrayList Property_EnvironmentList { get; set; }

   private GlobalEnumerations.en_SERVICE_ENVIRON_TYPE m_Environment;

   public GlobalEnumerations.en_SERVICE_ENVIRON_TYPE Property_Environment
   {
      get
      {
         return this.m_Environment;
      }
      set
      {
         this.Environment = value;
         if (this.Property_ServiceName != null)
         {
            switch (this.Property_ServiceName.ToLower())
            {
               case "rest_myservice":
                  this.Method_EndPointChange(BET_WebService.Method_REST_MyService_ReturnURL(this.m_Environment);
                  break;
               case "soap_myservice":
                  this.Method_EndPointChange(BET_WebService.Method_SOAP_MyService_ReturnURL(this.m_Environment);
                  break;
               default:
                  break;
            }
         }
      }
   }

   public BET_WebService(
      string sWebServiceName)
   {
      try
      {
         this.m_Environment = GlobalEnumerations.en_SERVICE_ENVIRON_TYPE.NOTDEFINED;
         this.Property_EnvironmentList = new System.Collections.ArrayList();
         this.Property_ServiceName = sWebServiceName;

         switch(sWebServiceName.ToLower())
         {
            case "rest_myservice":
               this.Method_Settings_LiveEnvironment("REST_MYSERVICE_SERVICE");
               this.Property_ServiceAddress = BET_WebService.Method_REST_MyService_ReturnURL(this.m_Environment);
               break;

            case "soap_myservice":
               this.Method_Settings_LiveEnvironment("SOAP_MYSERVICE_SERVICE");
               this.Property_ServiceAddress = BET_WebService.Method_SOAP_MyService_ReturnURL(this.m_Environment);
               break;

            default:
               break;
         }
      }
      catch(System.Exception ex)
      {
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
      }
   }

   public EnvironmentType Method_Return_RESTServiceEnvironment(
      GlobalEnumerations.en_SERVICE_ENVIRON_TYPE sEnvironment)
   {
      try
      {
         switch (sEnvironment.ToString().ToLower())
         {
            case "testing":
               return EnvironmentType.Testing;
            case "production":
               return EnvironmentType.Production;
            default:
               return EnvironmentType.Testing;
         }
      }
      catch(System.Exception ex)
      {
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
         return Environment.Testing;
      }
   }

   private System.ServiceModel.BasicHttpBinding Method_HTTPBindingCreate()
   {
      try
      {
         System.ServiceModel.BasicHttpBinding oBasicHttpBinding;
         oBasicHttpBinding = new System.ServiceModel.BasicHttpBinding();
         oBasicHttpBinding.MaxReceivedMessageSize = 2147000000;
         oBasicHttpBinding.ReaderQuotas.MaxStringContentLength = 2147000000;
         oBasicHttpBinding.OpenTimeout = new System.TimeSpan(0, 3, 0);
         oBasicHttpBinding.SendTimeout = new System.TimeSpan(0, 3, 0);
         oBasicHttpBinding.CloseTimeout = new System.TimeSpan(0, 3, 0);
         return oBasicHTTPBinding;
      }
      catch(System.Exception ex)
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
         return null;
      }
   }

   public void Method_EndPointChange(string sEndPointURL)
   {
      try
      {
         System.ServiceModel.BasicHTTpBinding oBasicHttpBinding = null;
         System.ServiceModel.EndpointAddress oEndpointAddress = null;

         if (sEndPointURL.Length > 0)
         {
            this.Property_ServiceAddress = sEndPointURL;
            if (this.Property_ServiceAddress.Substring(0, 4).ToLower() == "soap")
            {
               oBasicHttpBinding = this.Method_HTTPBindingCreate();
               oEndpointAddress = new System.ServiceModel.EndpointAddress(sEndPointURL);
            }

            switch (this.Property_ServiceName.ToLower())
            {
               case "soap_myservice":
                  this.Property_ClientProxyOrURL = new SOAPServiceReference.MyServiceClient(oBasicHttpBinding, oEndpointAddress);
                  break;

               case "rest_myservice":
                  this.Property_ClientProxyOrURL = BET_WebService.Method_REST_MyService_ReturnURL(this.m_Environment);
                  break;

               default:
                  break;
            }
         }
      }
      catch(System.Exception ex)
      {
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
      }
   }

   private void Method_Settings_LiveEnvironment(
      string sWebServiceName)
   {
      try
      {
         this.m_Environment = GlobalEnumerations.en_SERVICE_ENVIRON_TYPE.NOTDEFINED;

         if (this.Method_AppSetting_Exists("APP_" + sWebServiceName + "_TESTING") == true)
         {
            this.Property_EnvironmentList.Add("TESTING");
            this.m_Environment = GlobalEnumerations.enSERVICE_ENVIRON_TYPE.TESTING;
         }
         if (this.Method_AppSetting_Exists("APP_" + sWebServiceName + "_PRODUCTION") == true)
         {
            this.Property_EnvironmentList.Add("PRODUCTION");
            this.m_Environment = GlobalEnumerations.enSERVICE_ENVIRON_TYPE.PRODUCTION;
         }
         this.m_Environment = Constants.ENVIRONMENT_DEFAULT;
      }
      catch(System.Exception ex)
      {
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
      }
   }

   private bool Method_AppSettings_Exists(
      string sSettingName)
   {
      try
      {
         bool breturn = false;
         breturn = Properties.Settings.Default.Properties[sSettingName] != null;
         return breturn;
      }
      catch(System.Exception ex)
      {
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
         return false;
      }
   }

   public static string Method_REST_MyService_ReturnURL(
       GlobalEnumerations.en_SERVICE_ENVIRON_TYPE oEnvironment)
   {
      try
      {
         switch (oEnvironment)
         {
            case GlobalEnumerations.en_SERVICE_ENVIRON_TYPE.TESTING:
               return Properties.Settings.Default.APP_SOAP_MyService_TESTING;
            case GlobalEnumerations.en_SERVICE_ENVIRON_TYPE.PRODUCTION:
               return Properties.Settings.Default.APP_SOAP_MyService_PRODUCTION;
            default:
               return "";
         }
      }
      catch(System.Exception ex)
      {
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
         return "";
      }

   public static string Method_SOAP_MyService_ReturnURL(
       GlobalEnumerations.en_SERVICE_ENVIRON_TYPE oEnvironment)
   {
      try
      {
         switch (oEnvironment)
         {
            case GlobalEnumerations.en_SERVICE_ENVIRON_TYPE.TESTING:
               return Properties.Settings.Default.APP_REST_MyService_TESTING;
            case GlobalEnumerations.en_SERVICE_ENVIRON_TYPE.PRODUCTION:
               return Properties.Settings.Default.APP_REST_MyService_PRODUCTION;
            default:
               return "";
         }
      }
      catch(System.Exception ex)
      {
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
         return "";
      }
//-----------------------------------------------------------------------
public class BET_WebServicesHUB
{
   private System.Collections.Generic.List<BET_WebService> m_oServicesList;

   public WebServicesHUB()
   {
      try
      {
         BET_WebService oWebService;
         System.ServiceModel.Configuration.ClientSection oClientSection;
         System.ServiceModel.Configuration.ChannelEndpointElement oChannelEndPoint;

         this.m_oServicesList = new System.Collections.Generic.List<BET_WebService>();

         oWebService = new BET_WebService("REST_MyService");
         m_oServicesList.Add(oWebService);
  
         oChannelEndPoint = new System.ServiceModel.Configuration.ChannelEndpointElement();
         oChannelEndPoint.Name = "SOAP_MyService";
         oClientSection = new System.ServiceModel.Configuration.ClientSection();
         oClientSection.EndPoints.Add(oChannelEndPoint);
         oWebService = new BET_WebService(oClientSection.Endpoints[0]);
         m_oServicesList.Add(oWebService);
      }
      catch(System.Exception ex)
      {
         BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
      }
   }

   public BET_WebService Method_GetService(string sServiceName)
   {
      try
      {
         BET_WebService oService;
   
         for (int icount = 0; icount < this.m_oServicesList.Count; icount++)
         {
            oService = this.m_oServicesList[icount];
            if (sServiceName == oService.Property_ServiceName)
            {
               return oService;
            }
         }
         return null;
       }
       catch (System.Exception ex)
       {
          BET_ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
          return null;
      }
   }
}
//-----------------------------------------------------------------------
public class CoreObjects
{
   public WebServicesHUB Property_WebServicesHub { get; set; }
   public string Property_CurrentUserName { get; set; }

   public CoreObjects()
   {
      this.Property_WebServicesHub = new WebServicesHub();
   }
}


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext