Last post Apr 16, 2010 11:47 AM by 0063292
Apr 03, 2009 12:40 PM|gsogol|LINK
I have a need to have a WebServiceHost2 because I need to add an Interceptor but I also need a binding element for a more advanced configuration? Can you have a a binding element in the config section and somehow add an interceptor via the config or reference
the binding when instantiating WebServiceHost2 due to its ability to add an interceptor?
My binding is really advanced and I don't want to nor do I know how to create such a binding via code. Please help.
Apr 06, 2009 04:44 PM|Yavor Georgiev - MSFT|LINK
If you derive from WebServiceHost2 and create your own host, you can manage the entire service description, including adding a RequestInterceptor or changing the binding on an endpoint:
class AppServiceHostFactory : ServiceHostFactory
protected override ServiceHost CreateServiceHost(Type serviceType, Uri baseAddresses)
return new MyCollectionServiceHost(serviceType, baseAddresses);
class MyCollectionServiceHost : CollectionServiceHost
public MyCollectionServiceHost(Type serviceType, params Uri baseAddresses) :
protected override void OnOpening()
// Add your interceptor
// Modify the endpoints in the service
ServiceEndpoint endpoint = Description.Endpoints.Find(typeof(IMyService));
Hope this helps,
Apr 06, 2009 06:17 PM|gsogol|LINK
Thank you.I already have my own implementation of WebServiceHost2 where I add an interceptor. My question was if I could use my own WebServiceHost3 plus the configuration from web.config as in:
Please let me know. Thanks though.
Apr 16, 2010 11:47 AM|0063292|LINK
Yavor, I came across this post when dealing with WebServiceHost2 and trying to implement 2 interfaces/contracts. It seems that WebServiceHost2 does not support more than one service contract because it appears the base.OnOpening() call throws away the additional
endpoints configured (either in web.config or created in code). Everything I have tried simple throws this error below. I have stepped through with the debugger and see that I have all my endpoints configured before the host is activated. I have tried both
using WebServiceHost2 and a factory where I configure endpoints for the interfaces (or verify that they came in on web.config) and have tried the subclass noted in this post. Each time an exception is thrown on the base WebServiceHost.OnOpening call saying
I don't have explicit endpoints defined---I DO! It appears WebServiceHost2 is tossing them out at some point.
Also interresting is that I can configure multiple endpoints as long as there is only one contract that all the endpoints are implementing--it seems to keep all the endpoints then.
Can you help? Is this the way WebServiceHost2 is designed? I see .net 4.0 supposedly now automatically creates default endpoints for all interfaces a service implements. Does WebServiceHost2 in .net 4.0 allow multiple interfaces?
Hope you have some advice--my head is spinning!