예제 #1
0
 private void btnketnoi_Click(object sender, EventArgs e)
 {
     try
     {
         if (cbbkieukn.SelectedIndex == 0)
         {
             EndpointAddress address = new EndpointAddress(new Uri("http://localhost:8888/BasicHttpBinding/Test1"));
             ChannelFactory<IService1> factory = new ChannelFactory<IService1>(new BasicHttpBinding(), address);
             service = factory.CreateChannel();
             rtxtthongtin.Text = service.GetAuthors();
         }
         if (cbbkieukn.SelectedIndex == 1)
         {
             EndpointAddress address = new EndpointAddress(new Uri("http://localhost:8888/WSHttpBinding/Test2"));
             ChannelFactory<IService1> factory = new ChannelFactory<IService1>(new WSHttpBinding(), address);
             service = factory.CreateChannel();
             rtxtthongtin.Text = service.GetAuthors();
         }
         if (cbbkieukn.SelectedIndex == 2)
         {
             EndpointAddress address = new EndpointAddress(new Uri("net.tcp://localhost:8888/NetTcpBinding/Test3"));
             ChannelFactory<IService1> factory = new ChannelFactory<IService1>(new NetTcpBinding(), address);
             service = factory.CreateChannel();
             rtxtthongtin.Text = service.GetAuthors();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Không kết nối được!!!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
         rtxtthongtin.Text = "";
     }
 }