Single endpoint with multiple service contracts

前端 未结 1 825
没有蜡笔的小新
没有蜡笔的小新 2021-01-13 03:30

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

Example:

[ServiceContract]
public interface IWirelessServic         


        
相关标签:
1条回答
  • 2021-01-13 03:52

    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);
        }
     }
    
    0 讨论(0)
提交回复
热议问题