Beispiel #1
0
        ///<summary>Optionally set hasConnectionLost true to keep the calling thread here until a connection to the Middle Tier connection can be established
        ///in the event of a web connection failure. Set hasConnectionLost to false if a throw is desired when a connection cannot be made.</summary>
        internal static string SendAndReceive(DataTransferObject dto, bool hasConnectionLost = true)
        {
            //Anyone trying to invoke a method other than CheckUserAndPassword must first check the current HasLoginFailed status as to not call the middle tier too often.
            bool isCheckUserAndPassword = (dto.MethodName == nameof(OpenDentBusiness) + "." + nameof(Userods) + "." + nameof(Userods.CheckUserAndPassword));

            if (!isCheckUserAndPassword && HasLoginFailed)
            {
                throw new ODException("Invalid username or password.", ODException.ErrorCodes.CheckUserAndPasswordFailed);
            }
            string            dtoString = dto.Serialize();
            IOpenDentalServer service   = OpenDentBusiness.WebServices.OpenDentalServerProxy.GetOpenDentalServerInstance();

            return(SendAndReceiveRecursive(service, dtoString, hasConnectionLost));
        }
Beispiel #2
0
 ///<summary>Tries to process the dto passed in.  If there was a web connection failure then this method will keep the calling thread here
 ///until a connection to the Middle Tier can be established.  Set hasConnectionLost to false if a throw is desired when a connection cannot be made.
 ///E.g. Set hasConnectionLost to false when a user is trying to log in for the first time (don't want to try logging in forever).</summary>
 private static string SendAndReceiveRecursive(IOpenDentalServer service, string dtoString, bool hasConnectionLost = true)
 {
     try {
         return(service.ProcessRequest(dtoString));
     }
     catch (WebException wex) {
         //If no connection monitoring desired or this is a WebException that we aren't explicitly looking for then bubble up the exception.
         //WebException class: https://docs.microsoft.com/en-us/dotnet/api/system.net.webexception?view=netframework-4.7.2
         //WebException.Status property: https://docs.microsoft.com/en-us/dotnet/api/system.net.webexception.status?view=netframework-4.7.2
         //Handling WebExceptions: https://docs.microsoft.com/en-us/dotnet/framework/network-programming/handling-errors?view=netframework-4.7.2
         if (!hasConnectionLost || wex.Status != WebExceptionStatus.ConnectFailure)
         {
             throw;
         }
         //The calling method wants to automatically retry connecting to the Middle Tier until it comes back.
         RemoteConnectionFailed();
         return(SendAndReceiveRecursive(service, dtoString));
     }
 }