Example #1
0
        internal static string SendAndReceive(DataTransferObject dto)
        {
            string dtoString = dto.Serialize();

            OpenDentalServer.ServiceMain service = new OpenDentBusiness.OpenDentalServer.ServiceMain();
            service.Url = ServerURI;
            if (MidTierProxyAddress != null && MidTierProxyAddress != "")
            {
                IWebProxy    proxy = new WebProxy(MidTierProxyAddress);
                ICredentials cred  = new NetworkCredential(MidTierProxyUserName, MidTierProxyPassword);
                proxy.Credentials = cred;
                service.Proxy     = proxy;
            }
            //The default useragent is
            //Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.296)
            //But DHS firewall doesn't allow that.  MSIE 6.0 is probably too old, and their firewall also looks for IE8Mercury.
            service.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; MS Web Services Client Protocol 4.0.30319.296; IE8Mercury)";
            string result = service.ProcessRequest(dtoString);

            //The web service (xml) serializer/deserializer is removing the '\r' portion of our newlines during the data transfer.
            //Replacing the string is not the best solution but it works for now. The replacing happens inside ProcessRequest() (server side) and here (client side).
            //It's done server side for usage purposes within the methods being called (exampe: inserting into db) and then on the client side for displaying purposes.
            if (result != null)
            {
                result = result.Replace("\n", "\r\n");
            }
            return(result);
        }
Example #2
0
        internal static byte[] SendAndReceive(DataTransferObject dto)
        {
            byte[] data = dto.Serialize();
            //#if DEBUG
            //	string xmlString=Encoding.UTF8.GetString(data);
            //	Debug.WriteLine("Client Sent: "+xmlString);
            //#endif
            if (client == null)
            {
                try{
                    client    = new TcpClient(ServerName, ServerPort);
                    netStream = client.GetStream();
                }
                catch {
                    throw new Exception("Server is refusing the connection. Either the server program is not running, or a port on the server is being blocked by a firewall.");
                }
            }
            try{
                netStream.Write(data, 0, data.Length);
            }
            catch (Exception e) {
                netStream.Close();
                client.Close();
                client = null;
                throw e;
            }
            //Receive the TcpServer.response-------------------------------------
            Byte[] buffer = new Byte[16384];            //a power of 2 that will easily cover average size result sets.
            //MemoryStream memStream=new MemoryStream();
            int           numberOfBytesRead = 0;
            StringBuilder strBuild          = new StringBuilder();
            //int readValue;
            Decoder decoder = Encoding.UTF8.GetDecoder();

            char[] chars;
            do
            {
                //this next line blocks until the response comes back
                numberOfBytesRead = netStream.Read(buffer, 0, buffer.Length);
                //readValue=netStream.ReadByte();
                // Use Decoder class to convert from bytes to UTF8
                // in case a character spans two buffers.
                chars = new char[decoder.GetCharCount(buffer, 0, numberOfBytesRead)];
                decoder.GetChars(buffer, 0, numberOfBytesRead, chars, 0);
                strBuild.Append(chars);
                // Check for EOF or an empty message.
                if (strBuild.ToString().IndexOf("<EOF>") != -1)
                {
                    break;
                }
            }while(numberOfBytesRead != 0);         //netStream.DataAvailable);
            strBuild.Replace("<EOF>", "");
            //memStream must be decoupled by converting to byte[] and then back to memStream.
            buffer = Encoding.UTF8.GetBytes(strBuild.ToString());          //memStream.ToArray();
            return(buffer);
        }
Example #3
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));
        }
Example #4
0
        internal static string SendAndReceive(DataTransferObject dto)
        {
            string dtoString = dto.Serialize();

            OpenDentalServer.ServiceMain service = new OpenDentBusiness.OpenDentalServer.ServiceMain();
            service.Url = ServerURI;
            string result = service.ProcessRequest(dtoString);

            //The web service (xml) serializer/deserializer is removing the '\r' portion of our newlines during the data transfer.
            //Replacing the string is not the best solution but it works for now. The replacing happens inside ProcessRequest() (server side) and here (client side).
            //It's done server side for usage purposes within the methods being called (exampe: inserting into db) and then on the client side for displaying purposes.
            if (result != null)
            {
                result = result.Replace("\n", "\r\n");
            }
            return(result);
        }