IPC Port 'Access is denied'

来源:互联网 发布:真探 知乎 编辑:程序博客网 时间:2024/04/29 15:51
 HashTable table; // properties   //...   table.Add("authorizedGroup", "Everyone");                             table.Add("portName", name);   // etc   IpcChannel  channel = new IpcChannel(table, clientSink,   serverSink);

The solution was to add this to the IPC channel configuration:

  <channel ref="ipc" portName="xxxManager" authorizedGroup="NtGroup" />  Then to add the AspNet user to the NT authorised group. Thanks for Sahil Malik!http://codebetter.com/blogs/sahil.malik/archive/2005/07/20/129505.aspx
using  IpcChannel to replace IpcServerChannel.

//ClientBinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();IDictionary prop = new Hashtable();prop["portName"] = "Client";//This seemed to be the key property to allow us to not get the access denied. We added this to both the server and the clientprop["authorizedGroup"] = "Everyone"IpcChannel channel = new IpcChannel(prop, clientProv, serverProv);ChannelServices.RegisterChannel(channel, false);

 

//ServerBinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();IDictionary prop = new Hashtable();prop["portName"] = "Server";//This seemed to be the key property to allow us to not get the access denied. We added this to both the server and the clientprop["authorizedGroup"] = "Everyone"IpcChannel channel = new IpcChannel(prop, clientProv, serverProv);ChannelServices.RegisterChannel(channel, false);

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.