Esempio n. 1
0
 void CloseSeviceClient()
 {
     if (serviceClient != null && serviceClient.State == CommunicationState.Opened)
     {
         serviceClient.Close();
     }
     serviceClient = null;
 }
Esempio n. 2
0
        bool OpenServiceClient(string server)
        {
            try
            {
                NetTcpBinding b = new NetTcpBinding();
                b.Security.Mode = SecurityMode.None;


                string address = "net.tcp://" + server + ":8001/CombatStateService";
                if (Regex.Match(server, ".+:[0-9]+").Success)
                {
                    address = "net.tcp://" + server + "/CombatStateService";
                }

                EndpointAddress a = new EndpointAddress(address);


                serviceClient = new CombatStateService.CombatStateServiceClient(new InstanceContext(this), b, a);
                serviceClient.Open();

                return(serviceClient.State == CommunicationState.Opened);
            }
            catch (System.UriFormatException)
            {
                MessageBox.Show("Invalid server name");
            }
            catch (System.ServiceModel.EndpointNotFoundException)
            {
                MessageBox.Show("Unable to locate requested server");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            return(false);
        }