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,但我想在他们的类中实现。这可能吗?我怎么解决这个问题?

4

1 回答 1

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);
    }
 }
于 2012-06-13T14:15:45.847 回答