void ConfigureHttpChannel (HttpContext context) { lock (GetType()) { if (webConfigLoaded) return; // Look for a channel that wants to receive http request foreach (IChannel channel in ChannelServices.RegisteredChannels) { IChannelReceiverHook chook = channel as IChannelReceiverHook; if (chook == null) continue; if (chook.ChannelScheme != "http") throw new RemotingException ("Only http channels are allowed when hosting remoting objects in a web server"); if (!chook.WantsToListen) continue; // Register the uri for the channel. The channel uri includes the scheme, the // host and the application path string channelUrl = context.Request.Url.GetLeftPart(UriPartial.Authority); channelUrl += context.Request.ApplicationPath; chook.AddHookChannelUri (channelUrl); transportSink = new HttpServerTransportSink (chook.ChannelSinkChain, null); } webConfigLoaded = true; } }
private void SetupChannel() { this._channelData = new ChannelDataStore(null); if (this._port > 0) { string channelUri = this.GetChannelUri(); this._channelData.ChannelUris = new string[] { channelUri }; this._wantsToListen = false; } if (this._sinkProvider == null) { this._sinkProvider = this.CreateDefaultServerProviderChain(); } CoreChannel.CollectChannelDataFromServerSinkProviders(this._channelData, this._sinkProvider); this._sinkChain = ChannelServices.CreateServerChannelSinkChain(this._sinkProvider, this); this._transportSink = new HttpServerTransportSink(this._sinkChain); base.SinksWithProperties = this._sinkChain; if (this._port >= 0) { this._tcpListener = new ExclusiveTcpListener(this._bindToAddr, this._port); ThreadStart start = new ThreadStart(this.Listen); this._listenerThread = new Thread(start); this._listenerThread.IsBackground = true; this.StartListening(null); } }
public RequestArguments (Socket socket, HttpServerTransportSink sink) { Id = count++; NetworkStream ns = new NetworkStream (socket); this.Stream = ns; this.socket = socket; Sink = sink; }
void ConfigureHttpChannel(HttpContext context) { lock (GetType()) { if (webConfigLoaded) { return; } string appConfig = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; if (File.Exists(appConfig)) { RemotingConfiguration.Configure(appConfig); } // Look for a channel that wants to receive http request IChannelReceiverHook chook = null; foreach (IChannel channel in ChannelServices.RegisteredChannels) { chook = channel as IChannelReceiverHook; if (chook == null) { continue; } if (chook.ChannelScheme != "http") { throw new RemotingException("Only http channels are allowed when hosting remoting objects in a web server"); } if (!chook.WantsToListen) { chook = null; continue; } //found chook break; } if (chook == null) { HttpChannel chan = new HttpChannel(); ChannelServices.RegisterChannel(chan); chook = chan; } // Register the uri for the channel. The channel uri includes the scheme, the // host and the application path string channelUrl = context.Request.Url.GetLeftPart(UriPartial.Authority); channelUrl += context.Request.ApplicationPath; chook.AddHookChannelUri(channelUrl); transportSink = new HttpServerTransportSink(chook.ChannelSinkChain); webConfigLoaded = true; } }
public RemotingHttpListener(IPAddress addr, int port, HttpServerTransportSink sink) { this.sink = sink; bool find_port = false; if (port == 0) { find_port = true; } string address = null; if (addr == IPAddress.Any) { address = "*"; } #if NET_2_0 else if (addr == IPAddress.IPv6Any) { address = "*"; } #endif else { address = addr.ToString(); } listener = new HttpListener(); while (true) { Random rnd = null; if (find_port) { if (rnd == null) { rnd = new Random(); } port = rnd.Next(1025, 65000); } try { listener.Prefixes.Add(String.Format("http://{0}:{1}/", address, port)); listener.Start(); local_port = port; break; } catch (Exception e) { if (!find_port) { throw; } listener.Prefixes.Clear(); // Port already in use } } listener.BeginGetContext(new AsyncCallback(OnGetContext), null); }
} // SetupMachineName private void SetupChannel() { // set channel data // (These get changed inside of StartListening(), in the case where the listen // port is 0, because we can't determine the port number until after the // TcpListener starts.) _channelData = new ChannelDataStore(null); if (_port > 0) { String channelUri = GetChannelUri(); _channelData.ChannelUris = new String[1]; _channelData.ChannelUris[0] = channelUri; _wantsToListen = false; } // set default provider (soap formatter) if no provider has been set if (_sinkProvider == null) { _sinkProvider = CreateDefaultServerProviderChain(); } CoreChannel.CollectChannelDataFromServerSinkProviders(_channelData, _sinkProvider); // construct sink chain _sinkChain = ChannelServices.CreateServerChannelSinkChain(_sinkProvider, this); _transportSink = new HttpServerTransportSink(_sinkChain); // set sink properties on base class, so that properties will be chained. SinksWithProperties = _sinkChain; if (_port >= 0) { // Open a TCP port and create a thread to start listening _tcpListener = new ExclusiveTcpListener(_bindToAddr, _port); ThreadStart t = new ThreadStart(this.Listen); _listenerThread = new Thread(t); _listenerThread.IsBackground = true; // Wait for thread to spin up StartListening(null); } } // SetupChannel
public RemotingHttpListener (IPAddress addr, int port, HttpServerTransportSink sink) { this.sink = sink; bool find_port = false; if (port == 0) find_port = true; string address = null; if (addr == IPAddress.Any) address = "*"; #if NET_2_0 else if (addr == IPAddress.IPv6Any) address = "*"; #endif else address = addr.ToString (); listener = new HttpListener (); while (true) { Random rnd = null; if (find_port) { if (rnd == null) rnd = new Random (); port = rnd.Next (1025, 65000); } try { listener.Prefixes.Add (String.Format ("http://{0}:{1}/", address, port)); listener.Start (); local_port = port; break; } catch (Exception) { if (!find_port) throw; listener.Prefixes.Clear (); // Port already in use } } listener.BeginGetContext (new AsyncCallback (OnGetContext), null); }
void BuildSink (IServerChannelSinkProvider sinkProvider) { //resolve names (modified from TcpChannel) if (machineName == null) { if (useIPAddress) { if (!bindAddress.Equals (IPAddress.Any)) { machineName = bindAddress.ToString (); } else { IPHostEntry hostEntry = Dns.Resolve (Dns.GetHostName ()); if (hostEntry.AddressList.Length == 0) throw new RemotingException ("IP address could not be determined for this host"); // We DON'T want to take the resolved address from the hostEntry, since the socket // should still bind to IPAddress.Any, so that we get the loopback too machineName = hostEntry.AddressList[0].ToString (); } } else { IPHostEntry hostEntry = Dns.GetHostByName (Dns.GetHostName ()); bindAddress = hostEntry.AddressList[0]; machineName = hostEntry.HostName; } } if (sinkProvider == null) { //build a default chain that can handle wsdl, soap, binary sinkProvider = new SdlChannelSinkProvider (); //for wsdl sinkProvider.Next = new SoapServerFormatterSinkProvider (); sinkProvider.Next.Next = new BinaryServerFormatterSinkProvider (); } //MS compat: channelData is null when port < 0 if (port >= 0) { channelData = new ChannelDataStore (null); IServerChannelSinkProvider provider = sinkProvider; while (provider != null) { provider.GetChannelData (channelData); provider = provider.Next; } } //create the sink chain and add an HTTP sink IServerChannelSink nextSink = ChannelServices.CreateServerChannelSinkChain (sinkProvider, this); sink = new HttpServerTransportSink (nextSink); // BaseChannelWithProperties wants this to be set with the chain base.SinksWithProperties = nextSink; StartListening (null); }
internal HttpRemotingHandler (HttpServerTransportSink sink) { transportSink = sink; }
void BuildSink(IServerChannelSinkProvider sinkProvider) { //resolve names (modified from TcpChannel) if (machineName == null) { if (useIPAddress) { if (!bindAddress.Equals(IPAddress.Any)) { machineName = bindAddress.ToString(); } else { IPHostEntry hostEntry = Dns.Resolve(Dns.GetHostName()); if (hostEntry.AddressList.Length == 0) { throw new RemotingException("IP address could not be determined for this host"); } // We DON'T want to take the resolved address from the hostEntry, since the socket // should still bind to IPAddress.Any, so that we get the loopback too machineName = hostEntry.AddressList[0].ToString(); } } else { IPHostEntry hostEntry = Dns.GetHostByName(Dns.GetHostName()); bindAddress = hostEntry.AddressList[0]; machineName = hostEntry.HostName; } } if (sinkProvider == null) { //build a default chain that can handle wsdl, soap, binary sinkProvider = new SdlChannelSinkProvider(); //for wsdl sinkProvider.Next = new SoapServerFormatterSinkProvider(); sinkProvider.Next.Next = new BinaryServerFormatterSinkProvider(); } //MS compat: channelData is null when port < 0 if (port >= 0) { channelData = new ChannelDataStore(null); IServerChannelSinkProvider provider = sinkProvider; while (provider != null) { provider.GetChannelData(channelData); provider = provider.Next; } } //create the sink chain and add an HTTP sink IServerChannelSink nextSink = ChannelServices.CreateServerChannelSinkChain(sinkProvider, this); sink = new HttpServerTransportSink(nextSink); // BaseChannelWithProperties wants this to be set with the chain base.SinksWithProperties = nextSink; StartListening(null); }
void SetupChannel (IServerChannelSinkProvider sinkProvider, IDictionary properties) { if (properties == null) properties = new Hashtable (); SetupMachineName(); _sinkProvider = sinkProvider; String[] urls = { this.GetChannelUri() }; // needed for CAOs _channelData = new ChannelDataStore(urls); if(_sinkProvider == null) { _sinkProvider = new SdlChannelSinkProvider(); _sinkProvider.Next = new SoapServerFormatterSinkProvider(); } // collect channel data from all providers IServerChannelSinkProvider provider = _sinkProvider; while (provider != null) { provider.GetChannelData(_channelData); provider = provider.Next; } // create the sink chain IServerChannelSink snk = ChannelServices.CreateServerChannelSinkChain(_sinkProvider,this); _transportSink = new HttpServerTransportSink (snk, properties); SinksWithProperties = _transportSink; }
} // SetupMachineName private void SetupChannel() { // set channel data // (These get changed inside of StartListening(), in the case where the listen // port is 0, because we can't determine the port number until after the // TcpListener starts.) _channelData = new ChannelDataStore(null); if (_port > 0) { String channelUri = GetChannelUri(); _channelData.ChannelUris = new String[1]; _channelData.ChannelUris[0] = channelUri; _wantsToListen = false; } // set default provider (soap formatter) if no provider has been set if (_sinkProvider == null) _sinkProvider = CreateDefaultServerProviderChain(); CoreChannel.CollectChannelDataFromServerSinkProviders(_channelData, _sinkProvider); // construct sink chain _sinkChain = ChannelServices.CreateServerChannelSinkChain(_sinkProvider, this); _transportSink = new HttpServerTransportSink(_sinkChain); // set sink properties on base class, so that properties will be chained. SinksWithProperties = _sinkChain; if (_port >= 0) { // Open a TCP port and create a thread to start listening _tcpListener = new ExclusiveTcpListener(_bindToAddr, _port); ThreadStart t = new ThreadStart(this.Listen); _listenerThread = new Thread(t); _listenerThread.IsBackground = true; // Wait for thread to spin up StartListening(null); } } // SetupChannel
internal HttpRemotingHandler(HttpServerTransportSink sink) { transportSink = sink; }
void ConfigureHttpChannel (HttpContext context) { lock (GetType()) { if (webConfigLoaded) return; string appConfig = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; if (File.Exists (appConfig)) RemotingConfiguration.Configure (appConfig); // Look for a channel that wants to receive http request IChannelReceiverHook chook = null; foreach (IChannel channel in ChannelServices.RegisteredChannels) { chook = channel as IChannelReceiverHook; if (chook == null) continue; if (chook.ChannelScheme != "http") throw new RemotingException ("Only http channels are allowed when hosting remoting objects in a web server"); if (!chook.WantsToListen) { chook = null; continue; } //found chook break; } if (chook == null) { HttpChannel chan = new HttpChannel(); ChannelServices.RegisterChannel(chan); chook = chan; } // Register the uri for the channel. The channel uri includes the scheme, the // host and the application path string channelUrl = context.Request.Url.GetLeftPart(UriPartial.Authority); channelUrl += context.Request.ApplicationPath; chook.AddHookChannelUri (channelUrl); transportSink = new HttpServerTransportSink (chook.ChannelSinkChain); webConfigLoaded = true; } }