質問

WCF (winodws service hosting) service uses set of protocols and bindings: http, https, net.tcp, net.pipe. It uses config file settings.

I want to build demo version of the service. This demo will use only net.pipe protocol. How I can restrict service to use only this one? I can do changes in code , but how and where?

役に立ちましたか?

解決

ServiceHost owns collection of ChannelDispatchers in ChannelDispatchers property. You can use ChannelDispatcher.BindingName to figure out name of binding used in your service.

ServiceHost host = new ServiceHost(typeof(SomeService), baseAddress))
//configure service endpoints here
host.Open();

#if DEMO_MODE
foreach (ChannelDispatcher dispatcher in host.ChannelDispatchers)
{
   //binding name includes namespace. Example - http://tempuri.org/:NetNamedPipeBinding
   var bindingName = dispatcher.BindingName;
   if (!(bindingName.EndsWith("NetNamedPipeBinding") || bindingName.EndsWith("MetadataExchangeHttpBinding")))
     throw new ApplicationException("Only netNamedPipeBinding is supported in demo mode");
}
#endif
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top