Exemplo n.º 1
0
        public static void testMath()
        {
            CHessianProxyFactory factory = new CHessianProxyFactory();

            //String url = "http://localhost:9090/resin-doc/protocols/tutorial/hessian-service/hessian/math";
            //String url = "http://localhost:2180/csharphessian/math";
            String url = "http://localhost/MathService/test2.hessian";

            try {
                IMathService math;
                math = (IMathService)factory.Create(typeof(IMathService), url);
                Console.WriteLine(math.add(3, 5));

                Console.WriteLine("3 + 5 = {0}", math.add(3, 5));
                Console.WriteLine("9 - 5 = {0}", math.sub(9, 5));
                Console.WriteLine("9 / 3 = {0}", math.div(9, 3));
                Console.WriteLine("9 * 3 = {0}", math.mul(9, 3));

                Console.WriteLine(math.testString("Hallo"));
                int[] ar = { 2, 3, 5 };
                Console.WriteLine(math.addArray(ar));


                for (int i = 0; i < 30; i++)
                {
                    Console.WriteLine(i + " FOR" + i + "* 3 = " + math.mul(i, 3));
                }

                Console.ReadLine();
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Console.ReadLine();
            }
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            CHessianProxyFactory factory = new CHessianProxyFactory();
            String url = "http://localhost/HessianTest/test.hessian";



            IHessianTest test = (IHessianTest)factory.Create(typeof(IHessianTest), url);

            Console.WriteLine("Started");
            MainStart.testSession(test);

            /*
             * DateTime d1 = System.DateTime.Now;
             * for(int i = 0; i < 1; i++)
             * {
             *  MainStart.testWithConsole(test);
             *  Console.WriteLine(i);
             * }
             * TimeSpan time = System.DateTime.Now - d1;
             *
             * Console.WriteLine("Time to execute: " + time);
             *  */
            Console.ReadLine();
        }
        public HessianConnection()
        {
            CHessianProxyFactory factory = new CHessianProxyFactory();
            Type testConnType            = typeof(ITestConnectionController);

            _tester = (ITestConnectionController)factory.Create(testConnType, InitUrlOfService(testConnType));
        }
Exemplo n.º 4
0
        public PHINVADSDeviceSession(PHINVADSDevice device, ServerProcess serverProcess, Schema.DeviceSessionInfo deviceSessionInfo) : base(device, serverProcess, deviceSessionInfo)
        {
            // Initialize the PHINVADS Client
            _factory = new CHessianProxyFactory();
            _client  = (VocabService)_factory.Create(typeof(VocabService), device.Endpoint);

            // TODO: Establish authentication/authorization tokens?
        }
        public void CreateTest()
        {
            CHessianProxyFactory target = new CHessianProxyFactory();
            Type        type            = typeof(IServiceAPI);
            String      url             = ApiUrl;
            object      actual          = null;
            IServiceAPI test            = (IServiceAPI)target.Create(type, url);

            actual = test.registerAccount("Tim" + DateTime.Now.ToString());

            Assert.IsInstanceOfType(actual, typeof(Response));
        }
Exemplo n.º 6
0
        public void DoHessianMethodCallTest()
        {
            CHessianProxyFactory hessianProxyFactory = null;                                  // TODO: Initialize to an appropriate value
            Uri uri = null;                                                                   // TODO: Initialize to an appropriate value
            CHessianMethodCaller target = new CHessianMethodCaller(hessianProxyFactory, uri); // TODO: Initialize to an appropriate value

            object[]   arrMethodArgs = null;                                                  // TODO: Initialize to an appropriate value
            MethodInfo methodInfo    = null;                                                  // TODO: Initialize to an appropriate value
            object     expected      = null;                                                  // TODO: Initialize to an appropriate value
            object     actual;

            actual = target.DoHessianMethodCall(arrMethodArgs, methodInfo);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            CHessianProxyFactory factory = new   CHessianProxyFactory("dimi", "dimi");
            String       url             = "http://localhost:5667/test/hessiantest.hessian";
            IHessianTest test            = (IHessianTest)factory.Create(typeof(IHessianTest), url);
            DateTime     d1 = System.DateTime.Now;

            for (int i = 0; i < 2; i++)
            {
                //ClientMain.test(test);
                ClientMain.testWithConsole(test);
                Console.WriteLine(i);
            }
            TimeSpan time = System.DateTime.Now - d1;

            Console.WriteLine("Time to execute: " + time);
            Console.ReadLine();
        }
