# Wednesday, February 22, 2006

I'm creating a .NET 2.0 ASP.NET web service as a front end to several Windows Services (also built using .NET 2.0) and want to use IPC since the web service and the Windows Services will be running on the same machine.

I don't want to use XML configuration files. I want to do it in code. It works with a console app to the Windows Service, but the ASP.NET web service blows chunks.

Failed to connect to an IPC port:  Access Denied

Search. Search. Search. One clue about "authorizedGroup" = "Everyone" but no code. Tinker. Stumble. Search. Tinker. Finally. Here's the final result in the Windows Service server:

Dictionary<string, string> props = new Dictionary<string, string>();
props.Add("authorizedGroup", "Everyone");
props.Add("portName", "ServerPortName");
serverChannel = new IpcServerChannel(props, null);
ChannelServices.RegisterChannel(serverChannel, true);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalByRefObjectSubClass),
   "ServerAppName", WellKnownObjectMode.SingleCall);
serverChannel.StartListening(null);

With the client setup like this in the web service:

using System;
using System.Data;
using System.Configuration;
using System.Threading;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;
using MyRemotingInterfaces;

public class RemotingClientFactory
{
   private static Mutex mut = new Mutex();
   private static WellKnownClientTypeEntry remoteEntry;
   private static IpcClientChannel remoteChannel;
   private static string remoteUrl = "ipc://RemoteExampleRemoteServer/RemoteExampleRemote";

   static RemotingClientFactory() { }

   public static IMyRemoteObject CreateRemote()
   {
      if (remoteChannel == null || remoteEntry == null)
      {
         mut.WaitOne();
         try
         {
            if (remoteChannel == null)
            {
               remoteChannel = new IpcClientChannel();
               ChannelServices.RegisterChannel(remoteChannel, true);
            }
            if (remoteEntry == null)
            {
               remoteEntry =
                 new WellKnownClientTypeEntry(typeof(MyRemotingInterfaces.IMyRemoteObject),
                       remoteUrl);
               RemotingConfiguration.RegisterWellKnownClientType(remoteEntry);
            }
         }
         finally
         {
            mut.ReleaseMutex();
         }
      }
      try
      {
         IMyRemoteObject obj =
          
(IRemoteExampleRemote)Activator.GetObject(remoteEntry.ObjectType, remoteUrl);
         return obj;
      }
      catch(Exception e)
      {
         //TODO log then rethrow
         throw e;
      }
   }
}

And it works like a charm. It's not perfect, I'm sure. But it's a start. And it didn't seem like anyone had or wanted to post their solution to the newsgroups or anywhere else I could find.

Let me know if you find a better way or if this helps you. And good luck.

Monday, May 01, 2006 12:22:40 PM (Mountain Daylight Time, UTC-06:00)
Thanks very much for posting this. I had encountered the same lack of information about this that you had.
John A
Thursday, July 13, 2006 8:22:42 AM (Mountain Daylight Time, UTC-06:00)
good code
Friday, September 15, 2006 8:03:04 AM (Mountain Daylight Time, UTC-06:00)
IPC Remoting is new in .NET framework 2.0 and that's why the implementation and the documentation is not complete yet. When running the client IPC channel from an ASP page, you have to take care about the process model. In IIS 5.0 (Windows XP and 2000) the process is asp.net_wp.exe and run as user ASPNET. In IIS 6.0 (Windows 2003 server) the process is w3wp.exe and run as NETWORK SERVICE. Using ASPNET is ok for authorizedGroup but only with the IIS 5.0 process model. For some security reasons, using NETWORK SERVICE account doesn't work. IPC Remoting is designed for local use only. So, you have to create a dedicated account and use it like this:

Hashtable properties = new Hashtable();
properties.Add("name", "myclient");
properties.Add("useDefaultCredentials", "false");
properties.Add("domain", "mydomain");
properties.Add("username", "toto");
properties.Add("password", "xxxx");

ipcCh = new IpcClientChannel(properties, null);
ChannelServices.RegisterChannel(ipcCh);

A last thing, don't forget to put significant informations (like passwords) in a more secured place.
Yo
Friday, September 15, 2006 8:41:27 AM (Mountain Daylight Time, UTC-06:00)
Excellent addition/extension to the post. Thanks very much. -Tyler
Wednesday, September 27, 2006 1:38:29 AM (Mountain Daylight Time, UTC-06:00)
Hi!

Can I have your full code on this? I'm working on the window service and ipc remoting. I encontered problem with my code and can't fully applies the one you said above.

Thanks in advance

Rom
roman narciso
Wednesday, September 27, 2006 1:39:38 AM (Mountain Daylight Time, UTC-06:00)
My email address is roman.narciso@infonxx.com

Rom
roman narciso
Wednesday, September 27, 2006 8:59:35 AM (Mountain Daylight Time, UTC-06:00)
Rom,

Sadly the project belongs to a client, so I cannot provide it to you. I eventually abandoned IPC because it uses named pipes and I was making way too many connections and the system would throw an exception when the limit was exceeded.

The first thing to be sure (and you probably know this but it bears repeating) is to be sure that you are on the same machine. IPC is only supported when on the same server. This is of course the limitation of using named pipes.

The other thing to be sure of is permissions. There are a variety of issues there.

I wish you luck and if I can be of further assistance, please let me know.

-Tyler
Tuesday, December 04, 2007 3:41:26 PM (Mountain Standard Time, UTC-07:00)
Hello,

I am having major problems with something similar - is it possible to have the IIS running with Identity=Impersonate and call IPC Remoting and pass the impersonated credentials? I seem to either have to have it EnsureSecurity=False (no credentials get passed) or else I get access denied

Its driving me crazy so any help much appreciated


Cheers,


Dave
David Homer
Tuesday, December 04, 2007 4:01:15 PM (Mountain Standard Time, UTC-07:00)
Hi Dave,

It's been a while since I've worked with ASP.NET as a remoting client. If you're running IIS 6, you may think about having your app run under a unique application pool which runs under a specified identity. (See http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/f05a7c2b-36b0-4b6e-ac7c-662700081f25.mspx?mfr=true).

You may want to consider moving to WCF. I'm a latecomer to this .NET 3.0 stack, but I'm learning more each day and I have to say, I don't think I'll ever go back to plain old remoting. Look for me to blog about what I'm learning soon.

-Tyler
Comments are closed.