예제 #1
0
        void InputSessionFaultedCore(ServiceChannel channel)
        {
            IDuplexContextChannel proxy = channel.Proxy as IDuplexContextChannel;

            if (proxy != null)
            {
                IInputSessionShutdown[] handlers = inputSessionShutdownHandlers;
                try
                {
                    for (int i = 0; i < handlers.Length; i++)
                    {
                        handlers[i].ChannelFaulted(proxy);
                    }
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    if (!error.HandleError(e))
                    {
                        proxy.Abort();
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Subscribe to the service
        /// Messages are sent to service message listener until enter is pressed.
        /// </summary>
        /// <param name="method">A method from GetSubscribableMethods</param>
        public void SubscribeMethod(MethodInfo method)
        {
            if (!Initialized)
            {
                throw new InvalidOperationException("Service not initialized");
            }

            Object[] subAttributes = method.GetCustomAttributes(typeof(DPWSSubscription), true);
            if (subAttributes.Length < 1)
            {
                throw new ArgumentException("Not a subscribable method");
            }

            String eventOut = ((DPWSSubscription)subAttributes[0]).EventOut;

            /// Open connection
            InstanceContext instanceContext = new InstanceContext(this);
            Object          client          = Activator.CreateInstance(clientType, instanceContext, GetConfigurationName());
            ServiceEndpoint endpoint        = (ServiceEndpoint)endpointField.GetValue(client, null);

            endpoint.Address = endpointAddress;
            endpoint.Binding.ReceiveTimeout = new TimeSpan(0, 0, 2);

            clientOpenMethod.Invoke(client, null);


            IDuplexContextChannel innerDuplexChannel = (IDuplexContextChannel)clientChannelField.GetValue(client, null);
            EndpointAddress       callbackEndpoint   = innerDuplexChannel.LocalAddress;
            EventSourceClient     eventSource        = new EventSourceClient(instanceContext, "WSEventing");

            eventSource.Endpoint.Address = endpointAddress;
            eventSource.Open();
            String subscriptionId = SubscribeMsg(eventSource, callbackEndpoint, eventOut);

            /// Invoke

            Console.WriteLine("Got subscription: {0}", subscriptionId);

            object[] args = new object[] { client };
            try
            {
                method.Invoke(this, args);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            Console.WriteLine("Press <ENTER> to unsubscribe.");
            Console.ReadLine();

            Console.WriteLine("Unsubscribing {0}", subscriptionId);

            /// Close connection
            UnsubscribeMsg(subscriptionId);
            clientCloseMethod.Invoke(client, null);
        }
예제 #3
0
        private void InnerDuplexChannel_StateChanged(object sender, EventArgs e)
        {
            IDuplexContextChannel duplexContext = sender as IDuplexContextChannel;

            if (duplexContext != null)
            {
                CommunicationState state = duplexContext.State;
                _eventAggregator.GetEvent <ClientConnectionEvent>().Publish(state);
            }
        }
예제 #4
0
        private void InnerDuplexChannel_StateChanged(object sender, EventArgs e)
        {
            IDuplexContextChannel duplexContext = sender as IDuplexContextChannel;

            clientService.Form.Connected = duplexContext.State == CommunicationState.Opened;
            clientService.Form.Status(duplexContext.State.ToString());
            if (duplexContext.State == CommunicationState.Closed || duplexContext.State == CommunicationState.Faulted)
            {
                clientService.Clients.Clear();
            }
        }
예제 #5
0
            void IInputSessionShutdown.ChannelFaulted(IDuplexContextChannel channel)
            {
                RoutingChannelExtension channelExtension = channel.Extensions.Find <RoutingChannelExtension>();

                if (channelExtension != null)
                {
                    channelExtension.Fault(new CommunicationObjectFaultedException());
                }
                else
                {
                    RoutingUtilities.Abort(channel, channel.LocalAddress);
                }
            }
            private void CreateControlProxy()
            {
                EndpointAddress remoteAddress            = new EndpointAddress(System.ServiceModel.Activation.Utility.FormatListenerEndpoint(this.serviceName, this.listenerEndPoint), new AddressHeader[0]);
                NamedPipeTransportBindingElement element = new NamedPipeTransportBindingElement();
                CustomBinding   binding                      = new CustomBinding(new BindingElement[] { element });
                InstanceContext callbackInstance             = new InstanceContext(null, this, false);
                ChannelFactory <IConnectionRegister> factory = new DuplexChannelFactory <IConnectionRegister>(callbackInstance, binding, remoteAddress);

                factory.Endpoint.Behaviors.Add(new SharedListenerProxyBehavior(this));
                IConnectionRegister register = factory.CreateChannel();

                this.channelFactory             = factory;
                this.controlSessionWithListener = register as IDuplexContextChannel;
            }
예제 #7
0
        public virtual TChannel CreateChannel(InstanceContext callbackInstance, EndpointAddress address, Uri via)
        {
            if (address == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("address");
            }

            if (this.CallbackType != null && callbackInstance == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SRServiceModel.SFxCreateDuplexChannelNoCallback1));
            }
            if (callbackInstance == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SRServiceModel.SFxCreateDuplexChannelNoCallback));
            }

            if (callbackInstance.UserObject == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SRServiceModel.SFxCreateDuplexChannelNoCallbackUserObject));
            }

            if (!this.HasDuplexOperations())
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(SRServiceModel.SFxCreateDuplexChannel1, this.Endpoint.Contract.Name)));
            }

            Type userObjectType = callbackInstance.UserObject.GetType();
            Type callbackType   = this.Endpoint.Contract.CallbackContractType;

            if (callbackType != null && !callbackType.IsAssignableFrom(userObjectType))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(
                                                                                                            SRServiceModel.SFxCreateDuplexChannelBadCallbackUserObject, callbackType)));
            }

            EnsureOpened();
            TChannel result = this.ServiceChannelFactory.CreateChannel <TChannel>(address, via);
            // Desktop: this.ServiceChannelFactory.CreateChannel(typeof(TChannel), address, via);

            IDuplexContextChannel duplexChannel = result as IDuplexContextChannel;

            if (duplexChannel != null)
            {
                duplexChannel.CallbackInstance = callbackInstance;
            }
            return(result);
        }
        public virtual TChannel CreateChannel(InstanceContext callbackInstance, EndpointAddress address, Uri via)
        {
            if (address == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("address");
            }
            if ((base.CallbackType != null) && (callbackInstance == null))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxCreateDuplexChannelNoCallback1")));
            }
            if (callbackInstance == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxCreateDuplexChannelNoCallback")));
            }
            if (callbackInstance.UserObject == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxCreateDuplexChannelNoCallbackUserObject")));
            }
            if (!base.HasDuplexOperations())
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxCreateDuplexChannel1", new object[] { base.Endpoint.Contract.Name })));
            }
            System.Type c = callbackInstance.UserObject.GetType();
            System.Type callbackContractType = base.Endpoint.Contract.CallbackContractType;
            if ((callbackContractType != null) && !callbackContractType.IsAssignableFrom(c))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxCreateDuplexChannelBadCallbackUserObject", new object[] { callbackContractType })));
            }
            base.EnsureOpened();
            TChannel local = (TChannel)base.ServiceChannelFactory.CreateChannel(typeof(TChannel), address, via);
            IDuplexContextChannel channel = local as IDuplexContextChannel;

            if (channel != null)
            {
                channel.CallbackInstance = callbackInstance;
            }
            return(local);
        }
 void IInputSessionShutdown.ChannelFaulted(IDuplexContextChannel channel)
 {
     this.OnControlChannelShutdown();
 }
