简体   繁体   中英

IIS hosting for WCF service with 2 contracts or hosting 2 services with dependencies

I'm developing a WCF service that has a contract called MyApp.IOperationService.

<service name="MyApp.OperationService">
    <endpoint address="OperationService" binding="basicHttpBinding" contract="MyApp.IOperationService" />
</service>

For the service behaviour I used InstanceContextMode = InstanceContextMode.Single and ConcurrencyMode = ConcurrencyMode.Multiple because the application uses a shared physical resource.

I needed an administrative interface for this service and first I added a new contract within the same service. This approach didn't appeal to me because the administrative contract was exposed, through the metadata, to the clients using the operation contract.

Then I opted for creating another service altogether.

<service name="MyApp.AdminService">
    <endpoint address="Admin" binding="netTcpBinding" contract="MyApp.IAdminService" />
</service>

This service has one operation, called Login, that propagates the pincode to the OperationService object.

namespace MyApp
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, UseSynchronizationContext = false)]
    public class AdminService : IAdmin
    {
        MyApp.OperationService objOperationService = null;

        public AdminService(MyApp.OperationService objOperationService)
        {
            m_objOperationService = objOperationService;
        }

        public void Login(string pincode)
        {
            m_objOperationService.Login(pincode);
        }
    }       
}

In a self-hosting environment I create a MyApp.OperationService object, then pass this object to the constructor of MyApp.AdminService. For IIS hosting, I discovered that I need to use WCF extensibility points and implement an IInstanceProvider, then use a ServiceHostFactory.

At this point I stopped and wondered if this will work at all, given that my AdminService expects an already created MyApp.OperationService that IIS controls, and it already seems awfully complicated for my humble purpose.

The question is if this (administrative contract/interface for an existing service that is not exposed through the metadata) can be achieved in another way?

Thank you.

I couldn't find a way to solve the problem, except using WCF extensibility points. I used Microsoft.Practices.Unity to manage the services through IoC, then used the Factory property in the .svc file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM