Ejemplo n.º 1
0
        /// <summary>
        /// 截获从Client端发送的消息转发到目标终结点并获得返回值给Client端
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public Message ProcessMessage(Message requestMessage)
        {
            //Binding binding = null;
            EndpointAddress endpointAddress = null;

            GetServiceEndpoint(requestMessage, out endpointAddress);
            IDuplexRouterCallback callback = OperationContext.Current.GetCallbackChannel <IDuplexRouterCallback>();
            NetTcpBinding         tbinding = new NetTcpBinding("netTcpExpenseService_ForSupplier");

            using (DuplexChannelFactory <IRouterService> factory = new DuplexChannelFactory <IRouterService>(new InstanceContext(null, new DuplexRouterCallback(callback)), tbinding, endpointAddress))
            {
                factory.Endpoint.Behaviors.Add(new MustUnderstandBehavior(false));
                IRouterService proxy = factory.CreateChannel();

                using (proxy as IDisposable)
                {
                    // 请求消息记录
                    IClientChannel clientChannel = proxy as IClientChannel;
                    //Console.WriteLine(String.Format("Request received at {0}, to {1}\r\n\tAction: {2}", DateTime.Now, clientChannel.RemoteAddress.Uri.AbsoluteUri, requestMessage.Headers.Action));
                    if (WcfServerManage.IsDebug)
                    {
                        hostwcfMsg(DateTime.Now, String.Format("路由请求消息发送:  {0}", clientChannel.RemoteAddress.Uri.AbsoluteUri));
                    }
                    // 调用绑定的终结点的服务方法
                    Message responseMessage = proxy.ProcessMessage(requestMessage);

                    // 应答消息记录
                    //Console.WriteLine(String.Format("Reply received at {0}\r\n\tAction: {1}", DateTime.Now, responseMessage.Headers.Action));
                    //Console.WriteLine();
                    //hostwcfMsg(DateTime.Now, String.Format("应答消息: {0}", responseMessage.Headers.Action));
                    return(responseMessage);
                }
            }
        }
Ejemplo n.º 2
0
 public DuplexCallbackProxy(Guid activityID, IDuplexRouterCallback callbackInstance)
 {
     this.activityID       = activityID;
     this.callbackInstance = callbackInstance;
     if (Fx.Trace.IsEtwProviderEnabled)
     {
         this.eventTraceActivity = new EventTraceActivity(activityID);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 截获从Client端发送的消息转发到目标终结点并获得返回值给Client端
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public Message ProcessMessage(Message requestMessage)
        {
            try
            {
                begintime();
                IRouterService  proxy = null;
                HeaderParameter para  = HeaderOperater.GetHeaderValue(requestMessage);

                if (RouterServerManage.routerDic.ContainsKey(para.routerid))
                {
                    proxy = RouterServerManage.routerDic[para.routerid];
                    para.replyidentify = RouterServerManage.headParaDic[para.routerid].replyidentify;
                }
                else
                {
                    //Binding binding = null;
                    EndpointAddress endpointAddress = null;
                    Uri             touri           = null;
                    para = RouterServerManage.AddClient(requestMessage, para, out endpointAddress, out touri);
                    requestMessage.Headers.To = touri;

                    IDuplexRouterCallback callback = OperationContext.Current.GetCallbackChannel <IDuplexRouterCallback>();
                    NetTcpBinding         tbinding = new NetTcpBinding("NetTcpBinding_WCFHandlerService");
                    DuplexChannelFactory <IRouterService> factory = new DuplexChannelFactory <IRouterService>(new InstanceContext(new DuplexRouterCallback(callback)), tbinding, endpointAddress);
                    proxy = factory.CreateChannel();

                    //缓存会话
                    RouterServerManage.routerDic.Add(para.routerid, proxy);
                    RouterServerManage.headParaDic.Add(para.routerid, para);
                }

                Message responseMessage = null;
                HeaderOperater.AddMessageHeader(requestMessage, para);//增加自定义消息头
                responseMessage = proxy.ProcessMessage(requestMessage);

                if (para.cmd == "Quit")
                {
                    //关闭连接释放缓存会话
                    RouterServerManage.RemoveClient(para);
                }

                double outtime = endtime();
                // 请求消息记录
                if (WcfServerManage.IsDebug)
                {
                    RouterServerManage.hostwcfMsg(Color.Black, DateTime.Now, String.Format("路由请求消息发送(耗时[" + outtime + "]):  {0}", requestMessage.Headers.Action));
                }


                return(responseMessage);
            }
            catch (Exception e)
            {
                return(Message.CreateMessage(requestMessage.Version, FaultCode.CreateReceiverFaultCode("error", RouterServerManage.ns), e.Message, requestMessage.Headers.Action));
            }
        }
 public RoutingEndpointTrait(Type routerContract, ServiceEndpoint endpoint, OperationContext operationContext)
 {
     if (routerContract == typeof(IDuplexSessionRouter))
     {
         IDuplexRouterCallback callbackSession = operationContext.GetCallbackChannel <IDuplexRouterCallback>();
         this.CallbackInstance = callbackSession;
     }
     this.Endpoint       = endpoint;
     this.RouterContract = routerContract;
 }
Ejemplo n.º 5
0
                    public CallbackAsyncResult(IDuplexRouterCallback callbackInstance, Message message, AsyncCallback callback, object state)
                        : base(callback, state)
                    {
                        this.callbackInstance = callbackInstance;

                        IAsyncResult result;

                        using (this.PrepareTransactionalCall(TransactionMessageProperty.TryGetTransaction(message)))
                        {
                            result = this.callbackInstance.BeginProcessMessage(message,
                                                                               this.PrepareAsyncCompletion(processCallback), this);
                        }

                        if (this.SyncContinue(result))
                        {
                            this.Complete(true);
                        }
                    }
Ejemplo n.º 6
0
        public void ProcessMessage(Message requestMessage)
        {
            lock (this.m_duplexSessionLock)
            {
                if (this.m_duplexSession == null)
                {
                    IDuplexRouterCallback callback =
                        OperationContext.Current.GetCallbackChannel
                        <IDuplexRouterCallback>();

                    DuplexChannelFactory <IDuplexRouterService> factory =
                        new DuplexChannelFactory <IDuplexRouterService>
                            (new InstanceContext(null,
                                                 new DuplexRouterCallback(callback)), "serviceEndpoint");
                    factory.Endpoint.Behaviors.Add(new MustUnderstandBehavior(false));
                    this.m_duplexSession = factory.CreateChannel();
                }
            }

            this.m_duplexSession.ProcessMessage(requestMessage);
        }
 public DuplexRouterCallback(IDuplexRouterCallback clientCallback)
 {
     m_clientCallback = clientCallback;
 }
Ejemplo n.º 8
0
 public DuplexRouterCallback(IDuplexRouterCallback clientCallback)
 {
     m_clientCallback = clientCallback;
 }