Single endpoint with multiple service contracts

◇◆丶佛笑我妖孽 提交于 2019-12-19 07:48:13

问题


How can I write a WCF web service that has single endpoint but multiple service contract?

Example:

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

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

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

Lets think like IInternetService is my main webs service and i want to implement IwiredService and IWirelessService in it, but i want to do implementation in their classes.Is this possible? How can i solve this problem?


回答1:


I have given the below example is it what you were looking for?

[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);
    }
 }


来源:https://stackoverflow.com/questions/9567810/single-endpoint-with-multiple-service-contracts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!