此代碼工作在普通類:爲什麼WCF類需要接口繼承,但普通類不是?
public interface IServiceBase
{
void BaseMethod();
}
public class ServiceBase : IServiceBase
{
public void BaseMethod() { }
}
public interface ITestService // : IServiceBase - it doesn't reqiure
// in plain classes but in WCF it does.
{
void TestMethod();
}
public class TestService : ServiceBase, ITestService
{
public void TestMethod() { }
}
class Program
{
static void Main(string[] args)
{
var ts = new TestService();
ts.BaseMethod();
}
}
但在WCF上下文中的客戶端無法看到BaseMethod直到你從IServiceBase inherite ITestService:
public interface ITestService : IServiceBase
爲什麼?
我想
TestService : ServiceBase
已經包括
TestService : IServiceBase
在普通班是這樣,但在WCF事實並非如此。
我的問題是不是這個問題Interface inheritance and derived classes
你如何創建你的代理類?通過代碼生成或通過使用ServiceChannel在客戶端和服務器之間手動共享相同的接口? – CodeNotFound
通過Visual Studio中的AddServiceReference選項。 – Alex34758
然後@TomTom的答案是正確的。 – CodeNotFound