/// <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); }
protected override void OnMessage(object sender, MessageEventArgs e) { var protocol = new RemotingTcpProtocolHandle(new MemoryStream(e.RawData)); protocol.ReadPreamble(); protocol.ReadMajorVersion(); protocol.ReadMinorVersion(); ushort operation = protocol.ReadOperation(); protocol.ReadContentDelimiter(); protocol.ReadContentLength(); IDictionary<string, Object> transportHeaders = protocol.ReadTransportHeaders(); var flag = (int)transportHeaders[RemotingTransportHeader.Flag]; ISerializer serializer = serializationFactory.Get(null); transportHeaders.Clear(); transportHeaders.Add(RemotingTransportHeader.Flag, flag); MethodCall methodCall = serializer.DeserializeMethodCall(protocol.ReadContent()); var methodReturn = new MethodReturn() { ReturnValue = methodCall.Args[0] }; byte[] data = serializer.SerializeMethodReturn(methodReturn); var response = new MemoryStream(); var handle = new RemotingTcpProtocolHandle(response); handle.WritePreamble(); handle.WriteMajorVersion(); handle.WriteMinorVersion(); handle.WriteOperation(TcpOperations.Reply); handle.WriteContentDelimiter(TcpContentDelimiter.ContentLength); handle.WriteContentLength(data.Length); handle.WriteTransportHeaders(transportHeaders); handle.WriteContent(data); this.Send(response.ToArray()); }