[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

Re: Remoting event stopped working when No-Touch Deployment were used

Sunny

7/27/2004 10:17:00 PM

Hi Niklas,

can you provide a short but complete example. Read this to see what I
mean:

http://www.yoda.arachsys.com/csharp/com...

Sunny

In article <143F3352-F2B9-41CF-8531-A5AE2908E8D3@microsoft.com>,
Niklas@discussions.microsoft.com says...
> Hi
> I have created a server and a client using remoting. Server is using Singleton. I have a timer in the server which raises an event with the server time. Clients can subscribe to this event so they can display the current server time. This works fine when the client is started as a Window application, but when the application is started thru the intranet the application do not get any events. The remoting is still working becasue I can use the server functions. Client
and server are signed with a Strong Name and the Strong Name give the application Full Trust on the machine.
> Why are events not working when No-Touch Deployment is used over a intranet?
> Regards
> /Niklas
>
1 Answer

Niklas

7/30/2004 6:05:00 AM

0

Hi
Now I have an example I can show you.

The Client server communication woks fine if the are started as two console applications. You can get a time thru the function and you can get time from the events.
If you connect to the server by a No-toch client over the intranet the function deliver the time but the event throws an exception on the server , see below. What I have read you need to have Full Trust if remoting is going to be used thru No-touch, so if the function works the permissions is OK. I have used a Strong Name to accomplice this. The code is compiled on a computer with only Framework v1.0 installed. The client is a computer with Framework 1.0 and the server have both v1.0 and v1.1 installed. What am I doing wrong?

Another question. If I connect thru No-touch the connect to the server takes 4 minutes, but if I use the console client the connection is immediate. Why is it a delay if I use the intranet?

I used the object Communicator to take care of the event from the server becasue if I use the Client you have to have the client assembly on the server which I don't want. Is it poosible to do this in another way?

Regards
/Niklas

C:\Temp\RemotingServer>Server.exe
Server started. Hit enter to close server.
Sending event: 15:23

Unhandled Exception: System.Runtime.Remoting.RemotingException: An error occurre
d while processing the request on the server: Request for the permission of type
System.Security.Permissions.SecurityPermission, mscorlib, Version=1.0.3300.0, C
ulture=neutral, PublicKeyToken=b77a5c561934e089 failed.

Server stack trace:
at System.Runtime.Remoting.Channels.Tcp.TcpSocketHandler.ReadToEndOfHeaders(B
aseTransportHeaders headers)
at System.Runtime.Remoting.Channels.Tcp.TcpClientSocketHandler.ReadHeaders()
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage
(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITranspor
tHeaders& responseHeaders, Stream& responseStream)
at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMess
age(IMessage msg)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
at Definitions.Communicator.SendObjectMessageToClientArrived(IServerInformati
on ServerInformation)
at Server.Server.SendTimeToClients(Object stateInfo)
Sending event: 15:23

Unhandled Exception: System.Runtime.Remoting.RemotingException: An error occurre
d while processing the request on the server: Request for the permission of type
System.Security.Permissions.SecurityPermission, mscorlib, Version=1.0.3300.0, C
ulture=neutral, PublicKeyToken=b77a5c561934e089 failed.

Server stack trace:
at System.Runtime.Remoting.Channels.Tcp.TcpSocketHandler.ReadToEndOfHeaders(B
aseTransportHeaders headers)
at System.Runtime.Remoting.Channels.Tcp.TcpClientSocketHandler.ReadHeaders()
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage
(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITranspor
tHeaders& responseHeaders, Stream& responseStream)
at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMess
age(IMessage msg)

Client code, project 1:


Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Lifetime
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Imports Definitions.Interfaces
Imports Microsoft.VisualBasic

Public Class Client

#Const CompileForVersion1_1 = True

Private m_clientChannel As System.Runtime.Remoting.Channels.Tcp.TcpChannel
Private m_server As IServer = Nothing
Private m_communicator As New Definitions.Communicator
Private m_computerName As String

Shared Sub Main(ByVal CmdArgs() As String)
Dim client As Client
Dim command As String

If (CmdArgs.Length > 0) Then
client = New Client(CmdArgs(0))
Else
client = New Client
End If
Help()

Try
Do While True
command = Console.ReadLine.ToLower
Select Case command
Case "c"
client.ConnectToServer()
Case "d"
client.DisconnectFromServer()
Case "t"
Console.WriteLine(client.m_server.GetServerTime())
Case "exit"
client.DisconnectFromServer()
Console.WriteLine("Closing client")
Exit Do
Case "ce"
client.ConnectToServerEvent()
Case "de"
client.DisconnectFromServerEvent()
Case Else
Console.WriteLine(command & " is not a valid command")
Help()
End Select
Loop
Catch ex As Exception
Console.WriteLine(ex.ToString)
Console.WriteLine("Hit enter to exit application.")
Console.ReadLine()
Finally
client.DisconnectFromServer()
End Try

End Sub

Private Shared Sub Help()
Console.WriteLine("Commands:" & vbCrLf & "c = connect to server" & vbCrLf & "d = disconnect to server" & vbCrLf & _
"ce = connect to server event" & vbCrLf & "de = disconnect from server event" & vbCrLf & "t = get server time" & vbCrLf & _
"exit = close client")
End Sub

Public Sub New()

End Sub

Public Sub New(ByVal computerName As String)
m_computerName = computerName
End Sub

Private Sub ConnectToServer()
If (m_computerName Is Nothing) Then
ConnectToServer("tcp://" & RemotingAddress & ":" & RemotingPort & "/" & ServerUriName)
Else

End If

End Sub

Private Sub ConnectToServer(ByVal Uri As String)
#If CompileForVersion1_1 Then
Dim clientProvider As New BinaryClientFormatterSinkProvider
Dim serverProvider As New BinaryServerFormatterSinkProvider
serverProvider.TypeFilterLevel = Runtime.Serialization.Formatters.TypeFilterLevel.Full
Dim properties As IDictionary = New Hashtable
properties("port") = 0
Dim uniqueName As String = System.Guid.NewGuid().ToString()
properties("name") = uniqueName
properties("typeFilterLevel") = Runtime.Serialization.Formatters.TypeFilterLevel.Full
m_clientChannel = New Tcp.TcpChannel(properties, clientProvider, serverProvider)
#Else
m_clientChannel = New System.Runtime.Remoting.Channels.Tcp.TcpChannel(0)
#End If
ChannelServices.RegisterChannel(m_clientChannel)
m_server = CType(Activator.GetObject(GetType(IServer), Uri), IServer)

Console.WriteLine("Connected to " & Uri)
End Sub

Private Sub DisconnectFromServer()
If (Not m_clientChannel Is Nothing) Then
Try
ChannelServices.UnregisterChannel(m_clientChannel)
Catch ex As Exception
Console.WriteLine(ex.ToString)
End Try
m_clientChannel = Nothing
m_server = Nothing

Console.WriteLine("Disconnected from server")
End If
End Sub

Private Sub ConnectToServerEvent()
'AddHandler m_server.SendMessageToClient, AddressOf DisplayServerTime
'AddHandler m_server.SendObjectMessageToClient, AddressOf DisplayServerTime
'AddHandler m_server.SendObjectMessageToClient, AddressOf Definitions.Communicator.DisplayServerTime

AddHandler m_communicator.SendObjectMessageToClient, AddressOf DisplayServerTime
AddHandler m_server.SendObjectMessageToClient, AddressOf m_communicator.SendObjectMessageToClientArrived

'Dim msd As Definitions.Interfaces.SendObjectMessageToClient
'msd = AddressOf DisplayServerTime
'AddHandler m_server.SendObjectMessageToClient, msd

Console.WriteLine("Connected to server event")
End Sub

Private Sub DisconnectFromServerEvent()
'RemoveHandler m_server.SendMessageToClient, AddressOf DisplayServerTime
'RemoveHandler m_server.SendObjectMessageToClient, AddressOf DisplayServerTime
'RemoveHandler m_server.SendObjectMessageToClient, AddressOf Definitions.Communicator.DisplayServerTime

RemoveHandler m_communicator.SendObjectMessageToClient, AddressOf DisplayServerTime
RemoveHandler m_server.SendObjectMessageToClient, AddressOf m_communicator.SendObjectMessageToClientArrived

Console.WriteLine("Disconnected from server event")
End Sub

Public Sub DisplayServerTime(ByVal ServerTime As String)
Console.WriteLine(ServerTime)
End Sub

Public Sub DisplayServerTime(ByVal ServerInfo As IServerInformation)
Console.WriteLine("(By object) Server (" & ServerInfo.ComputerName & ") time is " & ServerInfo.Time)
End Sub


End Class


Definition code (do not forget to add a remoting address), project 2:

Public Class Interfaces
#Const CompileForVersion1_1 = True

Public Const RemotingPort As Integer = 5000
Public Const ServerUriName As String = "TestEventServer"
Public Const RemotingAddress As String = "???"

Public Interface IServer
Function GetServerTime() As String
Event SendMessageToClient(ByVal Message As String)
Event SendObjectMessageToClient(ByVal ServerInformation As IServerInformation)
End Interface

Public Interface IServerInformation
ReadOnly Property [Time]() As String
ReadOnly Property [Date]() As String
ReadOnly Property ComputerName() As String
End Interface

End Class

Public Class Communicator
Inherits MarshalByRefObject

Public Shared Sub DisplayServerTime(ByVal ServerInfo As Interfaces.IServerInformation)
Console.WriteLine("(By object) Server (" & ServerInfo.ComputerName & ") time is " & ServerInfo.Time)
End Sub

Event SendObjectMessageToClient(ByVal ServerInformation As Interfaces.IServerInformation)

Public Sub SendObjectMessageToClientArrived(ByVal ServerInformation As Interfaces.IServerInformation)
RaiseEvent SendObjectMessageToClient(ServerInformation)
End Sub
End Class


Server code, project 3:


Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Lifetime
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Imports Definitions.Interfaces

Public Class Server
Inherits MarshalByRefObject
Implements IServer, IDisposable

#Const CompileForVersion1_1 = True

Public Event SendMessageToClient(ByVal Message As String) Implements IServer.SendMessageToClient
Public Event SendObjectMessageToClient(ByVal ServerInformation As IServerInformation) Implements IServer.SendObjectMessageToClient

Private m_sendEventTimer As System.Threading.Timer
Private m_serverChannel As TcpChannel = Nothing
Private m_objRefServer As ObjRef = Nothing

Shared Sub Main()
Dim server As Server
Try
server = New Server
Console.WriteLine("Server started. Hit enter to close server.")
Console.ReadLine()
Catch ex As Exception
Console.WriteLine(ex.ToString)
Console.WriteLine("Hit enter to exit application.")
Console.ReadLine()
Finally
If (Not server Is Nothing) Then server.Dispose()
End Try
End Sub

Public Sub New()
#If CompileForVersion1_1 Then
Dim clientProvider As BinaryClientFormatterSinkProvider
Dim serverProvider As New BinaryServerFormatterSinkProvider
serverProvider.TypeFilterLevel = Runtime.Serialization.Formatters.TypeFilterLevel.Full
Dim properties As IDictionary = New Hashtable
properties("port") = RemotingPort
properties("typeFilterLevel") = Runtime.Serialization.Formatters.TypeFilterLevel.Full
m_serverChannel = New Channels.Tcp.TcpChannel(properties, clientProvider, serverProvider)
#Else
m_serverChannel = New Channels.Tcp.TcpChannel(RemotingPort)
#End If
ChannelServices.RegisterChannel(m_serverChannel)
m_objRefServer = RemotingServices.Marshal(Me, ServerUriName)

Dim timerDelegate As System.Threading.TimerCallback = AddressOf SendTimeToClients
m_sendEventTimer = New System.Threading.Timer(timerDelegate, Nothing, 500, 1000)
End Sub

Protected Overloads Sub Dispose() Implements IDisposable.Dispose
RemotingServices.Disconnect(Me)
m_objRefServer = Nothing
ChannelServices.UnregisterChannel(m_serverChannel)
m_serverChannel = Nothing
End Sub

Public Overrides Function InitializeLifetimeService() As Object
Return Nothing
End Function

Public Function GetServerTime() As String Implements IServer.GetServerTime
Return "(Function) Server (" & Environment.MachineName & ") time is " & System.DateTime.Now.ToString
End Function

Private Sub SendTimeToClients(ByVal stateInfo As Object)
If (Not SendMessageToClientEvent Is Nothing) Then
RaiseEvent SendMessageToClient("(Event) Server (" & Environment.MachineName & ") time is " & System.DateTime.Now.ToString)
End If
If (Not SendObjectMessageToClientEvent Is Nothing) Then
Console.WriteLine("Sending event: " & DateTime.Now.ToShortTimeString.ToString)
RaiseEvent SendObjectMessageToClient(CType(New ServerInformation, IServerInformation))
End If
End Sub

End Class

'<Serializable()> _
Public Class ServerInformation
Inherits MarshalByRefObject
Implements IServerInformation

Private m_time As String = String.Empty
Private m_date As String = String.Empty
Private m_computerName As String = String.Empty

Friend Sub New()
Dim currentTime As DateTime
currentTime = DateTime.Now
m_time = currentTime.ToLongTimeString
m_date = currentTime.ToLongDateString
m_computerName = Environment.MachineName
End Sub

Public ReadOnly Property [Time]() As String Implements IServerInformation.Time
Get
Return m_time
End Get
End Property

Public ReadOnly Property [Date]() As String Implements IServerInformation.Date
Get
Return m_date
End Get
End Property

Public ReadOnly Property ComputerName() As String Implements IServerInformation.ComputerName
Get
Return m_computerName
End Get
End Property

End Class

PS Do not forget to sign the projects with a Strong Name and give the computers Full Trust.

"Sunny" wrote:

> Hi Niklas,
>
> can you provide a short but complete example. Read this to see what I
> mean:
>
> http://www.yoda.arachsys.com/csharp/com...
>
> Sunny
>
> In article <143F3352-F2B9-41CF-8531-A5AE2908E8D3@microsoft.com>,
> Niklas@discussions.microsoft.com says...
> > Hi
> > I have created a server and a client using remoting. Server is using Singleton. I have a timer in the server which raises an event with the server time. Clients can subscribe to this event so they can display the current server time. This works fine when the client is started as a Window application, but when the application is started thru the intranet the application do not get any events. The remoting is still working becasue I can use the server functions. Client
> and server are signed with a Strong Name and the Strong Name give the application Full Trust on the machine.
> > Why are events not working when No-Touch Deployment is used over a intranet?
> > Regards
> > /Niklas
> >
>






Manage Your Profile |Legal |Contact Us |MSDN Flash Newsletter