title: .Net remoting error "Requested Service not found"
body: <p>I am trying to build a very simple .Net remoting connection and can't seem to figure out the magic incantation. </p>
  
  <p>I have a server side class that is meant to be a singleton and live for the duration of the service process.</p>
  
  <pre><code>public class MyRemoteServerClass : MarshalByRefObject
  {
      public void DoSomething()
      {
          System.Diagnostics.Trace.Assert(false);
      }
  
      public override object InitializeLifetimeService()
      {
          return null;
      }
  }
  </code></pre>
  
  <p>Based on my readings of .Net remoting, I wrote this code to instantiate and register the server class in the service:</p>
  
  <pre><code>    static void Main(string[] args)
      {
          MyRemoteServerClass server = new MyRemoteServerClass();
          TcpChannel channel = new TcpChannel(8080);
          ChannelServices.RegisterChannel(channel, false);
          string url = "tcp://localhost:8080/MyRemoteServerClass";
          RemotingServices.Marshal(server, url, server.GetType());
          System.Console.ReadLine();
      }
  </code></pre>
  
  <p>I wrote this code in the .Net winforms client to invoke the 'MyRemoteServerClass.DoSomething' function:</p>
  
  <pre><code>    private void button1_Click(object sender, EventArgs e)
      {
          string url = "tcp://localhost:8080/MyRemoteServerClass";
          ChannelServices.RegisterChannel(new TcpChannel(), false);
          MyRemoteServerClass root = Activator.GetObject(typeof(MyRemoteServerClass), url) as MyRemoteServerClass;
          root.DoSomething();
      }
  </code></pre>
  
  <p>The 'Activate.GetObject' call appears to get a proxy reference to the server 'MyRemoteServerClass' instance. However, when I call 'DoSomething' I get a "Requested Service not found" exception.</p>
  
  <p>{System.Runtime.Remoting.RemotingException: Requested Service not found</p>
  
  <p>Server stack trace: 
     at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage&amp; responseMsg, ITransportHeaders&amp; responseHeaders, Stream&amp; responseStream)</p>
  
  <p>Exception rethrown at [0]: 
     at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
     at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)
     at RemoteExampleServer.MyRemoteServerClass.DoSomething()
     at RemoteExampleClient.Form1.button1_Click(Object sender, EventArgs e) in c:\Aaron\RemoteExampleClient\Form1.cs:line 30} System.Exception {System.Runtime.Remoting.RemotingException}</p>
  
  <p>What am I doing wrong? Note, I've allowed access for these apps through the firewall (and I get the same behavior when I completely disable the firewall). I have no other security software on my computer.</p>
  
  <p>Thanks,</p>
  
  <p>Aaron</p>
  
  <p>PS. I'd prefer solutions that don't involve modifications to the 'App.config' xml. If at all possible, I'd like the .Net remote connection to be configured in code-space.</p>