注册众所周知的客户端类型时出现异常
我正在使用 .NET 远程处理在客户端和服务器之间进行通信。我实现了客户端应用程序,并在使用“RegisterWellKnownClientType”在客户端上注册对象时遇到了异常。例外情况是“尝试重定向已重定向的类型的激活”。仅当我第二次注册该对象时才会出现此异常。下面是说明它的代码:
IpcClientChannel clientChannel = new IpcClientChannel();
try
{
ChannelServices.RegisterChannel(clientChannel, true);
RemotingConfiguration.RegisterWellKnownClientType(typeof(RemoteTester), m_remoteUrl);
}
此代码在我的 ClientClass
中实现。最初,我创建一个对象,例如 ClientClass
的 myClient
来访问此类公开的方法。这还包括在客户端注册对象的方法。一旦这个对象(myClient
)被处理,我就创建另一个ClientClass
实例并访问在客户端注册该对象的方法。在此过程中,我遇到了上述异常。使用在客户端注册对象的方法来对服务器进行远程调用。
如果我在这里遗漏了什么,请告诉我。
谢谢, 穆斯塔克
I am using .NET remoting to communicate between the client and server. I implemented the client application and encountered an exception while registering an object on the client using "RegisterWellKnownClientType". The exception is "attempt to redirect activation of type which is already redirected". I get this exception only when I register the object for the second time. Here is the code that illustrates it:
IpcClientChannel clientChannel = new IpcClientChannel();
try
{
ChannelServices.RegisterChannel(clientChannel, true);
RemotingConfiguration.RegisterWellKnownClientType(typeof(RemoteTester), m_remoteUrl);
}
This code is implemented in my ClientClass
. Initially i create an object say myClient
of ClientClass
to access the methods exposed by this class. This also includes the method to register the object on the client. Once this object (myClient
) is disposed i create another instance of the ClientClass
and access the method which registers the object on the client. During this process i get the above mentioned exception. The method to register the object on the client is used in order to make remote calls to the server.
Let me know if I am missing anything here.
Thanks,
Mustaq
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
测试您是否已经注册了客户端类型,如下所示:
-Oisin
Test if you have already registered the client type like so:
-Oisin
IsWellKnownClientType(..,..) 此方法不返回 bool 值,
如果检查指定对象 System.Type 是否注册为众所周知的客户端类型, 则返回 WellKnownClientTypeEntry。如果 WellKnownClientTypeEntry 为 null,则不注册。
这是我解决问题的代码。希望它能帮助您...
WellKnownClientTypeEntry 条目 = RemotingConfiguration.IsWellKnownClientType(typeof(RemoteConverter));
如果(条目==空)
{
RemotingConfiguration.RegisterWellKnownClientType(typeof(RemoteConverter), "http://localhost:4000/ServiceURI");
}
RemoteConverter RemoteConverter = new RemoteConverter();
现在调用远程方法remoteConverter.RemoteMethod(.......)
谢谢。
IsWellKnownClientType(..,..) this methos is not returning bool value, it returns WellKnownClientTypeEntry
if checks whether the specified object System.Type is registered as a well-known client type. if WellKnownClientTypeEntry is null then not register.
Here is my code to solve the problem. hope it wiil help you...
WellKnownClientTypeEntry entry = RemotingConfiguration.IsWellKnownClientType(typeof(RemoteConverter));
if (entry == null)
{
RemotingConfiguration.RegisterWellKnownClientType(typeof(RemoteConverter), "http://localhost:4000/ServiceURI");
}
RemoteConverter remoteConverter = new RemoteConverter();
now call the remorte Methods remoteConverter.RemoteMethod(.......)
thank you.