예제 #1
0
        internal static IMessageSink CreateClientChannelSinkChain(IChannelSender sender, string url, object[] channelDataArray, out string objectUri)
        {
            objectUri = null;
            if (channelDataArray == null)
            {
                return(sender.CreateMessageSink(url, null, out objectUri));
            }
            else
            {
                foreach (object data in channelDataArray)
                {
                    IMessageSink sink;

                    if (data is IChannelDataStore)
                    {
                        // Don't provide the url in this case, since some channels won't
                        // check the channelData parameter if the url is not null.
                        sink = sender.CreateMessageSink(null, data, out objectUri);
                    }
                    else
                    {
                        sink = sender.CreateMessageSink(url, data, out objectUri);
                    }
                    if (sink != null)
                    {
                        return(sink);
                    }
                }
            }
            return(null);
        }
 internal static IMessageSink CreateClientChannelSinkChain(IChannelSender sender, string url, object[] channelDataArray, out string objectUri)
 {
     objectUri = null;
     if (channelDataArray == null)
     {
         return(sender.CreateMessageSink(url, null, out objectUri));
     }
     foreach (object obj in channelDataArray)
     {
         IMessageSink messageSink;
         if (obj is IChannelDataStore)
         {
             messageSink = sender.CreateMessageSink(null, obj, out objectUri);
         }
         else
         {
             messageSink = sender.CreateMessageSink(url, obj, out objectUri);
         }
         if (messageSink != null)
         {
             return(messageSink);
         }
     }
     return(null);
 }
        public MyProxy(Type myType, string myUrl1)
            : base(myType)
        {
            myUrl = myUrl1;

            IChannel[] myRegisteredChannels = ChannelServices.RegisteredChannels;
            foreach (IChannel channel in myRegisteredChannels)
            {
                if (channel is IChannelSender)
                {
                    IChannelSender myChannelSender = (IChannelSender)channel;

                    myMessageSink = myChannelSender.CreateMessageSink(myUrl, null, out myObjectURI);
                    if (myMessageSink != null)
                    {
                        break;
                    }
                }
            }

            if (myMessageSink == null)
            {
                throw new Exception("A supported channel could not be found for myUrl1:" + myUrl);
            }
        }
        public MyProxy(Type type, String url)
            : base(type)
        {
            // This constructor forwards the call to base RealProxy.
            // RealProxy uses the Type to generate a transparent proxy
            _url = url;

            IChannel[] registeredChannels = ChannelServices.RegisteredChannels;

            foreach (IChannel channel in registeredChannels)
            {
                if (channel is IChannelSender)
                {
                    IChannelSender channelSender = (IChannelSender)channel;

                    _messageSink = channelSender.CreateMessageSink(_url, null, out _objectURI);
                    if (_messageSink != null)
                    {
                        break;
                    }
                }
            }

            if (_messageSink == null)
            {
                throw new Exception("A supported channel could not be found for url:" + _url);
            }
        }
예제 #5
0
        public CustomProxy(Type type, String url) : base(type)
        {
            _url = url;


            // check each registered channel if it accepts the
            // given URL
            IChannel[] registeredChannels = ChannelServices.RegisteredChannels;
            foreach (IChannel channel in registeredChannels)
            {
                if (channel is IChannelSender)
                {
                    IChannelSender channelSender = (IChannelSender)channel;

                    // try to create the sink
                    _sinkChain = channelSender.CreateMessageSink(_url,
                                                                 null, out _uri);

                    // if the channel returned a sink chain, exit the loop
                    if (_sinkChain != null)
                    {
                        break;
                    }
                }
            }

            // no registered channel accepted the URL
            if (_sinkChain == null)
            {
                throw new Exception("No channel has been found for " + _url);
            }
        }
