public static void Main(string[] args)
    {
        // Create the server channel.
        HttpServerChannel serverChannel = new HttpServerChannel(9090);

        // Register the server channel.
        ChannelServices.RegisterChannel(serverChannel);

        // Display the channel's scheme.
        Console.WriteLine("The channel scheme is {0}.",
                          serverChannel.ChannelScheme);

        // Display the channel's URI.
        Console.WriteLine("The channel URI is {0}.",
                          serverChannel.GetChannelUri());

        // Expose an object for remote calls.
        RemotingConfiguration.RegisterWellKnownServiceType(
            typeof(RemoteObject), "RemoteObject.rem",
            WellKnownObjectMode.Singleton);

        // Get the channel's sink chain.
        IServerChannelSink sinkChain = serverChannel.ChannelSinkChain;

        Console.WriteLine(
            "The type of the server channel's sink chain is {0}.",
            sinkChain.GetType().ToString());

        // See if the channel wants to listen.
        bool wantsToListen = serverChannel.WantsToListen;

        Console.WriteLine(
            "The value of WantsToListen is {0}.",
            wantsToListen);

        // Parse the channel's URI.
        string[] urls = serverChannel.GetUrlsForUri("RemoteObject.rem");
        if (urls.Length > 0)
        {
            string objectUrl = urls[0];
            string objectUri;
            string channelUri =
                serverChannel.Parse(objectUrl, out objectUri);
            Console.WriteLine("The object URI is {0}.", objectUri);
            Console.WriteLine("The channel URI is {0}.", channelUri);
            Console.WriteLine("The object URL is {0}.", objectUrl);
        }

        // Wait for the user prompt.
        Console.WriteLine("Press ENTER to exit the server.");
        Console.ReadLine();
        Console.WriteLine("The server is exiting.");
    }
예제 #2
0
    static void Main( )
    {
        try
        {
            string myString;
// <Snippet2>
            int myPort = 8085;
            // Creating the 'IDictionary' to set the server object properties.
            IDictionary myDictionary = new Hashtable();
            myDictionary["name"]     = "MyServerChannel1";
            myDictionary["priority"] = 2;
            myDictionary["port"]     = 8085;
            // Set the properties along with the constructor.
            HttpServerChannel myHttpServerChannel = new HttpServerChannel(myDictionary,
                                                                          new BinaryServerFormatterSinkProvider());
            // Register the server channel.
            ChannelServices.RegisterChannel(myHttpServerChannel);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyHelloServer),
                                                               "SayHello", WellKnownObjectMode.SingleCall);
            myHttpServerChannel.WantsToListen = true;
            // Start listening on a specific port.
            myHttpServerChannel.StartListening((object)myPort);
            // Get the name of the channel.
            Console.WriteLine("ChannelName : " + myHttpServerChannel.ChannelName);
            // Get the channel priority.
            Console.WriteLine("ChannelPriority : " + myHttpServerChannel.ChannelPriority);
            // Get the schema of the channel.
            Console.WriteLine("ChannelScheme : " + myHttpServerChannel.ChannelScheme);
            // Get the channel URI.
            Console.WriteLine("GetChannelUri : " + myHttpServerChannel.GetChannelUri());
            // Indicates whether 'IChannelReceiverHook' wants to be hooked into the outside listener service.
            Console.WriteLine("WantsToListen : " + myHttpServerChannel.WantsToListen);
// </Snippet2>
// <Snippet3>
            // Extract the channel URI and the remote well known object URI from the specified URL.
            Console.WriteLine("Parsed : " +
                              myHttpServerChannel.Parse(myHttpServerChannel.GetChannelUri() +
                                                        "/SayHello", out myString));
            Console.WriteLine("Remote WellKnownObject : " + myString);
            Console.WriteLine("Hit <enter> to stop listening...");
            Console.ReadLine();
            // Stop listening to channel.
            myHttpServerChannel.StopListening((object)myPort);
// </Snippet3>
            Console.WriteLine("Hit <enter> to exit...");
            Console.ReadLine();
        }
        catch (Exception ex)
        {
            Console.WriteLine("The following exception is raised on server side : " + ex.Message);
        }
    }