[lnkForumImage]
TotalShareware - Download Free Software

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


 

John Vonesh

11/3/2004 7:07:00 PM

Hello,

I am working on a remoting project in VB.NET that uses interfaces to instantiate remote objects on the server. After browsing the web for a few days, I realize that you have probably heard one version of what I am going to ask at least a few hundred times. The one difference is, I have already added typeFilterLevel="Full" to my configuration file. So here is the error we are all so familiar with:
Type System.DelegateSerializationHolder and the types derived from it (such as System.DelegateSerializationHolder) are not permitted to be deserialized at this security level.

Here is my interface definition:
Public Interface IJobServer
Event JobEvent As JobEventHandler
Sub CreateJob(ByVal sDescription As String)
Sub UpdateJobState(ByVal nJobID As Int32, ByVal sUser As String, ByVal sStatus As String)
Function GetJobs() As ArrayList
End Interface
Public Delegate Sub JobEventHandler(ByVal sender As Object, ByVal args As JobEventArgs)

A custom EventArgs class:
<Serializable()> _
Public Class JobEventArgs : Inherits EventArgs
Public Enum ReasonCode
[NEW]
CHANGE
End Enum

Private m_Reason As ReasonCode
Private m_JobInfo As JobInfo

Public Sub New(ByVal NewJob As JobInfo, ByVal Reason As ReasonCode)
m_JobInfo = NewJob
m_Reason = Reason
End Sub

Public Property Job() As JobInfo
Get
Return m_JobInfo
End Get
Set(ByVal Value As JobInfo)
m_JobInfo = Value
End Set
End Property

Public ReadOnly Property Reason()
Get
Return m_Reason
End Get
End Property
End Class

And a JobInfo structure:
<Serializable()> _
Public Structure JobInfo
Public Sub New(ByVal nID As Int32, ByVal sDescription As String, ByVal sAssignedUser As String, ByVal sStatus As String)
JobID = nID
Description = sDescription
AssignedUser = sAssignedUser
Status = sStatus
End Sub

Public JobID As Int32
Public Description As String
Public AssignedUser As String
Public Status As String
End Structure

My Server code:
Imports System
Imports System.Runtime.Remoting

Public Class Host : Inherits System.Windows.Forms.Form
Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
Me.Close()
End Sub

Private Sub Host_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RemotingConfiguration.Configure("..\App.config")
End Sub
End Class

My Server Config File:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application name="JobsServer">
<service>
<wellknown mode="Singleton" type="JobServer.JobServerImpl, JobServer" objectUri="JobServer" />
</service>
<channels>
<channel ref="tcp" port="81">
<serverProviders>
<formatter ref="binary" typefilterLevel="Full" />
</serverProviders>
<clientProviders>
<formatter ref="binary" />
</clientProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>

My Client Code:
Imports System
Imports System.Runtime.Remoting
Imports JobLib

Public Class Client : Inherits System.Windows.Forms.Form

Private m_IJobServer As IJobServer
Private m_JobEventRepeater As JobEventRepeater
Private Function GetIJobServer() As IJobServer
RemotingConfiguration.Configure("..\App.config")
Dim obj As Object = RemotedObjects.GetObject(GetType(IJobServer))
Return DirectCast(obj, IJobServer)
End Function

Private Sub JobEventRepeater_JobEventHandler(ByVal sender As Object, ByVal args As JobEventArgs)
MessageBox.Show(args.Reason)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call m_IJobServer.CreateJob("My New Job")
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub

Private Sub Client_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
m_IJobServer = GetIJobServer()
m_JobEventRepeater = New JobEventRepeater(m_IJobServer)
AddHandler m_JobEventRepeater.JobEvent, AddressOf Me.JobEventRepeater_JobEventHandler
'AddHandler m_IJobServer.JobEvent, AddressOf m_JobEventRepeater.Handler
End Sub
End Class

My Remoted Objects class:
Imports System.Collections
Imports System.Runtime.Remoting

Class RemotedObjects
Private Shared _isInit As Boolean
Private Shared _wellKnownTypes As IDictionary

Public Shared Function GetObject(ByVal _type As Type) As Object
If Not _isInit Then Call InitTypeCache()
Dim Entry As WellKnownClientTypeEntry = DirectCast(_wellKnownTypes(_type), WellKnownClientTypeEntry)
If (Entry Is Nothing) Then Throw New RemotingException("Type not found!")
Return Activator.GetObject(Entry.ObjectType, Entry.ObjectUrl)
End Function

