2012-03-05 91 views
5

如何編寫具有單個端點但具有多個服務合同的WCF Web服務?具有多個服務合同的單個端點

例子:

[ServiceContract] 
public interface IWirelessService 
{ 
    [OperationContract] 
    void AddWireless(); 
} 

[ServiceContract] 
public interface IWiredService 
{ 
    [OperationContract] 
    void AddWired(); 
} 

[ServiceContract] 
public interface IInternetService 
{ 
    [OperationContract] 
    void AddInternet(); 
} 

讓我們覺得像IInternetService是我的主網服務,我要實現IwiredService和IWirelessService在裏面,但我想要做的實現他們的classes.Is這可能嗎?我怎麼解決這個問題?

+1

您是否看到此問題?我認爲它有你想要做的答案... [鏈接](http://stackoverflow.com/questions/334472/run-wcf-servicehost-with-multiple-contracts) – 2012-03-05 13:58:35

+0

謝謝,這實際上是我需要的。 – svlytns 2012-03-05 14:12:36

回答

3

我給出了下面的例子是你在找什麼?

[ServiceContract] 
public interface IWirelessService : IInternetService 
{ 
    [OperationContract] 
    Connection AddInternet(); 
} 

[ServiceContract] 
public interface IWiredService : IInternetService 
{ 
    [OperationContract] 
    Connection AddInternet(); 
} 

public class WirelessService : IWirelessService 
{ 
    public Connection AddInternet() 
    { 
    //Get Internet the wireless way 
    } 

} 

public class WiredService : IWiredService 
{ 
    public Connection AddInternet() 
    { 
    //Get Internet the wired way 
    } 
} 

[ServiceContract] 
public interface IInternetService 
{ 
    [OperationContract] 
    Connection AddInternet(); 
} 


[ServiceContract] 
public interface IEnterpriseApplicationService 
{ 
    [OperationContract] 
    void GetDataFromInternet(string url, IInternetService internetService); 
} 
public class InternetProviderService : IEnterpriseApplicationService 
{ 
    public HTMLResponse GetDataFromInternet(string url, IInternetService internetService) 
    { 
     Connection con = internetService.AddInternet(); 
     return con.GetContentFromURL(url); 
    } 
} 
+1

從「http://stackoverflow.com/questions/334472/run-wcf-servicehost-with-multiple-contracts」鏈接我得到的解決方案。實際上部分類幫助我。感謝您的幫助。 – svlytns 2012-06-13 17:44:20

相關問題