Also talk about event handling in DotNet Remoting

Source: Internet
Author: User
Tags dotnet mscorlib

Some friends mentioned the issue of event processing in Remoting. I Googled several useful articles.

Dotnet Remoting event handling
Http://blog.joycode.com/joe/archive/2004/11/09/38437.aspx

Create a distributed application architecture based on Microsoft. NET Remoting
Lu Yan
Http://www.microsoft.com/china/community/Column/62.mspx

The idea is very simple. If you imitate and write one, it is still very easy to make mistakes.

General idea:
The premise of the event subscription and publishing model is that the program must be stateful. This is important because http web service cannot directly implement the event model.

For Remoting events, you must also ensure that the remote object is stateful.
So if you use the server to activate it, you mustSingletonModel. If singlecall is used, you will find that the program debugging is normal. The root cause of the event handler cannot be executed :)

It is easy for beginners to encounter errors.

An unhandled exception of type 'System. Security. securityexception' occurred in mscorlib. dll

Additional information: Type System. DelegateSerializationHolder and the types derived from it (such as System. DelegateSerializationHolder) are not permitted to be deserialized at this security level.

This problem has been explained by the bad guy, as long as the TypeFilterLevel Of The Formatter channel in the Channel sink of the server is configured in the program or hard encoding is set to Full.

For example, the Code
Vb.net

Dim chan2 As HttpChannel
Chan2 = New HttpChannel (8086)

Dim ic As IServerChannelSink = chan2.ChannelSinkChain
While Not (ic Is Nothing)

If TypeOf (ic) Is SoapServerFormatterSink Then
CType (ic, SoapServerFormatterSink). TypeFilterLevel = Runtime. Serialization. Formatters. TypeFilterLevel. Full
End If
If TypeOf (ic) Is BinaryServerFormatterSink Then
CType (ic, BinaryServerFormatterSink). TypeFilterLevel = Runtime. Serialization. Formatters. TypeFilterLevel. Full
End If
Ic = ic. NextChannelSink
End While

C #

HttpChannel chan2 = new HttpChannel (8086 );

IServerChannelSink SC = chan2.ChannelSinkChain;
While (SC! = Null)
{
If (SC is BinaryServerFormatterSink)
{
(BinaryServerFormatterSink) SC). TypeFilterLevel = TypeFilterLevel. Full;
}

If (SC is SoapServerFormatterSink)
{
(SoapServerFormatterSink) SC). TypeFilterLevel = TypeFilterLevel. Full;
}

SC = SC. NextChannelSink;
}

Of course, you can set it on the server.

Another easy mistake is:

N unhandled exception of type 'System. Runtime. Remoting. remotingexception' occurred in mscorlib. dll

Additional information: This remoting proxy has no channel sink which means either the server has no registered server channels that are listening, or this application has no suitable client channel to talk to the server.

In this case, you only need to change the channel Port Number of the client to 0 so that the system can "Toss" freely.

Dim chan As HttpChannel
Chan = New HttpChannel (0)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.