Public Shared Sub InitTypeCache()
_isInit = True
_wellKnownTypes = New Hashtable
For Each Entry As WellKnownClientTypeEntry In RemotingConfiguration.GetRegisteredWellKnownClientTypes
If Entry.ObjectType Is Nothing Then Throw New RemotingException("A configured type could not be found. Please check spelling")
_wellKnownTypes.Add(Entry.ObjectType, Entry)
Next
End Sub
End Class

And finally my client configuration file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application name="JobClient">
<client>
<wellknown type="JobLib.IJobServer, JobLib" url="tcp://localhost:81/JobServer" />
</client>
<channels>
<channel ref="tcp" port="0">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
<clientProviders>
<formatter ref="binary" />
</clientProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>

I have been hung up on this for about 10 days now and I feel like I have exhausted all my own resources to try and fix this. I have purchased Ingo's book, as well as Visual Basic .NET Programmers Cookbook all of which have been helpful, but the registration of the server side event is becoming more than a minor annoyance now.

Do you think you can help?

John Vonesh
Senior Developer
Tran-Tech Inc.

---
Posted using Wimdows.net NntpNews Component -

Post Made from http://www.DotNetJunkies.com/... Our newsgroup engine supports Post Alerts, Ratings, and Searching.
1 Answer

Ken Kolda

11/3/2004 8:08:00 PM

0

Here's one thing I see, but I don't know if this was just a typo when you
transcribed this to the posting: in your server's config file, you have
"typefilterLevel" instead of "typeFilterLevel".

Ken


