My endpoints specify which interface is used to govern the WCF service. Because it's an interface, I can have multiple different concrete classes implement the interface's functionality. How do I specify which concrete class should be used for a given WCF service's endpoint?
How do you say for this en开发者_如何学编程dpoint, use this concrete class and for that endpoint, use that concrete class when both endpoints use the same interface?
The contract implementation type to use is defined when the ServiceHost
instance is created. If you have multiple endpoints served by the same ServiceHost, it will create an instance of the same type to respond to requests to these endpoints.
If you want two endpoints for the same contract to use different implementations, you have two choices:
- expose the two endpoints on two separate service hosts. (Either through creating two
ServiceHost
instances or specifying two<service>
configuration elements); - have a composite implementation for the class that has two separate implementations of the same interface (through any OOP approach you can think of) and dispatches the calls to these based on the endpoint address.
I personally would stick with the first approach. If you go for the second approach, you would be essentially reimplementing ServiceHost
yourself.
精彩评论