如何编写具有单个端点但具有多个服务合同的WCF Web服务?
示例:
[ServiceContract]
public interface IWirelessService
{
[OperationContract]
void AddWireless();
}
[ServiceContract]
public interface IWiredService
{
[OperationContract]
void AddWired();
}
[ServiceContract]
public interface IInternetService
{
[OperationContract]
void AddInternet();
}
让我们认为IInternetService是我的主要Web服务,我想在其中实现IwiredService和IWirelessService,但我想在他们的类中实现。这可能吗?我该如何解决这个问题?
答案 0 :(得分: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);
}
}