예제 #6
0
        } // RegisteredChannels

        internal static IMessageSink CreateMessageSink(String url, Object data, out String objectURI)
        {
            BCLDebug.Trace("REMOTE", "ChannelServices::CreateMessageSink for url " + url + "\n");
            IMessageSink msgSink = null;

            objectURI = null;

            RegisteredChannelList regChnlList = s_registeredChannels;
            int count = regChnlList.Count;

            for (int i = 0; i < count; i++)
            {
                if (regChnlList.IsSender(i))
                {
                    IChannelSender chnl = (IChannelSender)regChnlList.GetChannel(i);
                    msgSink = chnl.CreateMessageSink(url, data, out objectURI);

                    if (msgSink != null)
                    {
                        break;
                    }
                }
            }

            // If the object uri has not been set, set it to the url as
            // default value
            if (null == objectURI)
            {
                objectURI = url;
            }

            return(msgSink);
        } // CreateMessageSink
예제 #7
0
        /// <summary>
        /// constructor
        /// </summary>
        public CustomProxy(string ACrossDomainURL, string AServiceURI, string AClientID, Type type) : base(type)
        {
            this.CrossDomainURL = ACrossDomainURL;

            this.clientID = AClientID;

            this.serviceID = AServiceURI;

            foreach (IChannel channel in ChannelServices.RegisteredChannels)
            {
                if (channel is IChannelSender)
                {
                    IChannelSender sender = (IChannelSender)channel;

                    if (string.Compare(sender.ChannelName, "tcp") == 0)
                    {
                        string objectUri;
                        this.messageSink = sender.CreateMessageSink(this.CrossDomainURL, null, out objectUri);

                        if (this.messageSink != null)
                        {
                            break;
                        }
                    }
                }
            }

            if (this.messageSink == null)
            {
                throw new Exception("No channel found for " + this.CrossDomainURL);
            }
        }
예제 #8
0
        internal static IMessageSink CreateMessageSink(string url, object data, out string objectURI)
        {
            IMessageSink messageSink = null;

            objectURI = null;
            RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
            int count = registeredChannelList.Count;

            for (int i = 0; i < count; i++)
            {
                if (registeredChannelList.IsSender(i))
                {
                    IChannelSender channelSender = (IChannelSender)registeredChannelList.GetChannel(i);
                    messageSink = channelSender.CreateMessageSink(url, data, out objectURI);
                    if (messageSink != null)
                    {
                        break;
                    }
                }
            }
            if (objectURI == null)
            {
                objectURI = url;
            }
            return(messageSink);
        }
예제 #9
0
        private IMessageSink[] GetMessageSinks()
        {
            IChannel[]   registeredChannels = ChannelServices.RegisteredChannels;
            IMessageSink MessageSink;
            string       ObjectURI;
            ArrayList    MessageSinks = new ArrayList();

            foreach (IChannel channel in registeredChannels)
            {
                if (channel is IChannelSender)
                {
                    IChannelSender channelSender = (IChannelSender)channel;
                    if (channelSender.ChannelName == "tcp")
                    {
                        MessageSink = channelSender.CreateMessageSink(_TcpUrl, null, out ObjectURI);
                    }
                    else
                    {
                        MessageSink = channelSender.CreateMessageSink(_HttpUrl, null, out ObjectURI);
                    }
                    if (MessageSink != null)
                    {
                        MessageSinks.Add(MessageSink);
                    }
                }
            }
            //string objectURI;
            //HttpChannel HttpChannel = new HttpChannel();
            //ChannelServices.RegisterChannel(HttpChannel, false);
            //MessageSinks.Add(HttpChannel.CreateMessageSink(_HttpUrl, null, out objectURI));

            if (MessageSinks.Count > 0)
            {
                return((IMessageSink[])MessageSinks.ToArray(typeof(IMessageSink)));
            }
            // Made it out of the foreach block without finding
            // a MessageSink for the URL.
            throw new Exception("Unable to find MessageSink for the URL :" + _TcpUrl);
        }
