Results 1 to 12 of 12

Thread: Moving from .Net Remoting to Anonymous Pipes, equivalent of Activator.GetObject

Threaded View

  1. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: Moving from .Net Remoting to Anonymous Pipes, equivalent of Activator.GetObject

    Quote Originally Posted by FunkyDexter View Post
    I'm rewriting an old application that used .Net Remoting to control a second application. The rewrite involves changing from VB to C# (so apologies for the mixed languages in this post) and targeting core rather than a framework. Core doesn't support .Net Remoting and the advise seems to be to use Anonymous Pipes. I'm not familiar with either of these so it's a bit of a baptism of fire. I've been following the example here and have got it sending a simple string from one app to the other.

    Here's my server app code:-
    c# Code:
    1. public void StartAquatorXV(string exePath, int port)
    2.         {
    3.             mAquatorXVPipe = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable);
    4.             ProcessStartInfo psi = new ProcessStartInfo(exePath, $"/anonymousPipe:{mAquatorXVPipe.GetClientHandleAsString()}");
    5.             psi.UseShellExecute = false;
    6.             mProcess = Process.Start(psi);
    7.             mAquatorXVPipe.DisposeLocalCopyOfClientHandle();
    8.             mProcess.WaitForInputIdle();
    9.             mAquatorXVWriter = new StreamWriter(mAquatorXVPipe);
    10.             mAquatorXVWriter.AutoFlush = true;
    11.             mAquatorXVWriter.WriteLine("SYNC");
    12.             mAquatorXVPipe.WaitForPipeDrain();
    13.  
    14.  
    15.             mAquatorXVWriter.WriteLine("Test");
    16.         }

    Here's the client app code:-
    C# Code:
    1. PipeStream mAquatorServerPipe;
    2.         StreamReader mAquatorServerReader;
    3.         public static void ListenForAquatorServer(StreamReader reader)
    4.         {
    5.             string input;
    6.             while ((input = reader.ReadLine()) != null)
    7.             {
    8.                 Console.WriteLine(input);
    9.             }
    10.         }
    11.         public void SetUpClientPipe(string serverHandle)
    12.         {
    13.             mAquatorServerPipe = new AnonymousPipeClientStream(PipeDirection.In, serverHandle);
    14.             mAquatorServerReader = new StreamReader(mAquatorServerPipe);
    15.             string input;
    16.             do
    17.             {
    18.                 input = mAquatorServerReader.ReadLine();
    19.             }
    20.             while (!input.StartsWith("SYNC"));
    21.  
    22.             Thread listener = new Thread(() => ListenForAquatorServer(mAquatorServerReader));
    23.             listener.Start();
    24.         }

    Note, all the examples I could find dispose of the pipes and streams as soon as they're used which doesn't work for me, I need the client app to continue running but be able to interrupt it to send messages so I'm keeping those objects alive and will explicitly dispose of them on shutdown.

    My next problem is that I'd like to be able to communicate with the client app in a strongly typed fashion. The original app used to do this to get an interface to work against:-
    VB.Net Code:
    1. ' Start AquatorXV, tell it to listen on the designated port, and wait for it to be ready
    2.             Dim psi As ProcessStartInfo = New ProcessStartInfo(location, $"/remoting:{port}")
    3.             psi.UseShellExecute = False
    4.             m_process = Process.Start(psi)
    5.             m_process.WaitForInputIdle()
    6.  
    7.             ' Create the one remote AquatorXVInterfaces object
    8.             If m_channel Is Nothing Then
    9.                 m_channel = New TcpChannel()
    10.                 ChannelServices.RegisterChannel(m_channel, True)
    11.             End If
    12.             Dim url As String = $"tcp://localhost:{port}/OSS.AquatorXV.Server"
    13.             Dim o As Object = Activator.GetObject(Type.GetType("AquatorXVInterfaces.IServer, AquatorXVInterfaces"), url)  '<<<This is the bit I need to mimic
    14.             m_aquatorXV = CType(o, AquatorXVInterfaces.IServer)

    So if I understand that right it uses Activator.GetObject to retrieve the client application from the uri and then cast it to a known interface to get strong typing. I'm looking for an equivalent of that which will work in Core using Anonymous Pipes. Is that possible or am I going to have to couch all the communication in untyped strings?
    Perhaps this isn't directly helping but... If you haven't invested too much time in this already grpc might be a better option.

    https://docs.microsoft.com/en-us/asp...aspnetcore-6.0 is a decent starting point.
    Last edited by PlausiblyDamp; May 5th, 2022 at 08:42 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width