예제 #1
0
파일: Client.cs 프로젝트: Erroman/universal
 void CreateClient()
 {
     try
     {
         if (client != null)
         {
             if (client.Url.Equals(url) & client.Type.Equals(type))
             {
                 return;
             }
         }
         Disconnect();
         if (type.Equals(RemoteType.Ipc))
         {
             client = new IPCClient.Subscriber(url);
         }
         else if (type.Equals(RemoteType.Tcp))
         {
             client = new TCPClient.Subscriber(url);
         }
         else
         {
             client = new HttpClient.Subscriber(url);
         }
         foreach (Action <object[]> read in reads)
         {
             client.Read += read;
         }
         str = client.Register();
         if (str != null)
         {
             types = str.StringToTypes();
         }
     }
     catch (Exception exception)
     {
         isEnanled = false;
         exception.ShowError();
         Disconnect();
         client = null;
     }
 }
예제 #2
0
 /// <summary>
 /// Creates subscription
 /// </summary>
 void CreateSubscription()
 {
     if (type.Equals(Remote.RemoteType.Ipc))
     {
         IPCClient.Subscriber s = new IPCClient.Subscriber(url, ev);
         register     = (bool b) => { s.Subscribe(b); };
         subscription = s;
         return;
     }
     if (type.Equals(Remote.RemoteType.Tcp))
     {
         TCPClient.Subscriber s = new TCPClient.Subscriber(url, ev);
         register     = (bool b) => { s.Subscribe(b); };
         subscription = s;
         return;
     }
     if (type.Equals(Remote.RemoteType.Http))
     {
         HttpClient.Subscriber s = new HttpClient.Subscriber(url, ev);
         register     = (bool b) => { s.Subscribe(b); };
         subscription = s;
         return;
     }
 }
예제 #3
0
        /// <summary>
        /// This is the method that is used to take pub and sub service in listen mode.
        ///
        /// </summary>
        void Initializeoperation()
        {
            try
            {
                // eventServiceHost = new ServiceHost(typeof(Publishing));

                ///Here diferent binding is created for different protocol.
                /// For example NetTcpBinding is created for TCP protocol.
                /// For example WSDualHttpBinding is created for  HTTP  protocol.
                /// For example NetNamedPipeBinding is created for Named Pipe protocol.

                if (type.Equals(RemoteType.Ipc))
                {
                    binding = new NetNamedPipeBinding();
                }
                else if (type.Equals(RemoteType.Tcp))
                {
                    NetTcpBinding n = new NetTcpBinding(SecurityMode.None);
                    n.Security.Message.ClientCredentialType = MessageCredentialType.None;
                    binding = n;
                }
                else
                {
                    binding = new WSDualHttpBinding(WSDualHttpSecurityMode.None);
                }

                ///By the following line i add the address of PublishService to eventServiceHost for differnt protocol

                /*!!!     eventServiceHost.AddServiceEndpoint(typeof(IEvent), wsDualBindingpublish,
                 *                           "http://localhost:8000/PublishingService/");
                 *   eventServiceHost.AddServiceEndpoint(typeof(IEvent), tcpBindingpublish,
                 *                           "net.tcp://localhost:8001/PublishingService");
                 *   eventServiceHost.AddServiceEndpoint(typeof(IEvent), namedPipeBindingpublish,
                 *                           "net.pipe://localhost/MyPipe1");
                 *
                 *   //This line is used  to open pub service to listen.
                 *   eventServiceHost.Open();*/
                subscriptionManagerHost = new ServiceHost(typeof(Subscription));

                /*
                 * System.ServiceModel.Channels.Binding wsDualBinding = new WSDualHttpBinding(WSDualHttpSecurityMode.None);
                 * System.ServiceModel.Channels.Binding tcpBinding = new NetTcpBinding(SecurityMode.None);*/
                // System.ServiceModel.Channels.Binding namedPipeBinding = new NetNamedPipeBinding();

                /*
                 *
                 * ///By the following line i add the address of Subscription Service to subscriptionManagerHost for differnt protocol
                 * subscriptionManagerHost.AddServiceEndpoint(typeof(IRegistration), wsDualBinding,
                 *                      "http://localhost:8003/SubscriptionServie/");
                 * subscriptionManagerHost.AddServiceEndpoint(typeof(IRegistration), tcpBinding,
                 *                  "net.tcp://localhost:8002/SubscriptionServie");*/
                subscriptionManagerHost.AddServiceEndpoint(typeof(IRegistration), binding, url);



                //This line is used  to open sub service to listen.
                subscriptionManagerHost.Open();
            }
            catch (Exception exception)
            {
                this.ShowError(exception);
            }
        }