Beispiel #1
0
		/// <summary>
		/// 使用指定的配置文件名称、配置文件物理路径初始化 <see cref="ClientConnectEventArgs"/> 类的新实例。
		/// </summary>
		/// <param name="callbackState">事件相关的回调状态数据。</param>
		internal DataReceivedEventArgs(CallbackState callbackState)
		{
			if (callbackState == null)
			{
				throw new ArgumentNullException();
			}

			this.callbackState = callbackState;
		}
		/// <summary>
		/// 在处理接收数据的事件中,调用此方法以通知调用方请求执行成功,该返回值应该是可序列化的。
		/// </summary>
		internal void Reply(object value, CallbackState state)
		{
			state.InvokeStacks.Add(new KeyValue<DateTime, string>() { Key = DateTime.Now, Value = "Reply" });

			try
			{
				BinarySerializeHelper.Write(formatter, state.Channel.pipeStream, ReturnValue<object>.Get200OK(value), true, state.Channel.sendTimeout);
			}
			catch (Exception err)
			{
				state.InvokeStacks.Add(new KeyValue<DateTime, string>() { Key = DateTime.Now, Value = "Reply-Error:" + err.GetType().FullName });

				throw new ReplyException(err);
			}
			finally
			{
				state.InvokeStacks.Add(new KeyValue<DateTime, string>() { Key = DateTime.Now, Value = "Reply-End-BeginReceive" });

				// 应答后使通道重新进入读取状态,以读取客户端的新请求
				BinarySerializeHelper.BeginReceive(state.Channel, HandleReceivedData);
			}
		}
		public static void BeginReceive(PipeServiceClientChannel channel, SendOrPostCallback callback)
		{
			CallbackState state = new CallbackState(channel, callback);

			state.InvokeStacks.Add(new KeyValue<DateTime, string>()
			{
				Key = DateTime.Now,
				Value = Thread.CurrentThread.ManagedThreadId.ToString("#000") + " " + (Thread.CurrentThread.IsThreadPoolThread ? "true" : "false") + " BeginRead: ChannelsCount=" + channel.Client.Channels.Length
			});

			channel.pipeStream.BeginRead(state.LengthBuffer, 0, state.LengthBuffer.Length, new AsyncCallback(ReadCallback), state);
		}