5

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?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
svlytns
  • 83
  • 1
  • 8
  • 1
    Did you see this question? I think it has the answer for what you are trying to do... [link](http://stackoverflow.com/questions/334472/run-wcf-servicehost-with-multiple-contracts) – Selcuk S. Mar 05 '12 at 13:58
  • Thanks, that is actually what i need. – svlytns Mar 05 '12 at 14:12

1 Answers1

3

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);
    }
 }
Wali
  • 440
  • 1
  • 4
  • 21
  • 1
    From the "http://stackoverflow.com/questions/334472/run-wcf-servicehost-with-multiple-contracts" link i get the solution.Actually partial classes help me.Thanks for help. – svlytns Jun 13 '12 at 17:44