0
here과 같은 작업을 동적으로 추가하는 WCF 서비스 계약 (IService1)이 있습니다. 내가 가지고있는 것이 모두 IService1 투명 프록시이고 IClientChannel이 ClientChannelFactory를 통해 생성되었을 때 어떻게 클라이언트 측에서 동적으로 추가 된 작업을 호출 할 수 있습니까?서비스 계약에 동적으로 추가 된 작업 호출
업데이트
투명 프록시가 this method를 사용하여 ChannelFactory에에서 반환에서 나는 RealProxy를 얻을 수 있습니다.
var realProxy = System.Runtime.Remoting.RemotingServices.GetRealProxy(transparentProxy);
IT는 동적으로 추가 메소드를 호출에 프록시를 속여 가짜 메시지와 함께
realyProxy.Invoke(IMessage)
를 호출 할 수 있을까요? ,
// this is your base interface
[ServiceContract]
public interface ILoginService
{
[OperationContract(Action = "http://tempuri.org/LoginService/Login", Name = "Login")]
bool Login(string userName, string password);
}
[ServiceContract]
public interface IExtendedInterface : ILoginService
{
[OperationContract(Action = "http://tempuri.org/LoginService/Ping", Name="Ping")]
DateTime Ping();
}
class Program
{
static void Main(string[] args)
{
IExtendedInterface channel = null;
EndpointAddress endPointAddr = new EndpointAddress("http://localhost/LoginService");
BasicHttpBinding binding = new BasicHttpBinding();
channel = ChannelFactory<IExtendedInterface>.CreateChannel(binding, endPointAddr);
if (channel.Login("test", "Test"))
{
Console.WriteLine("OK");
}
DateTime dt = channel.Ping();
Console.WriteLine(dt.ToString());
}
}
나는이 솔루션은 다양한 서비스를 통해 재사용되고 싶어하기 때문에 이것은, 수용 가능한 해결책이 아니다 :
과 같은 클라이언트를 만들 : – m0sa
"모든 서비스 인터페이스가 추가 메서드가 정의 된 인터페이스에서 상속되어야한다는 생각은 마음에 들지 않습니다." 내 제안 된 솔루션이 당신 에게이 제약 조건을 부과하지 않습니다. 간단하게 서비스 인터페이스를 사용하고 동적 WCF 운영 계약이 필요할 때 새로운 운영 계약의 정의로 인터페이스를 확장하면됩니다. – CSharpenter
하지만 내 확장 인터페이스를 클라이언트에 적용해야합니다. 내 클라이언트 channelfactory가 IExtendedInterface의 인스턴스를 만들지 만 원래의 인스턴스를 계속 사용하고 싶지는 않습니다. 확실히 ChannelFactory를 확장하여 (예 : 비헤이비어 추가) RealProxy 등을 확장하여이 작업을 수행하는 방법이어야합니다. – m0sa