"John Vonesh" <jvonesh@-NOSPAM-peacecorps.gov> wrote in message
news:Ow59bhdwEHA.2600@TK2MSFTNGP09.phx.gbl...
> Hello,
>
> I am working on a remoting project in VB.NET that uses interfaces to
instantiate remote objects on the server. After browsing the web for a few
days, I realize that you have probably heard one version of what I am going
to ask at least a few hundred times. The one difference is, I have already
added typeFilterLevel="Full" to my configuration file. So here is the error
we are all so familiar with:
> Type System.DelegateSerializationHolder and the types derived from it
(such as System.DelegateSerializationHolder) are not permitted to be
deserialized at this security level.
>
> Here is my interface definition:
> Public Interface IJobServer
> Event JobEvent As JobEventHandler
> Sub CreateJob(ByVal sDescription As String)
> Sub UpdateJobState(ByVal nJobID As Int32, ByVal sUser As String, ByVal
sStatus As String)
> Function GetJobs() As ArrayList
> End Interface
> Public Delegate Sub JobEventHandler(ByVal sender As Object, ByVal args As
JobEventArgs)
>
> A custom EventArgs class:
> <Serializable()> _
> Public Class JobEventArgs : Inherits EventArgs
> Public Enum ReasonCode
> [NEW]
> CHANGE
> End Enum
>
> Private m_Reason As ReasonCode
> Private m_JobInfo As JobInfo
>
> Public Sub New(ByVal NewJob As JobInfo, ByVal Reason As ReasonCode)
> m_JobInfo = NewJob
> m_Reason = Reason
> End Sub
>
> Public Property Job() As JobInfo
> Get
> Return m_JobInfo
> End Get
> Set(ByVal Value As JobInfo)
> m_JobInfo = Value
> End Set
> End Property
>
> Public ReadOnly Property Reason()
> Get
> Return m_Reason
> End Get
> End Property
> End Class
>
> And a JobInfo structure:
> <Serializable()> _
> Public Structure JobInfo
> Public Sub New(ByVal nID As Int32, ByVal sDescription As String, ByVal
sAssignedUser As String, ByVal sStatus As String)
> JobID = nID
> Description = sDescription
> AssignedUser = sAssignedUser
> Status = sStatus
> End Sub
>
> Public JobID As Int32
> Public Description As String
> Public AssignedUser As String
> Public Status As String
> End Structure
>
> My Server code:
> Imports System
> Imports System.Runtime.Remoting
>
> Public Class Host : Inherits System.Windows.Forms.Form
> Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuExit.Click
> Me.Close()
> End Sub
>
> Private Sub Host_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
> RemotingConfiguration.Configure("..\App.config")
> End Sub
> End Class
>
> My Server Config File:
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
> <system.runtime.remoting>
> <application name="JobsServer">
> <service>
> <wellknown mode="Singleton" type="JobServer.JobServerImpl,
JobServer" objectUri="JobServer" />
> </service>
> <channels>
> <channel ref="tcp" port="81">
> <serverProviders>
> <formatter ref="binary" typefilterLevel="Full" />
> </serverProviders>
> <clientProviders>
> <formatter ref="binary" />
> </clientProviders>
> </channel>
> </channels>
> </application>
> </system.runtime.remoting>
> </configuration>
>
> My Client Code:
> Imports System
> Imports System.Runtime.Remoting
> Imports JobLib
>
> Public Class Client : Inherits System.Windows.Forms.Form
>
> Private m_IJobServer As IJobServer
> Private m_JobEventRepeater As JobEventRepeater
> Private Function GetIJobServer() As IJobServer
> RemotingConfiguration.Configure("..\App.config")
> Dim obj As Object = RemotedObjects.GetObject(GetType(IJobServer))
> Return DirectCast(obj, IJobServer)
> End Function
>
> Private Sub JobEventRepeater_JobEventHandler(ByVal sender As Object,
ByVal args As JobEventArgs)
> MessageBox.Show(args.Reason)
> End Sub
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
> Call m_IJobServer.CreateJob("My New Job")
> End Sub
>
> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
> Me.Close()
> End Sub
>
> Private Sub Client_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
> m_IJobServer = GetIJobServer()
> m_JobEventRepeater = New JobEventRepeater(m_IJobServer)
> AddHandler m_JobEventRepeater.JobEvent, AddressOf
Me.JobEventRepeater_JobEventHandler
> 'AddHandler m_IJobServer.JobEvent, AddressOf
m_JobEventRepeater.Handler
> End Sub
> End Class
>
> My Remoted Objects class:
> Imports System.Collections
> Imports System.Runtime.Remoting
>
> Class RemotedObjects
> Private Shared _isInit As Boolean
> Private Shared _wellKnownTypes As IDictionary
>
> Public Shared Function GetObject(ByVal _type As Type) As Object
> If Not _isInit Then Call InitTypeCache()
> Dim Entry As WellKnownClientTypeEntry =
DirectCast(_wellKnownTypes(_type), WellKnownClientTypeEntry)
> If (Entry Is Nothing) Then Throw New RemotingException("Type not
found!")
> Return Activator.GetObject(Entry.ObjectType, Entry.ObjectUrl)
> End Function
>
> Public Shared Sub InitTypeCache()
> _isInit = True
> _wellKnownTypes = New Hashtable
> For Each Entry As WellKnownClientTypeEntry In
RemotingConfiguration.GetRegisteredWellKnownClientTypes
> If Entry.ObjectType Is Nothing Then Throw New
RemotingException("A configured type could not be found. Please check
spelling")
> _wellKnownTypes.Add(Entry.ObjectType, Entry)
> Next
> End Sub
> End Class
>
> And finally my client configuration file:
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
> <system.runtime.remoting>
> <application name="JobClient">
> <client>
> <wellknown type="JobLib.IJobServer, JobLib"
url="tcp://localhost:81/JobServer" />
> </client>
> <channels>
> <channel ref="tcp" port="0">
> <serverProviders>
> <formatter ref="binary" typeFilterLevel="Full" />
> </serverProviders>
> <clientProviders>
> <formatter ref="binary" />
> </clientProviders>
> </channel>
> </channels>
> </application>
> </system.runtime.remoting>
> </configuration>
>
> I have been hung up on this for about 10 days now and I feel like I have
exhausted all my own resources to try and fix this. I have purchased Ingo's
book, as well as Visual Basic .NET Programmers Cookbook all of which have
been helpful, but the registration of the server side event is becoming more
than a minor annoyance now.
>
> Do you think you can help?
>
> John Vonesh
> Senior Developer
> Tran-Tech Inc.
>
> ---
> Posted using Wimdows.net NntpNews Component -
>
> Post Made from http://www.DotNetJunkies.com/... Our newsgroup
engine supports Post Alerts, Ratings, and Searching.