Beispiel #1
0
 private void btnketnoi_Click(object sender, EventArgs e)
 {
     try
     {
         if (rdbasic.Checked == true)
         {
             address = new EndpointAddress(new Uri("http://localhost:8888/BasicHttpBinding"));
             factory = new ChannelFactory<IService1>(new System.ServiceModel.BasicHttpBinding(), address);
             service = factory.CreateChannel();
             checkConnect = service.checkServer();
         }
         else if (rdws.Checked == true)
         {
             address = new EndpointAddress(new Uri("http://localhost:8888/WSHttpBinding"));
             factory = new ChannelFactory<IService1>(new WSHttpBinding(), address);
             service = factory.CreateChannel();
             checkConnect = service.checkServer();
         }
         else if (rdnet.Checked == true)
         {
             address = new EndpointAddress(new Uri("net.tcp://localhost:8888/NetTcpBinding"));
             factory = new ChannelFactory<IService1>(new NetTcpBinding(), address);
             service = factory.CreateChannel();
             checkConnect = service.checkServer();
         }
         if(checkConnect = service.checkServer())
         {
             txttinhtrang.Text = "Đã kết nối với Server!";
             btnngatkn.Focus();
             grbkieukn.Enabled = false;
             btnketnoi.Enabled = false;
             btnngatkn.Enabled = true;
         }
     }
     catch (Exception ex)
     {
         txttinhtrang.Text = "Lỗi kết nối!";
     }
 }