[.NET] События, сериализация и Remoting

agaaaa

Итак, сабж. Создаётся класс, наследующий MarshalByRefObject. В нём есть event. Требуется удалённо получать от него события.
Сервер

TcpServerChannel channel = new TcpServerChannel( 12647 );
ChannelServices.RegisterChannel( channel, false );
RemotingConfiguration.RegisterWellKnownServiceType( typeof( TEST "TEST", WellKnownObjectMode.Singleton );

Клиент
static void Main(string[] args)
{
TcpClientChannel channel = new TcpClientChannel( );
ChannelServices.RegisterChannel( channel );
RemotingConfiguration.RegisterWellKnownClientType( typeof( TEST "tcp://localhost:12647/TEST" );
TEST test = new TEST( );
test.OnString += new StringEventHandler( test_OnString );
test.String = "Hello, remoting!";
Console.WriteLine( "Press any key to exit..." );
Console.ReadKey( );
}
static void test_OnString(string str)
{
Console.WriteLine( str );
}

Клиент падает на test.OnString += new StringEventHandler( test_OnString ); с ошибкой доспупа Type System.DelegateSerializationHolder and the types derived from it (such as System.DelegateSerializationHolder) are not permitted to be deserialized at this security level.
Как это исправить и вообще реально ли получать события от такого удалённого объекта?

xz_post

попробуй задать у форматтера сериализации TypeFilterLevel = Full

agaaaa

Как?

psm-home

вот пример завалялся

ListDictionary channelProperties = new ListDictionary;
channelProperties.Add("port", 1111);
BinaryServerFormatterSinkProvider serverSinkProvider = new BinaryServerFormatterSinkProvider;
serverSinkProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
TcpChannel channel = new TcpChannel(channelProperties, null, serverSinkProvider);

agaaaa

А декларативно как?

agaaaa

Всё, спасибо, нашёл

Helga87

Кстати, ты события используй аккуратно. Потому что они не работают, если:
1. Клиент за NAT-ом или proxy (т.е. нет двусторонней связи между клиентом и сервером)
2. На сервере установлен клиент для Microsoft ISA Server.
И в некоторых других случаях.

xz_post

если декларативно через конфиг
<formatter
ref="FormatterReference"
type="FormatterSinkProviderType, FormatterAssembly"
customFormatterProperty="customProperty"
includeVersions="true"
strictBinding="false"
...typeFilterLevel="Low | Full"
/>

agaaaa

Сама аккуратность. ТОлько localhost

Helga87

Тогда лучше решения действительно сложно придумать.
Оставить комментарий
Имя или ник:
Комментарий: