remoting (acces denied)

Richnl

Well-known member
Joined
Mar 20, 2007
Messages
93
Programming Experience
Beginner
I succesfully did some remoting between applications. (the protocol is ipc)
Now that I want a windows service to host the remote object,

I get an acces denied error??

Do I need some additional settings for it to work in a w-service?
I may have found one clue, but I don't yet know how to implement it, or if it will work at all?
"authorizedGroup"..?
Anyway,this is the server side code sofar
VB.NET:
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System[/SIZE]
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Runtime.Remoting[/SIZE]
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Runtime.Remoting.Channels[/SIZE]
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Runtime.Remoting.Channels.Ipc[/SIZE]
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] RemoteObject[/SIZE]
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Timers[/SIZE]
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Threading[/SIZE]
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Diagnostics[/SIZE]
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Runtime.InteropServices[/SIZE]
 
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] TrafficService[/SIZE]
 
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]WithEvents[/COLOR][/SIZE][SIZE=2] m_Timer [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Timers.Timer[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] thdServer [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Thread[/SIZE]
 
[SIZE=2]#[/SIZE][SIZE=2][COLOR=#0000ff]Region[/COLOR][/SIZE][SIZE=2][COLOR=#a31515]"Event Handlers"[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]Protected[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Overrides[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] OnStart([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] args() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#008000]' Add code here to start your service. This method should set things[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' in motion so your service can do its work.[/COLOR][/SIZE]
[SIZE=2]thdServer = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Thread([/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] ThreadStart([/SIZE][SIZE=2][COLOR=#0000ff]AddressOf[/COLOR][/SIZE][SIZE=2] ServerThread))[/SIZE]
[SIZE=2]thdServer.Start()[/SIZE]
[SIZE=2]m_Timer.Interval = 900000 [/SIZE][SIZE=2][COLOR=#008000]'1800000[/COLOR][/SIZE]
[SIZE=2]m_Timer.Start()[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]Protected[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Overrides[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] OnStop()[/SIZE]
[SIZE=2][COLOR=#008000]' Add code here to perform any tear-down necessary to stop your service.[/COLOR][/SIZE]
[SIZE=2]m_Timer.Stop()[/SIZE]
[SIZE=2]ChannelServices.UnregisterChannel(ChannelServices.GetChannel([/SIZE][SIZE=2][COLOR=#a31515]"serverchannel"[/COLOR][/SIZE][SIZE=2]))[/SIZE]
[SIZE=2]thdServer.Abort()[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] m_Timer_Elapsed([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Timers.ElapsedEventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] m_Timer.Elapsed[/SIZE]
[SIZE=2]Beep()[/SIZE]
[SIZE=2]Beep()[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
[SIZE=2]#[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Region[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'Event Handlers[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] ServerThread()[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] serverChannel [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] IChannel = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] IpcServerChannel([/SIZE][SIZE=2][COLOR=#a31515]"serverchannel"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"msg"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]ChannelServices.RegisterChannel(serverChannel, [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]RemotingConfiguration.RegisterWellKnownServiceType( _[/SIZE]
[SIZE=2][COLOR=#0000ff]GetType[/COLOR][/SIZE][SIZE=2](RemObject), [/SIZE][SIZE=2][COLOR=#a31515]"msgAlerter"[/COLOR][/SIZE][SIZE=2], WellKnownObjectMode.Singleton)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE]

thanks in adv , Richard
 
Last edited:
from bits and pieces

I have constructed this for the serverside

I'am not exactly sure if this is actually going to work

VB.NET:
sub test
[SIZE=2] 
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] serverProv [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] BinaryServerFormatterSinkProvider = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] _
BinaryServerFormatterSinkProvider()
serverProv.TypeFilterLevel = _
Runtime.Serialization.Formatters.TypeFilterLevel.Full
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] props [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] IDictionary = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Hashtable
props.Add([/SIZE][SIZE=2][COLOR=#a31515]"port"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"msg"[/COLOR][/SIZE][SIZE=2])
props.Add([/SIZE][SIZE=2][COLOR=#a31515]"secure"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE][SIZE=2])
props.Add([/SIZE][SIZE=2][COLOR=#a31515]"impersonate"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE][SIZE=2])
props.Add([/SIZE][SIZE=2][COLOR=#a31515]"authorizedGroup"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"Everyone"[/COLOR][/SIZE][SIZE=2])
props.Add([/SIZE][SIZE=2][COLOR=#a31515]"portName"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"serverchannel"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] serverChannel [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] IpcServerChannel = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] IpcServerChannel(props, serverProv)
ChannelServices.RegisterChannel(serverChannel, [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE][SIZE=2])
RemotingConfiguration.RegisterWellKnownServiceType( _
[/SIZE][SIZE=2][COLOR=#0000ff]GetType[/COLOR][/SIZE][SIZE=2](RemObject), [/SIZE][SIZE=2][COLOR=#a31515]"msgAlerter"[/COLOR][/SIZE][SIZE=2], WellKnownObjectMode.Singleton)[/SIZE]
end sub
[SIZE=2]
[/SIZE]
 
I found that setting authorizedGroup to Users or Everyone worked with my service. How about you, did you find the time to try out the code you posted yet?

'port' and 'impersonate' properties doesn't operate on IPC channels, see Channel and Formatter Configuration Properties. It looks as if you have port name and channel name mixed up. You don't have to specify a sinkprovider if you don't have anything to add to it, use 'Nothing' keyword and the default is used.
A look at your service code also, why do you call the remoting configuration on a different thread? It doesn't harm, but also serves no purpose.
 
I will make some changes
I used some of this code and this code, some of this

It actually worked - not at all -

I could't get the program and the service removed anymore
I had to go into the registry to remove some keys

Al because off some IO exception

-As for the thread, I thought I could use it like this to stop the server from within the service without stopping the service itself.

-about the impersonate stuff
A lot has been set about it, all of wich the local system supposedly does't recognize the user. Even on this forum, somebody made a complicated api call to correct this. All of wich had to do with ipc on a local machine.

I will follow your advice
I hope it doesn't crash again:eek:
 
I changed the server side to this
I assume the client side has to have the same code?

VB.NET:
sub test
 
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] props [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] IDictionary = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Hashtable
props([/SIZE][SIZE=2][COLOR=#a31515]"name"[/COLOR][/SIZE][SIZE=2]) = [/SIZE][SIZE=2][COLOR=#a31515]"msgAlerter"
[/COLOR][/SIZE][SIZE=2]props([/SIZE][SIZE=2][COLOR=#a31515]"portName"[/COLOR][/SIZE][SIZE=2]) = [/SIZE][SIZE=2][COLOR=#a31515]"msg"
[/COLOR][/SIZE][SIZE=2]props([/SIZE][SIZE=2][COLOR=#a31515]"authorizedGroup"[/COLOR][/SIZE][SIZE=2]) = [/SIZE][SIZE=2][COLOR=#a31515]"Everyone"[/COLOR][/SIZE][SIZE=2] [/SIZE]
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] serverChannel [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] IpcServerChannel(props, [/SIZE][SIZE=2][COLOR=#0000ff]Nothing[/COLOR][/SIZE][SIZE=2])
ChannelServices.RegisterChannel(serverChannel, [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE][SIZE=2])
RemotingConfiguration.RegisterWellKnownServiceType( _
[/SIZE][SIZE=2][COLOR=#0000ff]GetType[/COLOR][/SIZE][SIZE=2](RemObject), [/SIZE][SIZE=2][COLOR=#a31515]"msgAlerter"[/COLOR][/SIZE][SIZE=2], WellKnownObjectMode.Singleton)[/SIZE]
[SIZE=2][/SIZE] 
[SIZE=2]end sub[/SIZE]
[SIZE=2]
[/SIZE]
 
one more error again, something with unmapped identity
my best guess is that I had to Import a namespace?

imports system security.identity

See screenshots
 

Attachments

  • Remoting Error.JPG
    Remoting Error.JPG
    147 KB · Views: 31
  • Error detail.JPG
    Error detail.JPG
    153.1 KB · Views: 29
In your (Dutch?) Windows the 'Everyone' group is perhaps different language, try this code to see and use that group string:
VB.NET:
'this code use namespace [SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Security.Principal[/SIZE]
 
Dim sid As New SecurityIdentifier(WellKnownSidType.WorldSid, Nothing)
Dim ntAccountName As String = sid.Translate(GetType(NTAccount)).ToString()
I found the code from another international user having the exact same problem (and solved by using a localized group).
 
thanks, I will try that

It never came up with me, because I have an english version of XP pro
But nevertheless, I will give it a go

In the meantime, I was busy making a testproject
Thought with all the errors I got, I may have corrupted something, - read below

While not having a better method yet, I have to remove some keys to get rid of the malfunctioning service and startup the computer again.
The uninstaller does not seem to work anymore.

I wil get back to you
 
I run an English version too, and here the names are "Everyone" and "Users" that I have tested. Both secure and not secure channel cause no problem with this here.

A crashing service should not cause any problem to uninstall it. Also you don't have to use a install project to install/uninstall during development, just use the .Net command-line utility InstallUtil.exe. It exist in folder "c:\windows\microsoft.net\framework\v2.0.50727" or included in environment path if you use the Visual Studio Command Prompt. To install/uninstall the service use these commands:
InstallUtil "windows service1.exe"
InstallUtil -u "windows service1.exe"
You can run these commands directly from the development Release folder.

Another comment about your "threading", OnStop you call thdServer.Abort() - you do realize the this thread was finished a millisecond after it was started? Still it makes no harm, but it serves no purpose.
 
i'ts indeed a different name

- "Iedereen" in Dutch -

it worked - Don't laugh - I actually wasn't aware the system used the Dutch language, - see post 9.

Thanks John
 
Last edited:

Similar threads

Back
Top