Esempio n. 1
0
 static void Main(string[] args)
 {
     try
     {
         IStateName            proxy  = XmlRpcProxyGen.Create <IStateName>();
         RequestResponseLogger logger = new RequestResponseLogger();
         logger.Directory = "C:/temp";
         proxy.AttachLogger(logger);
         Console.WriteLine("Synchronous call");
         string ret = proxy.GetStateName(45);
         Console.WriteLine("state #45 is {0}", ret);
         Console.WriteLine("Asynchronous call");
         IAsyncResult asr = proxy.BeginGetStateName(46);
         asr.AsyncWaitHandle.WaitOne();
         string aret = proxy.EndGetStateName(asr);
         Console.WriteLine("state #46 is {0}", aret);
     }
     catch (XmlRpcFaultException fex)
     {
         Console.WriteLine(fex.FaultString);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Esempio n. 2
0
        public void MakeAsynchronousCallWait()
        {
            IStateName   proxy = (IStateName)XmlRpcProxyGen.Create(typeof(IStateName));
            IAsyncResult asr2  = proxy.BeginGetStateName(1);

            asr2.AsyncWaitHandle.WaitOne();
            string ret2 = proxy.EndGetStateName(asr2);

            Assert.AreEqual("Alabama", ret2);
        }
Esempio n. 3
0
        public void MakeAsynchronousCallIsCompleted()
        {
            IStateName   proxy = (IStateName)XmlRpcProxyGen.Create(typeof(IStateName));
            IAsyncResult asr1  = proxy.BeginGetStateName(1);

            while (asr1.IsCompleted == false)
            {
                System.Threading.Thread.Sleep(10);
            }
            string ret1 = proxy.EndGetStateName(asr1);

            Assert.AreEqual("Alabama", ret1);
        }
Esempio n. 4
0
        void StateNameCallbackNoState(IAsyncResult asr)
        {
            XmlRpcAsyncResult clientResult = (XmlRpcAsyncResult)asr;
            IStateName        proxy        = (IStateName)clientResult.ClientProtocol;

            try
            {
                _ret = proxy.EndGetStateName(asr);
            }
            catch (Exception ex)
            {
                _excep = ex;
            }
            _evt.Set();
        }
Esempio n. 5
0
        void StateNameCallback(IAsyncResult asr)
        {
            XmlRpcAsyncResult clientResult = (XmlRpcAsyncResult)asr;
            IStateName        proxy        = (IStateName)clientResult.ClientProtocol;
            CBInfo            info         = (CBInfo)asr.AsyncState;

            try
            {
                info._ret = proxy.EndGetStateName(asr);
            }
            catch (Exception ex)
            {
                info._excep = ex;
            }
            info._evt.Set();
        }
Esempio n. 6
0
        public void AsynchronousFaultException()
        {
            IStateName   proxy = (IStateName)XmlRpcProxyGen.Create(typeof(IStateName));
            IAsyncResult asr   = proxy.BeginGetStateName(100);

            asr.AsyncWaitHandle.WaitOne();
            try
            {
                string ret = proxy.EndGetStateName(asr);
                Assert.Fail("exception not thrown on async call");
            }
            catch (XmlRpcFaultException fex)
            {
                Assert.AreEqual(1, fex.FaultCode);
                Assert.AreEqual("Invalid state number", fex.FaultString);
            }
        }
Esempio n. 7
0
        static void GetStateNameCallback(IAsyncResult result)
        {
            XmlRpcAsyncResult clientResult = (XmlRpcAsyncResult)result;
            IStateName        betty        = (IStateName)clientResult.ClientProtocol;
            BettyAsyncState   asyncState   = (BettyAsyncState)result.AsyncState;

            try
            {
                string s = betty.EndGetStateName(result);
                asyncState.theForm.Invoke(new AppendSuccessDelegate(
                                              asyncState.theForm.AppendSuccess), asyncState.stateNumber, s);
            }
            catch (Exception ex)
            {
                asyncState.theForm.Invoke(new AppendExceptionDelegate(
                                              asyncState.theForm.AppendException), ex);
            }
        }
Esempio n. 8
0
        private void butGetName_Click(object sender, System.EventArgs e)
        {
            IStateName betty = XmlRpcProxyGen.Create <IStateName>();

            betty.Timeout = 10000;
            try
            {
                AsyncCallback   acb        = new AsyncCallback(GetStateNameCallback);
                int             num        = Convert.ToInt32(txtStateNumber.Text);
                BettyAsyncState asyncState = new BettyAsyncState(num, this);
                IAsyncResult    asr        = betty.BeginGetStateName(num, acb, asyncState);
                if (asr.CompletedSynchronously)
                {
                    string ret = betty.EndGetStateName(asr);
                    AppendSuccess(num, ret);
                }
            }
            catch (Exception ex)
            {
                AppendException(ex);
            }
        }