Example #1
0
 /// <summary>
 /// Constructor with parameters.
 /// </summary>
 /// <param name="proxySession">Sets session id in request way.</param>
 /// <param name="callbackSession">Sets session id in response way.</param>
 public SessionData(AES128_ECB aesAlgorithm, IClientContract proxy, string proxySession, string callbackSession)
 {
     AesAlgorithm      = aesAlgorithm;
     Proxy             = proxy;
     ProxySessionId    = proxySession;
     CallbackSessionId = callbackSession;
 }
Example #2
0
        /// <summary>
        /// 此测试用例的目的在于测试消息头的发送是否成功
        /// </summary>
        static void Main()
        {
            //初始化容器
            InitContainer();

            //伪造一个登录信息
            IAuthenticationContract authenticationContract = ResolveMediator.Resolve <IAuthenticationContract>();
            LoginInfo fakeLoginInfo = authenticationContract.Login(CommonConstants.AdminLoginId, CommonConstants.InitialPassword);

            //将登录信息存入约定位置
            AppDomain.CurrentDomain.SetData(SessionKey.CurrentUser, fakeLoginInfo);

            //实例化WCF客户端服务接口
            IClientContract clientContract = ResolveMediator.Resolve <IClientContract>();

            //调用服务获取消息头,
            string header = clientContract.GetHeader();

            //如果消息头内容即是上述伪造的公钥,即说明整个认证过程没问题
            if (fakeLoginInfo.PublicKey.ToString() == header)
            {
                Console.WriteLine("认证通过!");
            }

            ResolveMediator.Dispose();
            Console.ReadKey();
        }
Example #3
0
        /// <summary>
        /// Initializes a new WCF service session.
        /// </summary>
        public WCFServerService()
        {
            var endpoint = GetRemoteEndpoint();

            _client = OperationContext.Current.GetCallbackChannel <IClientContract>();
            ClientConnected?.Invoke(new Client
            {
                IpAddress      = endpoint?.Address,
                Port           = endpoint?.Port ?? 0,
                ClientContract = _client
            });
        }
Example #4
0
        public void Unsubscribe()
        {
            IClientContract callback = OperationContext.Current.GetCallbackChannel <IClientContract>();

            clientsCollection.ClientDisconnected(callback);
            try
            {
                ((ICommunicationObject)callback).Abort();
                ((ICommunicationObject)callback).Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        public CertificateDto SendCert(CertificateDto certDto)
        {
            if (!vaProxy.isCertificateValidate(certDto.GetCert(false)))
            {
                return(null);
            }
            IClientContract otherSide       = OperationContext.Current.GetCallbackChannel <IClientContract>();
            string          callbackSession = otherSide.GetSessionId();
            string          proxySession    = OperationContext.Current.SessionId;

            SessionData newSd = new SessionData(null, otherSide, callbackSession, proxySession);

            newSd.Address = string.Format("temp{0}", tempSessionNum++);
            clientSessions.Add(newSd.Address, newSd);

            return(new CertificateDto(myCertificate, false));
        }
Example #6
0
        public bool Subscribe(string machineName, Object sessionMessage)
        {
            try
            {
                //Get the hashCode of the connecting app and store it as a connection
                OperationContext  context = OperationContext.Current;
                MessageProperties prop    = context.IncomingMessageProperties;

                RemoteEndpointMessageProperty endpointProperty = prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

                IClientContract callback = context.GetCallbackChannel <IClientContract>();
                ((ICommunicationObject)callback).Faulted += new EventHandler(Proxy_FaultedEvent);
                if (clientsCollection.ClientConnected(callback, machineName, endpointProperty.Address + ":" + endpointProperty.Port, sessionMessage))
                {
                }
                else
                {
                    try
                    {
                        callback.ServerDisconnect();
                        ((ICommunicationObject)callback).Abort();
                        ((ICommunicationObject)callback).Close();
                    }
                    catch
                    {
                        Console.WriteLine();
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
        }
 public ClientController(IClientContract clientContract)
 {
     _clientContract = clientContract;
 }
Example #8
0
        private void Proxy_FaultedEvent(object sender, EventArgs args)
        {
            IClientContract callback = sender as IClientContract;

            clientsCollection.ClientDisconnected(callback);
        }
Example #9
0
 /// <summary>
 /// Constructor with parameters.
 /// </summary>
 /// <param name="aesAlgorithm">Sets AES algorithm.</param>
 /// <param name="proxy">Sets proxy.</param>
 public SessionData(AES128_ECB aesAlgorithm, IClientContract proxy)
 {
     AesAlgorithm = aesAlgorithm;
     Proxy        = proxy;
 }