Exemplo n.º 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Stopwatch st = new Stopwatch();
                st.Start();
                CHessianProxyFactory factory = new CHessianProxyFactory();
                //factory.IsHessian2Request = false;
                //factory.IsHessian2Reply = false;
                factory.BaseAddress = new Uri("http://localhost.fiddler:2010/");
                var service = factory.Create <IService>();
                var result  = service.Test2();
                richTextBox1.Text = $"数据类型:{result.ToString()}";

                var type = result.GetType();
                if (type.IsGenericType || type.IsArray || result is DataTable)
                {
                    dataGridView1.DataSource = result;
                    richTextBox1.Text       += $",行数:{dataGridView1.Rows.Count},列数:{dataGridView1.ColumnCount}";
                }

                st.Stop();
                var elapsed = st.ElapsedMilliseconds;
                richTextBox1.Text += $",总消耗时间:{elapsed}毫秒";



                //var fs = File.Create(@"bin.bin");
                //BinaryWriter bw = new BinaryWriter(fs);
                //foreach (DataRow dr in result.Rows)
                //{
                //    foreach (object obj in dr.ItemArray)
                //    {
                //        var bytes = BitConverter.GetBytes((int)obj);
                //        bw.Write(bytes);
                //    }
                //}
                //bw.Close();
            }
            catch (Exception ex)
            {
                richTextBox1.Text = ex.ToString();
            }
        }
Exemplo n.º 9
0
        private static bool HeartBeat(string endPointAddress)
        {
            // WangBo said he will create a heartbeat later. temporarily, we can use login.
            string heartBeatMethod = "heartBeat";

            // Prepare service proxy intance
            // If the service proxy doesn't registed. Create service proxy instance and call.
            var serviceType = typeof(IRailSecurityInboundFacade);

            string requestUri = endPointAddress +
                                "/tos.rail.webservices.gateway/hessian/tos.rail.inbound.facade.RailSecurityInboundFacade";

            var factory = new CHessianProxyFactory()
            {
                IsOverloadEnabled = true
            };
            object serviceInstance = factory.Create(serviceType, requestUri);

            try
            {
                var mi = serviceType.GetMethod(heartBeatMethod);

                if (mi != null)
                {
                    mi.Invoke(serviceInstance, new object[] { });
                    return(true);
                }
            }
            catch (TargetInvocationException ex)
            {
                if (ex.InnerException.Message.Contains("(401)"))
                {
                    return(true);
                }

                return(false);
            }

            return(false);
        }
