.NET 리모 팅을위한 onclientConnected 이벤트와 같은 것이 있습니까?
-
05-07-2019 - |
문제
내 서버에서 이와 같은 것을 사용하고 있습니다.
TcpServerChannel channel = new TcpServerChannel(settings.RemotingPort);
ChannelServices.RegisterChannel(channel, true);
RemotingServices.Marshal(myRemoteObject, "myRemoteObject");
원격 클라이언트가 myremoteobject에 연결할 때마다 스레드를 확인할 수 있도록 어떤 종류의 이벤트를 구독하고 싶습니다.
현재 나는 지저분한 myremoteobject의 모든 노출 된 원격 방법에서 승인 확인을하고 있습니다 ...
해결책
원격 응용 프로그램에서 고객이 먼저 승인 해야하는 특수 객체/인터페이스를 정의했습니다. 클라이언트가 원격 객체를 성공적으로 승인 한 경우 특수 객체가 반환됩니다. 그래서 당신은 한 곳에 승인이 있습니다.
이렇게 보입니다.
public interface IPortal
{
object SignIn(string name, string password);
}
public class Portal : MarshalByRefObject, IPortal
{
private object _remoteObject;
public Portal() {
_remoteObject = new RemoteObject();
}
public object SignIn(string name, string password)
{
// Authorization
// return your remote object
return _remoteObject;
}
}
응용 프로그램에서는 포털 객체를 호스팅합니다
TcpServerChannel channel = new TcpServerChannel(settings.RemotingPort);
ChannelServices.RegisterChannel(channel, true);
Portal portal = new Portal()
RemotingServices.Marshal(portal , "portal");
다른 팁
당신은 같은 것을 사용할 수 있습니다 포스트 쇼트 모든 방법에서 확인을 고려하려면 AOP 조언으로 수행하십시오. (클라이언트 연결이 아닌 방법을 노출시키는 클래스에 이것을 적용합니다.)
이 접근법은 원격으로 사용하는 모든 전송과 무관합니다. 리모컨 클래스의 모든 방법에 걸쳐 승인의 교차 절단 문제를 고려합니다.
제휴하지 않습니다 StackOverflow