/// <summary> /// 此测试用例的目的在于测试消息头的发送是否成功 /// </summary> protected void Page_Load(object sender, EventArgs e) { //初始化容器 InitContainer(); //伪造一个登录信息 IAuthenticationContract authenticationContract = ResolveMediator.Resolve <IAuthenticationContract>(); LoginInfo fakeLoginInfo = authenticationContract.Login(CommonConstants.AdminLoginId, CommonConstants.InitialPassword); //将登录信息存入约定位置 base.Session.Add(SessionKey.CurrentUser, fakeLoginInfo); //实例化WCF服务端服务接口 IServerContract serverContract = ResolveMediator.Resolve <IServerContract>(); //调用服务获取消息头 string header = serverContract.GetHeader(); //如果消息头内容即是上述伪造的公钥,即说明整个认证过程没问题 if (fakeLoginInfo.PublicKey.ToString() == header) { base.Response.Write("认证通过!"); } ResolveMediator.Dispose(); }
public void Open(string endpointAddress) { try { Log.Debug("Установка подключения"); DuplexChannelFactory <IServerContract> clientChannelFactory; NetTcpBinding binding = new NetTcpBinding() { MaxReceivedMessageSize = 1048576, MaxBufferPoolSize = 1048576, MaxBufferSize = 1048576, Security = new NetTcpSecurity { Mode = SecurityMode.None } }; EndpointAddress endpoint = new EndpointAddress(endpointAddress); clientChannelFactory = new DuplexChannelFactory <IServerContract>(instanceContext, binding, endpoint); server = clientChannelFactory.CreateChannel(); } catch (Exception e) { ShowError("Проблемы при подключении к серверу.", true, true); Log.Error(e); } }
private Boolean TryConnect() { lock (locker) { proxy = (new DuplexChannelFactory <IServerContract>(context, binding, adress)).CreateChannel(); ((ICommunicationObject)proxy).Opened += new EventHandler( delegate { EOpened(); }); ((ICommunicationObject)proxy).Faulted += (sender, args) => Proxy_Faulted(sender, args); ((ICommunicationObject)proxy).Faulted += new EventHandler( delegate { EFaulted(); }); try { proxy.Subscribe( Environment.MachineName, _sessionHandler.IsActiveSession ? _sessionHandler.SessionMessage : null); unrespondedTime = 0; workTimer.Start(); return(true); } catch (CommunicationException ce) { WriteErrorLog("TryConnect()", "Ping Exception: " + ce.Message); return(false); } } }
private void Run() { while (!this._isDisposed && this._resetEvent.WaitOne()) { try { if (this._isDisposed) { return; } if (this._channel == null) { if ((this._channel = this.InitializeChannel()) == null) { this.OnConnectionStatusChanged(); continue; } this._channel.RegisterClient(); this.OnConnectionStatusChanged(); } while (!this._isDisposed && this._channel != null && ((ICommunicationObject)this._channel).State == CommunicationState.Opened) { IRequest request; if (!this._requests.TryDequeue(out request) || !request.Run(this._channel)) { break; } } } catch (CommunicationException e) { Debug.WriteLine(e); } } }
/// <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); //实例化服务接口 IServerContract serverContract = ResolveMediator.Resolve <IServerContract>(); //调用服务获取消息头 string header = serverContract.GetHeader(); //如果消息头内容即是上述伪造的公钥,即说明整个认证过程没问题 if (fakeLoginInfo.PublicKey.ToString() == header) { Console.WriteLine("认证通过!"); } ResolveMediator.Dispose(); Console.ReadKey(); }
public void Setup() { _mockCallback = new Mock<IClientCallback>(); _mockCallback.Setup(x => x.SendData(It.IsAny<string>())); _mockOperationContext = new Mock<IOperationContextWrapper>(); _mockOperationContext.Setup(x => x.GetCallback()) .Returns(_mockCallback.Object); _srv = new ServerContract(_mockOperationContext.Object); }
public bool Run(IServerContract channel) { try { this._taskCompletionSource.TrySetResult(this._function(channel)); return(true); } catch (Exception e) { this._taskCompletionSource.TrySetException(e); return(false); } }
public void Main1() { Uri tcpUri = new Uri("http://localhost:1050/TestService"); EndpointAddress address = new EndpointAddress(tcpUri); BasicHttpBinding binding = new BasicHttpBinding(); ChannelFactory <IServerContract> factory = new ChannelFactory <IServerContract>(binding, address); IServerContract service = factory.CreateChannel(); for (int i = 0; i < iter_num; i++) { service.Get(diff); } //List<int> a3 = service.Get(diff); foreach (int b in a3) Console.Write(b + " "); }
/// <summary> /// Create a connection to a musicplayer server. /// </summary> /// <param name="player">The musicplayer.</param> /// <param name="address">The server ip address.</param> /// <param name="port">The server port.</param> public ClientConnection(IMusicPlayer player, IPAddress address, int port) : base(player) { _client = new WCFServerClient(this); string serviceAddress = $"net.tcp://{address.ToString()}:{port}/"; NetTcpContextBinding binding = new NetTcpContextBinding(SecurityMode.None); binding.CloseTimeout = new TimeSpan(0, 1, 0); binding.ReceiveTimeout = new TimeSpan(1, 0, 0); binding.SendTimeout = new TimeSpan(0, 1, 0); binding.MaxReceivedMessageSize = 100000000; // 100Mb _factory = new DuplexChannelFactory <IServerContract>(new InstanceContext(_client), binding, serviceAddress); _server = _factory.CreateChannel(); _server.Anounce(); }
private void ConfigureConnection() { try { var cf = new DuplexChannelFactory<IServerContract>( new ClientCallback(this.lstOutput), new NetTcpBinding(SecurityMode.None), new EndpointAddress(_ENDPOINT)); _server = cf.CreateChannel(); } catch (Exception err) { lstOutput.Items.Add(err.Message); } }
public void Main1() { Uri tcpUri = new Uri("http://localhost:1050/TestService"); EndpointAddress address = new EndpointAddress(tcpUri); BasicHttpBinding binding = new BasicHttpBinding(); ChannelFactory <IServerContract> factory = new ChannelFactory <IServerContract>(binding, address); IServerContract service = factory.CreateChannel(); for (int i = 0; i < iter_num; i++) { service.Get(diff); service.Want_Me(); } Console.WriteLine("Количесвто увиденных запросов сервером: " + service.Client_Num()); //List<int> a3 = service.Get(diff); foreach (int b in a3) Console.Write(b + " "); }
private IServerContract InitializeChannel() { IServerContract channel = this._factory.CreateChannel(); ICommunicationObject communicationObject = (ICommunicationObject)channel; try { communicationObject.Open(); } catch { ServiceModelMethods.TryClose(channel); return(null); } communicationObject.Closed += this.Channel_ClosedOrFaulted; communicationObject.Faulted += this.Channel_ClosedOrFaulted; return(channel); }
private void AbortProxy(Boolean toDoReconnect) { if (proxy != null) { ((ICommunicationObject)proxy).Abort(); ((ICommunicationObject)proxy).Close(); proxy = null; } if (toDoReconnect) { ToReconnect(); } else { if (reconnectThread != null) { reconnectThread.Abort(); } } }
public void CreateProduct(string productNo, string productName, IEnumerable <PriceParam> priceParams) { Trace.WriteLine(productNo); Trace.WriteLine(productName); Trace.WriteLine(priceParams); //伪造一个登录信息 IAuthenticationContract authenticationContract = ResolveMediator.Resolve <IAuthenticationContract>(); LoginInfo fakeLoginInfo = authenticationContract.Login(CommonConstants.AdminLoginId, CommonConstants.InitialPassword); //实例化服务接口 IServerContract serverContract = ResolveMediator.Resolve <IServerContract>(); //调用服务获取消息头 string header = serverContract.GetHeader(); //如果消息头内容即是上述伪造的公钥,即说明整个认证过程没问题 if (fakeLoginInfo.PublicKey.ToString() == header) { Console.WriteLine("认证通过!"); } }
public string GetProducts(string keywords, int pageIndex, int pageSize) { Trace.WriteLine(keywords); Trace.WriteLine(pageIndex); Trace.WriteLine(pageSize); //伪造一个登录信息 IAuthenticationContract authenticationContract = ResolveMediator.Resolve <IAuthenticationContract>(); LoginInfo fakeLoginInfo = authenticationContract.Login(CommonConstants.AdminLoginId, CommonConstants.InitialPassword); //实例化服务接口 IServerContract serverContract = ResolveMediator.Resolve <IServerContract>(); //调用服务获取消息头 string header = serverContract.GetHeader(); //如果消息头内容即是上述伪造的公钥,即说明整个认证过程没问题 if (fakeLoginInfo.PublicKey.ToString() == header) { Console.WriteLine("认证通过!"); } return("Hello World"); }
public IEnumerable <Order> GetOrders(string keywords, int pageIndex, int pageSize) { Trace.WriteLine(keywords); Trace.WriteLine(pageIndex); Trace.WriteLine(pageSize); //伪造一个登录信息 IAuthenticationContract authenticationContract = ResolveMediator.Resolve <IAuthenticationContract>(); LoginInfo fakeLoginInfo = authenticationContract.Login(CommonConstants.AdminLoginId, CommonConstants.InitialPassword); //实例化服务接口 IServerContract serverContract = ResolveMediator.Resolve <IServerContract>(); //调用服务获取消息头 string header = serverContract.GetHeader(); //如果消息头内容即是上述伪造的公钥,即说明整个认证过程没问题 if (fakeLoginInfo.PublicKey.ToString() == header) { Console.WriteLine("认证通过!"); } IList <Order> orders = new List <Order> { new Order { Number = "001", Name = "单据1", Details = new List <OrderDetail> { new OrderDetail { Number = "明细1", Description = "明细1" }, new OrderDetail { Number = "明细2", Description = "明细2" } } }, new Order { Number = "002", Name = "单据2", Details = new List <OrderDetail> { new OrderDetail { Number = "明细1", Description = "明细1" }, new OrderDetail { Number = "明细2", Description = "明细2" }, } } }; return(orders); }
public Application(IServerContract instance, Binding binding) { this._instance = instance; this._binding = binding; }
public ClientContract(IServerContract serverContract) { this._serverContract = serverContract; }