Exemplo n.º 10
0
        public static void TestHessainCompact()
        {
            CHessianProxyFactory factory = new CHessianProxyFactory();
            //String url = "http://192.168.0.1:9090/resin-doc/protocols/tutorial/hessian-add/hessian/hessianDotNetTest";
            String url = "http://192.168.1.11:9090/resin-doc/protocols/csharphessian/hessian/hessianDotNetTest";
            CHessianMethodCaller methodCaller = new CHessianMethodCaller(factory, new Uri(url));

            try
            {
                MethodInfo mInfo_1 = typeof(IHessianTest).GetMethod("testConcatString");
                object     result  = methodCaller.DoHessianMethodCall(new object[] { "Hallo ", "Welt" }, mInfo_1);
                Console.WriteLine("Return value of method \"testConcatString\":");
                Console.WriteLine(result);
                MethodInfo            mInfo_2    = typeof(IHessianTest).GetMethod("testHashMap");
                string []             keys       = new string[] { "Bauarbeiter", "Jo!" };
                string []             values     = new string[] { "Koennen wir das schaffen?", "Wir schaffen das!" };
                Hashtable             hashResult = (Hashtable)methodCaller.DoHessianMethodCall(new object[] { keys, values }, mInfo_2);
                IDictionaryEnumerator dict       = hashResult.GetEnumerator();
                Console.WriteLine("Return value of method \"testHashMap\":");
                while (dict.MoveNext())
                {
                    Console.WriteLine(dict.Key.ToString() + " " + dict.Value.ToString());
                }
                ParamObject pobject = (ParamObject)Activator.CreateInstance(typeof(ParamObject));
                pobject.setStringVar("Bauarbeiter, koennen wir das schaffen?");
                Hashtable hashTab = new Hashtable();
                hashTab.Add("Jo", " Wir schaffen das!");
                MethodInfo  mInfo_3    = typeof(IHessianTest).GetMethod("testParamObject");
                ParamObject pObjResult = (ParamObject)methodCaller.DoHessianMethodCall(new object[] { pobject }, mInfo_3);
                Console.WriteLine("Return value of method \"testParamObject\":");
                Console.WriteLine(pObjResult.getStringVar());
                Console.WriteLine(pObjResult.getHashVar()["Message"].ToString());
            } catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }
Exemplo n.º 11
0
        public static void testHessian()
        {
            CHessianProxyFactory factory = new CHessianProxyFactory();

            //String url = "http://localhost:9090/resin-doc/protocols/tutorial/hessian-add/hessian/hessianDotNetTest";
            String url = "http://localhost:9090/resin-doc/protocols/csharphessian/hessian/hessianDotNetTest";

            //String url = "http://localhost/MathService/test.hessian";
            //String url = "http://localhost/MathService/MyHandler.hessian";

            url = "http://localhost:8080/hessiantest/hessian/hessianDotNetTest";
            try
            {
                /*
                 *
                 #region TEST_INPUTSTREAM
                 *              WebRequest webRequest =  WebRequest.Create(new Uri(url));
                 *              webRequest.ContentType = "text/xml";
                 *              webRequest.Method = "POST";
                 *              MemoryStream memoryStream = new MemoryStream();
                 *              CHessianOutput cHessianOutput = new CHessianOutput(memoryStream);
                 *
                 *              cHessianOutput.StartCall("download");
                 *              cHessianOutput.WriteString("C:/resin-3.0.8/webapps/resin-doc/protocols/csharphessian/WEB-INF/classes/HessianTest.java");
                 *              cHessianOutput.CompleteCall();
                 *              Stream sInStream = null;
                 *              Stream sOutStream = null;
                 *
                 *              try
                 *              {
                 *                      webRequest.ContentLength = memoryStream.ToArray().Length;
                 *                      sOutStream = webRequest.GetRequestStream();
                 *                      memoryStream.WriteTo(sOutStream);
                 *
                 *                      sOutStream.Flush();
                 *                      HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
                 *                      sInStream = webResponse.GetResponseStream();
                 *                      CHessianInput hessianInput = new CHessianInput(sInStream);
                 *                      hessianInput.StartReply();
                 *                      Stream is2 = hessianInput.ReadInputStream();
                 *                      FileStream fo = new FileStream("hallo_test.txt",FileMode.Create);
                 *                      int b;
                 *                      while((b = is2.ReadByte())!= -1)
                 *                      {
                 *                              fo.WriteByte((byte)b);
                 *                      }
                 *
                 *                      hessianInput.CompleteReply();
                 *                      fo.Close();
                 *                      is2.Close();
                 *                      Console.WriteLine("Datei erfolgreich übertragen: hallo.txt");
                 *
                 *              }
                 *              catch (Exception e)
                 *              {
                 *                      Console.WriteLine("Fehler "+ e.StackTrace);
                 *              }
                 *              finally
                 *              {
                 *                      if (sInStream != null)
                 *                      {
                 *                              sInStream.Close();
                 *                      }
                 *                      if (sOutStream != null)
                 *                      {
                 *                              sOutStream.Close();
                 *                      }
                 *              }
                 #endregion
                 */


                IHessianTest test = (IHessianTest)factory.Create(typeof(IHessianTest), url);

                /*
                 * char shouldChar = new char();
                 * shouldChar = 'R';
                 * Console.WriteLine("ShouldChar"+shouldChar);
                 *
                 * String recievedString = test.testCharToString(shouldChar);
                 *
                 * Console.WriteLine("ReceivedChar: " + recievedString);
                 *
                 */

                //Console.WriteLine("ReceivedChar2: " + test.testChar('P'));
                //Tut nicht



                DateTime dt         = DateTime.Today;
                string   dtASString = test.testDateToString(dt);
                Console.WriteLine(dtASString);
                DateTime dt2 = test.testStringToDate("10.12.2004");
                Console.WriteLine(dt2.ToString());


                Console.WriteLine(test.testConcatString("Hallo ", "Welt"));
                Console.WriteLine(test.testDoubleToString(1.2));
                Console.WriteLine(test.testStringToDouble("4.5"));
                Console.WriteLine(test.testStringToLong("-45675467"));
                Console.WriteLine(test.testStringToShort("5467"));
                Console.WriteLine(test.testFloatToString((float)1.4));
                Console.WriteLine(test.testStringToFloat("1.89"));
                Console.WriteLine(test.testBoolToString(true));
                Console.WriteLine(test.testStringToBoolean("false"));
                Console.WriteLine(test.testStringToByte("7"));
                Console.WriteLine(test.testByteToString(5));



                //Integer Array Test:
                int[]    intArr    = { 23, 467 };
                string[] stringArr = test.testIntArrToString(intArr);
                for (int i = 0; i < stringArr.Length; i++)
                {
                    Console.WriteLine(stringArr[i]);
                }

                string[] stringArr2 = { "788", "343" };
                int[]    intArr2    = test.testStringArrToInt(stringArr2);
                for (int i = 0; i < intArr2.Length; i++)
                {
                    Console.WriteLine(intArr2[i]);
                }

                //Double Arrray Test:
                double[] doubleArr = { 23.467, 78.3 };
                stringArr = test.testDoubleArrToString(doubleArr);
                for (int i = 0; i < stringArr.Length; i++)
                {
                    Console.WriteLine(stringArr[i]);
                }

                string[] stringArrDouble = { "788.56", "343.678" };
                double[] doubleArr2      = test.testStringArrToDouble(stringArrDouble);
                for (int i = 0; i < doubleArr2.Length; i++)
                {
                    Console.WriteLine(doubleArr2[i]);
                }

                //Float Arrray Test:
                float[] floatArr = { (float)22.47, (float)3.3 };
                stringArr = test.testFloatArrToString(floatArr);
                for (int i = 0; i < stringArr.Length; i++)
                {
                    Console.WriteLine(stringArr[i]);
                }

                string[] stringArrFloat = { "88.56", "4.678" };
                float[]  floatArr2      = test.testStringArrToFloat(stringArrFloat);
                for (int i = 0; i < floatArr2.Length; i++)
                {
                    Console.WriteLine(floatArr2[i]);
                }

                //Short Arrray Test:
                short[] shortArr = { 56, 3 };
                stringArr = test.testShortArrToString(shortArr);
                for (int i = 0; i < stringArr.Length; i++)
                {
                    Console.WriteLine(stringArr[i]);
                }

                string[] stringArrShort = { "7", "38" };
                short[]  shortArr2      = test.testStringArrToShort(stringArrShort);
                for (int i = 0; i < shortArr2.Length; i++)
                {
                    Console.WriteLine(shortArr2[i]);
                }

                //Char Arrray Test:
                char[] charArr = { 'c', 'd' };
                stringArr = test.testCharArrToString(charArr);
                for (int i = 0; i < stringArr.Length; i++)
                {
                    Console.WriteLine(stringArr[i]);
                }

                string[] stringArrChar = { "l", "w" };
                char[]   charArr2      = test.testStringArrToChar(stringArrChar);
                for (int i = 0; i < charArr2.Length; i++)
                {
                    Console.WriteLine(charArr2[i]);
                }

                //Long Arrray Test:
                long[] longArr = { 56323, 3232323 };
                stringArr = test.testLongArrToString(longArr);
                for (int i = 0; i < stringArr.Length; i++)
                {
                    Console.WriteLine(stringArr[i]);
                }

                string[] stringArrLong = { "111117", "2222238" };
                long[]   longArr2      = test.testStringArrToLong(stringArrLong);
                for (int i = 0; i < longArr2.Length; i++)
                {
                    Console.WriteLine(longArr2[i]);
                }

                //Byte Arrray Test:
                byte[] byteArr = { 5, 3 };
                stringArr = test.testByteArrToString(byteArr);
                for (int i = 0; i < stringArr.Length; i++)
                {
                    Console.WriteLine(stringArr[i]);
                }

                string[] stringArrByte = { "7", "3" };
                byte[]   byteArr2      = test.testStringArrToByte(stringArrByte);
                for (int i = 0; i < byteArr2.Length; i++)
                {
                    Console.WriteLine(byteArr2[i]);
                }

                //Bool Arrray Test:
                bool[] boolArr = { true, false };
                stringArr = test.testBoolArrToString(boolArr);
                for (int i = 0; i < stringArr.Length; i++)
                {
                    Console.WriteLine(stringArr[i]);
                }

                string[] stringArrBool = { "true", "false" };
                bool[]   boolArr2      = test.testStringArrToBool(stringArrBool);
                for (int i = 0; i < boolArr2.Length; i++)
                {
                    Console.WriteLine(boolArr2[i]);
                }

                Console.WriteLine("Test the hashtable return value");
                System.Collections.Hashtable             testHash = test.testHashMap(new string[] { "Hallo" }, new string [] { "Welt" });
                System.Collections.IDictionaryEnumerator enumer   = testHash.GetEnumerator();
                while (enumer.MoveNext())
                {
                    Console.WriteLine(enumer.Key.ToString() + " " + enumer.Value.ToString());
                }
                Console.WriteLine("Test the hashtable param");
                Console.WriteLine(test.testHashMapParam(testHash));



                ArrayList arrList = test.testArrayList(new string[] { "Hallo", " Dimi" });
                Console.WriteLine(test.testArrayListParam(arrList));


                Console.WriteLine("Test Object");

                ParamObject testPObject = new ParamObject();
                testPObject.setStringVar("Test Test");


                Console.WriteLine(test.testSendParamObject(testPObject));
                Console.WriteLine(test.testReceiveParamObject("REUTLINGEN").getStringVar());



                ParamObject testPObject2 = test.testParamObject(testPObject);

                Console.WriteLine(testPObject2.getStringVar());

                Hashtable h = testPObject2.getHashVar();

                Console.WriteLine(testPObject2.getHashVar()["Message"].ToString());



                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Console.ReadLine();
            }
        }
Exemplo n.º 12
0
        private static object GetProxyImpl(Type serviceType, string requestUri)
        {
            CHessianProxyFactory factory = ApplicationManager.Instance.GetService <CHessianProxyFactory>();

            return(factory.Create(serviceType, requestUri));
        }
Exemplo n.º 13
0
 public HessianConnection(string url)
 {
     factory  = new CHessianProxyFactory();
     this.url = url;
 }
Exemplo n.º 14
0
 public void Logon(string login, string password)
 {
     _factory = new CHessianProxyFactory(login, password);
 }
Exemplo n.º 15
0
 protected CHessianStore()
 {
     _factory = new CHessianProxyFactory();
 }