예제 #10
0
        /// <summary>
        /// Sendet eine Nachricht an den Komponentenaufrufer.
        /// </summary>
        /// <param name="message">Remoting-Nachricht mit Details für den entfernten Methodenaufruf</param>
        /// <returns>Remoting Antwortnachricht</returns>
        public override IMessage Invoke(IMessage message)
        {
            // Wenn noch keine Nachrichtensenke erstellt wurde ...
            if (_messageSink == null)
            {
                // Sendekanal vom Verbindungsobjekt abrufen
                IChannelSender channel = _connection.Channel as IChannelSender;

                // Nachrichtensenke erstellen
                string sinkObjektUri;
                _messageSink = channel.CreateMessageSink(_connection.ServerUrl, null, out sinkObjektUri);
            }
            // Nachricht an Server senden
            IMessage returnMessage = _messageSink.SyncProcessMessage(message);

            // Antwortnachricht zurückgeben
            return(returnMessage);
        }
예제 #11
0
        public MyProxy(Type serverType, MarshalByRefObject target) : base(serverType)
        {
            this.target = target;

            IChannel[] registeredChannels = ChannelServices.RegisteredChannels;
            string     ObjectURI;

            // A new IMessageSink chain has to be created
            // since the RemotingServices.GetEnvoyChainForProxy() is not yet
            // implemented.
            foreach (IChannel channel in registeredChannels)
            {
                IChannelSender channelSender = channel as IChannelSender;
                if (channelSender != null)
                {
                    _sink = (IMessageSink)channelSender.CreateMessageSink(RemotingServices.GetObjectUri(target), null, out ObjectURI);
                }
            }
        }
        internal static IMessageSink FindDelayLoadChannelForCreateMessageSink(string url, object data, out string objectURI)
        {
            LoadMachineConfigIfNecessary();
            objectURI = null;
            IMessageSink sink = null;

            foreach (DelayLoadClientChannelEntry entry in _delayLoadChannelConfigQueue)
            {
                IChannelSender channel = entry.Channel;
                if (channel != null)
                {
                    sink = channel.CreateMessageSink(url, data, out objectURI);
                    if (sink != null)
                    {
                        entry.RegisterChannel();
                        return(sink);
                    }
                }
            }
            return(null);
        }
예제 #13
0
파일: IceProxy.cs 프로젝트: retahc/old-code
        private void FindChannel()
        {
            IChannel[] registeredChannels = ChannelServices.RegisteredChannels;
            foreach (IChannel ch in registeredChannels)
            {
                if (ch is IChannelSender)
                {
                    IChannelSender chs = (IChannelSender)ch;
                    _sinkChain = chs.CreateMessageSink(_url, null, out _uri);
                    if (_sinkChain != null)
                    {
                        break;
                    }
                }
            }

            if (_sinkChain == null)
            {
                throw new Exception("No channel found for " + _url);
            }
        }
		internal static IMessageSink CreateClientChannelSinkChain (IChannelSender sender, string url, object[] channelDataArray, out string objectUri)
		{
			objectUri = null;
			if (channelDataArray == null) {
				return sender.CreateMessageSink (url, null, out objectUri);
			}
			else {
				foreach (object data in channelDataArray) {
					IMessageSink sink;

					if (data is IChannelDataStore) {
						// Don't provide the url in this case, since some channels won't
						// check the channelData parameter if the url is not null.
						sink = sender.CreateMessageSink (null, data, out objectUri);
					} else {
						sink = sender.CreateMessageSink (url, data, out objectUri);
					}
					if (sink != null) return sink;		
				}
			}
			return null;
		}
