By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,990 Members | 2,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,990 IT Pros & Developers. It's quick & easy.

Lease Sponsor and Infrastructure Exception

P: n/a
in re-reading something on .NET remoting I realized that I had done
nothing with lease sponsorship and renewal. so, I dug around in msdn2
and found this topic
http://msdn2.microsoft.com/library/6...us,vs.80).aspx.
However, in my testing I have come across a Security Exception that I
cannot overcome. The documentation seems to indicate an Infrastructure
permission being needed, but I have declaratively demanded this
permission... what am I missing?

***the exception***
Because of security restrictions, the type
System.Runtime.Remoting.ObjRef can not be accessed.
mscorlib

Server stack trace:
at
System.Runtime.Serialization.FormatterServices.Get SafeUninitializedObject(Type
type)
at
System.Runtime.Serialization.Formatters.Soap.Objec tReader.ParseObject(ParseRecord
pr)
at
System.Runtime.Serialization.Formatters.Soap.Objec tReader.Parse(ParseRecord
pr)
at
System.Runtime.Serialization.Formatters.Soap.SoapH andler.StartChildren()
at
System.Runtime.Serialization.Formatters.Soap.SoapP arser.ParseXml()
at System.Runtime.Serialization.Formatters.Soap.SoapP arser.Run()
at
System.Runtime.Serialization.Formatters.Soap.Objec tReader.Deserialize(HeaderHandler
handler, ISerParser serParser)
at
System.Runtime.Serialization.Formatters.Soap.SoapF ormatter.Deserialize(Stream
serializationStream, HeaderHandler handler)
at
System.Runtime.Remoting.Channels.CoreChannel.Deser ializeSoapRequestMessage(Stream
inputStream, Header[] h, Boolean bStrictBinding, TypeFilterLevel
securityLevel)
at
System.Runtime.Remoting.Channels.SoapServerFormatt erSink.ProcessMessage(IServerChannelSinkStack
sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders,
Stream requestStream, IMessage& responseMsg, ITransportHeaders&
responseHeaders, Stream& responseStream)

Exception rethrown at [0]:
at
System.Runtime.Remoting.Proxies.RealProxy.HandleRe turnMessage(IMessage
reqMsg, IMessage retMsg)
at
System.Runtime.Remoting.Proxies.RealProxy.PrivateI nvoke(MessageData&
msgData, Int32 type)
at System.Runtime.Remoting.Lifetime.ILease.Register(I Sponsor obj)
at RemotingClient.Client.Main() in C:\Documents and
Settings\cander\My Documents\Visual
Studio\Projects\RemotingLifetimes\RemotingClient\R emotingClient.vb:line
20

***the clinet code***
Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Lifetime
Imports System.Security
Imports System.Security.Permissions

Class Client

<MTAThread(), SecurityPermission(SecurityAction.LinkDemand,
Infrastructure:=True)> _
Public Shared Sub Main()

AppDomain.CurrentDomain.SetPrincipalPolicy(Princip al.PrincipalPolicy.WindowsPrincipal)

RemotingConfiguration.Configure("RemotingClient.ex e.config")
Dim CAObject As New ClientActivatedObject.RemoteObject()

Try
Dim ServerLease As ILease =
CType(RemotingServices.GetLifetimeService(CAObject ), ILease)
Dim sponsor As New MyClientSponsor()
ServerLease.Register(sponsor)
Catch ex As Exception
Console.WriteLine(ex.Message)
Console.WriteLine(ex.Source)
Console.WriteLine(ex.StackTrace)
Console.WriteLine(ex.HelpLink)
End Try

Console.WriteLine("1 Client-activated object: " &
CAObject.RemoteMethod())
Console.WriteLine("2 Client-activated object: " &
CAObject.RemoteMethod())
Console.WriteLine("3 Client-activated object: " &
CAObject.RemoteMethod())
Console.WriteLine("Press enter to exit client application")
Console.ReadLine()
End Sub

End Class

Public Class MyClientSponsor : Inherits MarshalByRefObject : Implements
ISponsor

Private lastrenewal As DateTime

Public Sub New()
lastrenewal = DateTime.Now
End Sub

Public Function Renewal(ByVal lease As
System.Runtime.Remoting.Lifetime.ILease) As System.TimeSpan Implements
System.Runtime.Remoting.Lifetime.ISponsor.Renewal

Console.WriteLine("I have been asked to renew the lease")
Dim latest As DateTime = DateTime.Now
Console.WriteLine("Time since last renewal: " &
(latest.Subtract(lastrenewal)).ToString())
lastrenewal = latest
Return (TimeSpan.FromSeconds(20))
End Function
End Class

***the config file (partial)***
<system.runtime.remoting>
<application>
<client url="http://localhost:8000">
<activated type="ClientActivatedObject.RemoteObject,
ClientActivatedObject"></activated>
</client>
<channels>
<channel ref="http" port="0">
<serverProviders>
<formatter ref="soap" typeFilterLevel="Full"/>
<formatter ref="binary" typeFilterLevel="Full"/>
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>

Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.