0

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?

ZedZip
  • 5,794
  • 15
  • 66
  • 119

1 Answers1

1

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
Dmitry Harnitski
  • 5,838
  • 1
  • 28
  • 43
  • Thank you. WHy there is this condition? || bindingName.EndsWith("MetadataExchangeHttpBinding")) – ZedZip Aug 21 '12 at 11:42
  • This is protocol that helps client applications development. It may be disabled in Live but very useful for develops. See details here - http://msdn.microsoft.com/en-us/library/ms734765.aspx – Dmitry Harnitski Aug 21 '12 at 13:37