예제 #15
0
        private IMessage MessageDispatcher(IMessage iMsgReq, Stream requestStream)
        {
            IMessage iMsgRsp = null;

            if (iMsgReq.Properties["__Uri"] != null)
            {
                // parse url address
                string   strObjectUrl = iMsgReq.Properties["__Uri"].ToString();
                string[] urlpath      = strObjectUrl.Split(';');
                string[] s            = urlpath[0].Split('/');

                // check endpoint
                if (urlpath.Length == 1 && s.Length == 1)
                {
                    //this is an end channel
                    Trace.WriteLine(string.Format("[{0}]MSMQChannel.Receiver.MessageDispatcher: Local endpoint={1}",
                                                  ChannelName, strObjectUrl));

                    // channel
                    Receiver rcv = this as Receiver;

                    // stack
                    ServerChannelSinkStack stack = new ServerChannelSinkStack();
                    stack.Push(rcv.TransportSink, null);

                    // request (workaround)
                    ITransportHeaders requestHeaders = null;
                    if (iMsgReq.Properties.Contains("__RequestHeaders"))
                    {
                        requestHeaders = iMsgReq.Properties["__RequestHeaders"] as ITransportHeaders;
                    }
                    else
                    {
                        requestHeaders = new TransportHeaders();
                        requestHeaders["__ContentType"] = "application/octet-stream";
                    }
                    requestHeaders["__RequestUri"] = "/" + strObjectUrl;
                    requestStream.Position         = 0;

                    // response
                    Stream            responseStream  = null;
                    ITransportHeaders responseHeaders = null;

                    // skip the transport sink
                    rcv.TransportSink.NextChannelSink.ProcessMessage(stack, null, requestHeaders, requestStream,
                                                                     out iMsgRsp, out responseHeaders, out responseStream);
                }
                else
                {
                    // chaining channel
                    string       strDummy = null;
                    IMessageSink sink     = null;

                    // find a properly channel
                    foreach (IChannel ch in ChannelServices.RegisteredChannels)
                    {
                        if (ch is IChannelSender)
                        {
                            IChannelSender iChannelSender = ch as IChannelSender;
                            sink = iChannelSender.CreateMessageSink(strObjectUrl, null, out strDummy);
                            if (sink != null)
                            {
                                //this is a next channel
                                Trace.WriteLine(string.Format("[{0}]MSMQChannel.Receiver.MessageDispatcher: Chained channel is url={1}",
                                                              ChannelName, strObjectUrl));
                                break;
                            }
                        }
                    }

                    if (sink == null)
                    {
                        //no channel found it
                        string strError = string.Format("[{0}]MSMQChannel.Receiver.MessageDispatcher: A supported channel could not be found for {1}",
                                                        ChannelName, strObjectUrl);
                        iMsgRsp = new ReturnMessage(new Exception(strError), (IMethodCallMessage)iMsgReq);
                        Trace.WriteLine(strError);
                    }
                    else
                    {
                        //check for an oneway attribute
                        IMethodCallMessage mcm = iMsgReq as IMethodCallMessage;

                        if (RemotingServices.IsOneWay(mcm.MethodBase) == true)
                        {
                            iMsgRsp = (IMessage)sink.AsyncProcessMessage(iMsgReq, null);
                        }
                        else
                        {
                            iMsgRsp = sink.SyncProcessMessage(iMsgReq);
                        }
                    }
                }
            }
            else
            {
                //exception
                Exception ex = new Exception(string.Format("[{0}]MSMQChannel.Receiver.MessageDispatcher: The Uri address is null", ChannelName));
                iMsgRsp = new ReturnMessage(ex, (IMethodCallMessage)iMsgReq);
            }

            // check the response message
            if (iMsgRsp != null)
            {
                IMethodReturnMessage mrm = iMsgRsp as IMethodReturnMessage;
                if (mrm.Exception != null)
                {
                    throw mrm.Exception;
                }
            }

            return(iMsgRsp);
        }
예제 #16
0
 public virtual IMessageSink CreateMessageSink(string url,
                                               object remoteChannelData,
                                               out string objectURI)
 {
     return(_innerChannel.CreateMessageSink(url, remoteChannelData, out objectURI));
 }
예제 #17
0
 public IMessageSink CreateMessageSink(string url,
                                       object remoteChannelData,
                                       out string objectUri)
 {
     return(_clientChannel.CreateMessageSink(url, remoteChannelData, out objectUri));
 }