예제 #10
0
        public void DoneReceiving(IDuplexContextChannel channel)
        {

        }
예제 #11
0
        public void ChannelFaulted(IDuplexContextChannel channel)
        {

        }
 private void CreateControlProxy()
 {
     EndpointAddress remoteAddress = new EndpointAddress(System.ServiceModel.Activation.Utility.FormatListenerEndpoint(this.serviceName, this.listenerEndPoint), new AddressHeader[0]);
     NamedPipeTransportBindingElement element = new NamedPipeTransportBindingElement();
     CustomBinding binding = new CustomBinding(new BindingElement[] { element });
     InstanceContext callbackInstance = new InstanceContext(null, this, false);
     ChannelFactory<IConnectionRegister> factory = new DuplexChannelFactory<IConnectionRegister>(callbackInstance, binding, remoteAddress);
     factory.Endpoint.Behaviors.Add(new SharedListenerProxyBehavior(this));
     IConnectionRegister register = factory.CreateChannel();
     this.channelFactory = factory;
     this.controlSessionWithListener = register as IDuplexContextChannel;
 }
예제 #13
0
 /// <summary>
 /// Indicates when the client channel is done receiving messages as part of the duplex message exchange.
 /// </summary>
 /// <param name="channel">The <see cref="T:System.ServiceModel.Channels.IDuplexSessionChannel"/> that is done receiving.</param>
 public void DoneReceiving(IDuplexContextChannel channel)
 {
     STrace.Debug(GetType().FullName, String.Format("DoneReceiving: state={0} client={1}", channel.State.ToString(), CurrentSession().Session.ClientName));
 }
예제 #14
0
 void IInputSessionShutdown.DoneReceiving(IDuplexContextChannel channel)
 {
     RoutingChannelExtension channelExtension = channel.Extensions.Find<RoutingChannelExtension>();
     channelExtension.DoneReceiving(this.Endpoint.Binding.CloseTimeout);
 }
예제 #15
0
 void IInputSessionShutdown.ChannelFaulted(IDuplexContextChannel channel)
 {
     RoutingChannelExtension channelExtension = channel.Extensions.Find<RoutingChannelExtension>();
     if (channelExtension != null)
     {
         channelExtension.Fault(new CommunicationObjectFaultedException());
     }
     else
     {
         RoutingUtilities.Abort(channel, channel.LocalAddress);
     }
 }
 void IInputSessionShutdown.ChannelFaulted(IDuplexContextChannel channel)
 {
     //Noop
 }
예제 #17
0
            void IInputSessionShutdown.DoneReceiving(IDuplexContextChannel channel)
            {
                RoutingChannelExtension channelExtension = channel.Extensions.Find <RoutingChannelExtension>();

                channelExtension.DoneReceiving(this.Endpoint.Binding.CloseTimeout);
            }
 void IInputSessionShutdown.DoneReceiving(IDuplexContextChannel channel)
 {
     this.OnControlChannelShutdown();
 }
 void IInputSessionShutdown.ChannelFaulted(IDuplexContextChannel channel)
 {
     this.OnControlChannelShutdown();
 }
 void IInputSessionShutdown.DoneReceiving(IDuplexContextChannel channel)
 {
     //Close it if the neighbor it was connected to has disconnected
     if (channel.State == CommunicationState.Opened)
     {
         channel.Close();
     }
 }
 void IInputSessionShutdown.DoneReceiving(IDuplexContextChannel channel)
 {
     this.OnControlChannelShutdown();
 }