code_junkie

Programatically configure individual WCF operations with different WCF configurations

Nov 13th, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. Server A
  2. ========
  3.  
  4. Operation 1 - Endpoint I
  5. Operation 2 - Endpoint II
  6.  
  7.  
  8. Server B
  9. ========
  10.  
  11. Operation 1 - Endpoint IV
  12. Operation 2 - Endpoint III
  13.  
  14. IDictionary<string, ServiceHost> hosts;
  15. NetTcpBinding binding;
  16. CustomBinding mexBinding;
  17.  
  18. private void AddService(Type serviceImp, Type serviceDef, string serviceName)
  19. {
  20. ServiceHost host = new ServiceHost(serviceImp);
  21.  
  22. string address = String.Format(baseAddress, wcfPort, serviceName);
  23.  
  24. string endAdd = address;
  25. string mexAdd = address + "/mex";
  26.  
  27. ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
  28. host.Description.Behaviors.Add(behavior);
  29. host.AddServiceEndpoint(serviceDef, binding, endAdd);
  30. host.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, mexAdd);
  31.  
  32. host.Open();
  33.  
  34. hosts.Add(serviceDef.Name, host);
  35. }
Add Comment
Please, Sign In to add comment