Pergunta

I have established communication with a remote server..The remote server has exposed an event.When i try to subscribe for the event i get the exception with following stack trace

    [System.Reflection.TargetInvocationException] 
    = {"Exception has been thrown by the target of an invocation."}

    [System.Reflection.TargetInvocationException] 
    = {"Exception has been thrown by the target of an invocation."}
    at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
    at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark,
    Boolean throwOnFileNotFound, Boolean forIntrospection)
    at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
    at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)\r\n
    at System.Reflection.Assembly.Load(String assemblyString)
    at System.Reflection.MemberInfoSerializationHolder..ctor(SerializationInfo info, StreamingContext context)

    StackTrace          
    Server stack trace: 
    at System.RuntimeMethodHandle._SerializationInvoke(Object target, SignatureStruct& declaringTypeSig, SerializationInfo info, StreamingContext context)
    at System.Reflection.RuntimeConstructorInfo.SerializationInvoke(Object target, SerializationInfo info, StreamingContext context)
    at System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context) 
    at System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder holder)
    at System.Runtime.Serialization.ObjectManager.DoFixups()
    at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
    at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
    at System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryRequestMessage(String objectUri, Stream inputStream, Boolean bStrictBinding, TypeFilterLevel securityLevel)
    at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.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.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
    at Mycode.Method(EventHandler value)
    at Mysource.Initialize()

My code block is as follows: The configuration for remoting server is given below //code

TurnOffRemotingExceptionFiltering();

BinaryClientFormatterSinkProvider^ clientProvider = nullptr;
BinaryServerFormatterSinkProvider^ serverProvider = gcnew aryServerFormatterSinkProvider();
serverProvider->TypeFilterLevel = TypeFilterLevel::Full;
System::Collections::IDictionary^ props = gcnew Hashtable();
props["port"] = port;
String^ guid = System::Guid::NewGuid().ToString();
props["typeFilterLevel"] = TypeFilterLevel::Full;

//TcpChannel
channel = gcnew TcpChannel(props, clientProvider, serverProvider);
ChannelServices::RegisterChannel(channel, false);
props["name"] = guid;

void RemoteConnectionManager::TurnOffRemotingExceptionFiltering()
{
                 // Gets the assembly in which the 'System.Runtime.Remoting.RemotingConfiguration' is defined.
                Assembly^ remoting = Assembly::GetAssembly(RemotingConfiguration::typeid);

                // Gets the Type object of 'System.Runtime.Remoting.CustomErrorsModes' from assembly instance.
                Type^ customErrorsModes = remoting->GetType("System.Runtime.Remoting.CustomErrorsModes");

                // Gets the Type object of 'System.Runtime.Remoting.RemotingConfigHandler' from assembly instance.
                Type^ remotingConfigHandler = remoting->GetType("System.Runtime.Remoting.RemotingConfigHandler");

                // Gets details of '_errorMode' field.'_errorMode' indicates whether the server channels in 
                // this application domain return filtered or complete exception information to local or remote callers.
                FieldInfo^ errorMode = remotingConfigHandler->GetField("_errorMode",
                                        BindingFlags::Static | BindingFlags::NonPublic);

                // Gets details of 'Off' field.'System.Runtime.Remoting.CustomErrorsModes' is an Enumeration
                FieldInfo^ mode = customErrorsModes->GetField("Off");

                // Sets "Off" to get to get complete exception information 
                // from server channels to to local or remote callers.
                errorMode->SetValue(nullptr, mode->GetValue(nullptr));
            }
Foi útil?

Solução

In case of distributed systems we need a wrapper class to communicate with the server and the client..We cannot subscribe directly for an event without a wrapper class..This wrapper class acts as a medium to communicate with the client and the server.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top