HelloServer.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:2k
- using System;
- using System.Runtime.Remoting;
- using System.Runtime.Remoting.Channels;
- using System.Runtime.Remoting.Channels.Tcp;
- using System.Runtime.Remoting.Channels.Http;
- using System.Collections;
- namespace Wrox.ProCSharp.Remoting
- {
- public class HelloServer
- {
- protected static void ShowChannelProperties(IChannelReceiver channel)
- {
- Console.WriteLine("Name: " + channel.ChannelName);
- Console.WriteLine("Priority: " + channel.ChannelPriority);
- if (channel is HttpChannel)
- {
- HttpChannel httpChannel = channel as HttpChannel;
- Console.WriteLine("Scheme: " + httpChannel.ChannelScheme);
- }
- ChannelDataStore data = (ChannelDataStore)channel.ChannelData;
- foreach (string uri in data.ChannelUris)
- {
- Console.WriteLine("URI: " + uri);
- }
- Console.WriteLine();
- }
- public static void Main(string[] args)
- {
- // IDictionary properties = new Hashtable();
- // properties["name"] = "TCP Channel";
- //// properties["priority"] = "20";
- // properties["port"] = "8086";
- // BinaryServerFormatterSinkProvider sinkProvider =
- // new BinaryServerFormatterSinkProvider();
- //// SoapServerFormatterSinkProvider sinkProvider =
- //// new SoapServerFormatterSinkProvider();
- // sinkProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
- // TcpServerChannel tcpChannel =
- // new TcpServerChannel(properties, sinkProvider);
- TcpServerChannel tcpChannel = new TcpServerChannel(8086);
- ShowChannelProperties(tcpChannel);
- HttpServerChannel httpChannel = new HttpServerChannel(8085);
- ShowChannelProperties(httpChannel);
- ChannelServices.RegisterChannel(tcpChannel);
- ChannelServices.RegisterChannel(httpChannel);
- // RemotingConfiguration.RegisterWellKnownServiceType(
- // typeof(Hello), "Hi",
- // WellKnownObjectMode.SingleCall);
- RemotingConfiguration.ApplicationName = "Hello";
- RemotingConfiguration.RegisterActivatedServiceType(
- typeof(Hello));
- System.Console.WriteLine("press return to exit");
- System.Console.ReadLine();
- }
- }
- }