wcf接口存在继承
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetTestString1();
}
[ServiceContract]
public interface IService2 : IService1
{
[OperationContract]
string GetTestString2();
}
客户端调用
static void Main(string[] args)
{
IService2 service = GetServiceInstance("net.tcp://*****"); ;
Type t = typeof(IService2);
//父类接口调用
var parentClass = t.GetInterfaces()[0];
MethodInfo method = parentClass.GetMethod("GetTestString1");
Console.WriteLine(method.Name);
var s1 = method.Invoke(service, new object[] { });
//子类接口调用
MethodInfo method2 = t.GetMethod("GetTestString2");
Console.WriteLine(method2.Name);
var s2 = method2.Invoke(service, new object[] { });
Console.ReadLine();
}
public static IService2 GetServiceInstance(string address)
{
EndpointAddress addresstemp = new EndpointAddress(address);
NetTcpBinding binding = new NetTcpBinding();
ChannelFactory<IService2> channelFactory = new ChannelFactory<IService2>(binding, addresstemp);
IService2 channeltemp = channelFactory.CreateChannel();
return channeltemp;
}