Example #1
0
    public static void Main()
    {
        // System.Runtime.Remoting.RemotingServices.Disconnect() -- ManualServer.cs has a snippet for Disconnect, too.
        // <Snippet3>
        WellKnownClientTypeEntry remoteType = new WellKnownClientTypeEntry(typeof(SampleWellKnown), "tcp://localhost:9000/objectWellKnownUri");

        RemotingConfiguration.RegisterWellKnownClientType(remoteType);

        SampleWellKnown objectWellKnown = new SampleWellKnown();

        try {
            objectWellKnown.Add(2, 3);
            Console.WriteLine("The add method on SampleWellKnown was successfully called.");
        }
        catch (SocketException) {
            Console.WriteLine("The server is not available.  Is it still running?");
        }
        catch (RemotingException) {
            Console.WriteLine("SampleWellKnown is currently not available.  The server probably called Disconnect().");
        }
        // </Snippet3>
    }
Example #2
0
    public static void Main()
    {
        // <Snippet2>
        TcpChannel channel = new TcpChannel(9000);

        ChannelServices.RegisterChannel(channel);

        SampleWellKnown objectWellKnown = new SampleWellKnown();

        // After the channel is registered, the object needs to be registered
        // with the remoting infrastructure.  So, Marshal is called.
        ObjRef objrefWellKnown = RemotingServices.Marshal(objectWellKnown, "objectWellKnownUri");

        Console.WriteLine("An instance of SampleWellKnown type is published at {0}.", objrefWellKnown.URI);

        Console.WriteLine("Press enter to unregister SampleWellKnown, so that it is no longer available on this channel.");
        Console.ReadLine();
        RemotingServices.Disconnect(objectWellKnown);

        Console.WriteLine("Press enter to end the server process.");
        Console.ReadLine();
        // </Snippet2>
    }
Example #3
0
    private static void Snippet1()
    {
        // <Snippet1>
        Console.WriteLine("Connecting to SampleNamespace.SampleWellKnown.");

        SampleWellKnown proxy =
            (SampleWellKnown)RemotingServices.Connect(typeof(SampleWellKnown), SERVER_URL);

        Console.WriteLine("Connected to SampleWellKnown");

        // Verifies that the object reference is to a transparent proxy.
        if (RemotingServices.IsTransparentProxy(proxy))
        {
            Console.WriteLine("proxy is a reference to a transparent proxy.");
        }
        else
        {
            Console.WriteLine("proxy is not a transparent proxy.  This is unexpected.");
        }

        // Calls a method on the server object.
        Console.WriteLine("proxy.Add returned {0}.", proxy.Add(2, 3));
        // </Snippet1>
    }