Esempio n. 1
0
        /// <summary>send call request to remote and pending callback
        /// </summary>
        /// <param name="remoteUri"></param>
        /// <param name="operation"></param>
        /// <param name="transportHeaders"></param>
        /// <param name="call"></param>
        /// <param name="callback"></param>
        public void Call(Uri remoteUri
            , ushort operation
            , IDictionary<string, object> transportHeaders
            , MethodCall call
            , RemotingCallback callback)
        {
            var data = this._serializationFactory.Get(callback.SerializationFormat).SerializeMethodCall(call);
            var flag = Interlocked.Increment(ref this._flag);
            callback.Flag = flag;
            transportHeaders.Add(RemotingTransportHeader.Flag, flag);
            transportHeaders.Add(RemotingTransportHeader.Format, callback.SerializationFormat);

            var request = new MemoryStream();
            var handle = new RemotingTcpProtocolHandle(request);
            handle.WritePreamble();
            handle.WriteMajorVersion();
            handle.WriteMinorVersion();
            handle.WriteOperation(TcpOperations.Request);
            handle.WriteContentDelimiter(TcpContentDelimiter.ContentLength);
            handle.WriteContentLength(data.Length);
            handle.WriteTransportHeaders(transportHeaders);
            handle.WriteContent(data);

            this.GetChannel(remoteUri).Send(request.ToArray());
            this._callbacks.Add(flag, callback);

            if (this._log.IsDebugEnabled)
                this._log.DebugFormat("pending methodCall#{0}|{1}", flag, remoteUri);
        }
Esempio n. 2
0
        public void MethodCallTest()
        {
            MethodCall call1 = new MethodCall();
            call1.MethodName = "echo";
            call1.TypeName = "serviceType";
            call1.Uri = "uri";
            call1.Args = new Object[] {
                "abc中文",
                (byte) 1,
                (double) 1.1,
                (float) 1.2,
                1,
                1L,
                (short) 1,
                DateTime.Now,
                GetDictionary(),
                GetEntity(),
                new string[] { "abc" }
            };
            call1.MethodSignature = new Type[] {
                typeof(string),
                typeof(byte),
                typeof(double),
                typeof(float),
                typeof(int),
                typeof(long),
                typeof(short),
                typeof(DateTime),
                typeof(IDictionary<string,string>),
                typeof(Entity),
                typeof(string[])
            };

            byte[] ret = jsonSerializer.SerializeMethodCall(call1);
            Console.WriteLine(Encoding.UTF8.GetString(ret));

            MethodCall call2 = jsonSerializer.DeserializeMethodCall(ret);
            Assert.AreEqual(call1.MethodName, call2.MethodName);
            Assert.AreEqual(call1.TypeName, call2.TypeName);
            Assert.AreEqual(call1.Uri, call2.Uri);
            Assert.AreEqual(call1.Args.Length, call2.Args.Length);
            for (int i = 0; i < call1.Args.Length; i++)
            {
                Assert.AreEqual(call1.Args[i].GetType(), call2.Args[i].GetType());
                Assert.AreEqual(call1.MethodSignature[i], call2.MethodSignature[i]);
                Assert.AreEqual(call1.Args[i].ToString(), call2.Args[i].ToString());
            }
            foreach (object arg in call2.Args)
                Console.WriteLine(string.Format("{0}|{1}", arg.GetType(), arg));
        }
Esempio n. 3
0
 public byte[] SerializeMethodCall(MethodCall methodCall)
 {
     _c = methodCall;
     return new byte[0];
 }