Rob Bird
Rob Bird

Reputation: 3824

WCF - same service on different IIS .svc endpoints with multiple interfaces

I am trying to achieve the following:

The way I have tried to go about this is to create one service that implements two interfaces

For example:

Public Service Interface

[ServiceContract(Namespace = "http://www.myurl.com/public/2011/10")]
public partial interface IPublicService
{
    [OperationContract]
    ResponseObjOne OperationAvailableToEveryone(RequestObjOne request);
}

Private Service Interface

[ServiceContract(Namespace = "http://www.myurl.com/private/2011/10")]
public partial interface IPrivateService
{
    [OperationContract]
    ResponseObjOne OperationAvailableToEveryone(RequestObjOne request);

    [OperationContract]
    ResponseObjTwo OperationAvailableInternally(RequestObjTwo request);
}

Service class to implement both interfaces

public class Service : IPrivateService, IPublicService
{
    ResponseObjOne OperationAvailableToEveryone(RequestObjOne request)
    { }

    ResponseObjTwo OperationAvailableInternally(RequestObjTwo request)
    { }
}

I would now like to be able to configure this to run as two separate endpoints in IIS. So I have an .svc file with the following:

<%@ ServiceHost Language="C#" Debug="true"  Service="Adactus.Pulse.SOAServices.Service, Adactus.Pulse.SOAServices"  %> 

And added the following in the web.config:

  <service name="Service">
    <endpoint address="/public" binding="basicHttpBinding" contract="IPublicService" />
    <endpoint address="/private" binding="basicHttpBinding" contract="IPrivateService" />
  </service>

But if I browse to the .svc file I now see all operations in the WSDL and if I add /public to the URL I see a 404. So how can I achieve this?

Ideally I would like to add another .svc endpoint and be able to specify the interface as well as the service implementation class in these svc files. Then I can lock down access to the svc in IIS to secure the internal service.

the key is that some of the operations are exposed in both contracts and I don't want to duplicate their implementation.

Any ideas? Am I going about this in the wrong way?

Cheers, Rob

Upvotes: 0

Views: 673

Answers (2)

Prasad Kanaparthi
Prasad Kanaparthi

Reputation: 6563

Observations: Your Service class to implement both interfaces seems wrong. both interfaces have same method name OperationAvailableToEveryone infact you have to implement your interfaces explicitly.

I even have same query. Infact you cannnot browse with http://localhost:8001/service.svc/public instead http://localhost:8001/public/service.svc. still you can create proxy with http://localhost:8001/service.svc and you use it as normal and your client enpoint address looks like

    </client>
        <endpoint address="http://localhost:8001/SOAService.svc/public"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPublicService"
            contract="SOAService.IPublicService" name="BasicHttpBinding_IPublicService" />
        <endpoint address="http://localhost:8001/SOAService.svc/private"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPrivateService"
            contract="SOAService.IPrivateService" name="BasicHttpBinding_IPrivateService" />
    </client>

Hope this helps.

Upvotes: 1

Graymatter
Graymatter

Reputation: 6587

While it doesn't answer your question, I would definitely not design it this way. I would create a single class library that includes both interfaces and the implementations for them and then I would create separate WCF projects that expose the different interfaces.

Upvotes: 1

Related Questions