Reputation: 909
My application runs a WCF service host with 2 different binding (each with different interfaces). Under certain circumstances, I'd like to disable 1 binding so clients that try to connect to this interface/port/binding-name (whatever) don't find anything there.
Is this possible, and how?
Upvotes: 1
Views: 137
Reputation: 1217
Going on what Dhawalk said, you could abstract out your business layer, and using dependency injection, injecting service handlers with implementations for "not available" and "functional". The not available implementations could just throw an exception or always return an error.
Upvotes: 1
Reputation: 1269
you will have to device your BL, and use WCF inspectors to bounceoff unlicensesd calls. please refer to the following link for inspectors
http://msdn.microsoft.com/en-us/library/aa717047.aspx
Upvotes: 0
Reputation: 3166
If both service contracts are on the same service class, I don't see how you would easily disable it beyond adding a check for 'If I am enabled...' at the start of each method.
Maybe you could programattically look at the Operation Contracts of your service host, it may be possible to remove them one at a time. The service host may have to be turned off temporarily to make that change though. I've added methods to a service contract in this way that never existed on the same class/interface as the real service class, and weren't even in the same assembly, but I can't remember if the servicehost had already been started at that time.
You'll need to look at the Endpoints in:
ServiceHost.Description.Endpoints
and choose the one you need to edit, then look at
Endpoint.Contract.Operations
to determine which methods you want to add/remove. They will disappear from the WSDL.
EDIT Just tried this, it seems to work at run time but I can imagine it would be harder to add OperationContracts back in (unnless you saved them before you removed them... let me know how you get on, it sounds interesting!)
Upvotes: 0