![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | "Generic" indigo console host Hi, Has anyone written a host that will read the config file at runtime and create a service host instance for all services/endpoints in app.config? If so, please point me to the code. If not, how would I go about it? I see there is a ServiceModel.Configuration namespace - could I use that? Thanks, Damon |
My System Specs![]() |
| | #2 (permalink) |
| | Re: "Generic" indigo console host Hello Damon, It is not a big deal writing one, but then you will not be able to set base addresses, and that will imply full addresses only in the config. In addition, you will not be able to get to some other features like singleton instance setting, throttling, etc. thanks, Juval Lowy. > Hi, > > Has anyone written a host that will read the config file at runtime > and > create a service host instance for all services/endpoints in > app.config? If so, please point me to the code. If not, how would I > go about it? I see there is a ServiceModel.Configuration namespace - > could I use that? > > Thanks, > Damon |
My System Specs![]() |
| | #3 (permalink) |
| | Re: "Generic" indigo console host In the code I post, I basically load Dynamically derived service hosts and not services. This could easily be changed though. Sorry for not pointed that out. Best Regards, Ido Samuelson Senior consultant Advantech (Magen MTC) mailto:idos@magen.com > Hello Juval, > > This should help you doing it. I removed some validation methods and > such, since I did it fast to post it here. Though I plan to post a > better solution on my blog. I'll post a url when completed. > > PS. This solution uses a services.xml to read which service types to > load. On a project am working on we basically recieving all the > services needed to load from a configuration service :-) > > You will still have all the app.config capabilites, since this > solution still uses the app.config. If you want something else you can > create a derived ServiceHost and override the ApplyConfiguration > method. > > class HostManager > { > private static List<ServiceHost> serviceHosts; // list of > loaded > sericeHosts > private static void InitServices() > { > ServiceList serviceList = GetServiceList(); > Trace.WriteLine("Opening services..."); > foreach (ServiceData data in serviceList.Services) > { > try > { > OpenService(data); > } > catch (Exception ex) > { > string msg = string.Format("Error Loading > ServiceHost > {0}, {1}", data.AssemblyName, data.TypeName); > Trace.WriteLine(msg); > Trace.WriteLine(ex.Message); > } > } > } > private static void OpenService(ServiceData data) > { > ServiceHost host = CreateServiceHost(data) as ServiceHost; > host.SetConfiguration(data.EndPoints); > serviceHosts.Add(host); > host.Open(); > } > private static ServiceList GetServiceList() > { > ServiceList list= null; > XmlFormatter formatter = new XmlFormatter(); > if (File.Exists(@"services.xml")) > { > using (StreamReader sr = new > StreamReader(@"services.xml")) > { > list = > formatter.Deserialize<ServiceList>(sr.BaseStream); > } > } > else > { > ServiceData data = new ServiceData(); > ServiceEndPointData ep = new ServiceEndPointData(); > ep.Address = "http://localhost:8000/EchoService"; > ep.Binding = "wsHttpBinding"; > ep.Contract = "Tests.EchoService.EchoContract"; > List<ServiceEndPointData> eps = new > List<ServiceEndPointData>(); > eps.Add(ep); > data.EndPoints = eps.ToArray(); > Trace.WriteLine("Creating default xml file."); > data.AssemblyName = "Tests.EchoService"; > data.TypeName = "Tests.EchoService.EchoServiceHost"; > list = new ServiceList(); > List<ServiceData> servicesList = new > List<ServiceData>(); > servicesList.Add(data); > list.Services = servicesList.ToArray(); > using (System.IO.StreamWriter sw = new > System.IO.StreamWriter(@"services.xml")) > { > sw.AutoFlush = true; > formatter.Serialize(sw.BaseStream, list); > } > } > return list; > } > private static ServiceHost CreateServiceHost(ServiceData data) > { > ObjectHandle handle = > Activator.CreateInstance(data.AssemblyName, > data.TypeName); > ServiceHost host = handle.Unwrap() as ServiceHost; > return host; > } > } > [DataContract(Namespace=Namespaces.ServiceData)] > public class ServiceData > { > [DataMember] > public string AssemblyName; > [DataMember] > public string TypeName; > } > > [DataContract(Namespace=Namespaces.ServiceListResponse)] > public class ServiceListResponse > { > [DataMember] > public ServiceData[] Services; > } > Best Regards, > > Ido Samuelson > Senior consultant > Advantech (Magen MTC) > mailto:idos@magen.com >> Hello Damon, >> >> It is not a big deal writing one, but then you will not be able to >> set base addresses, and that will imply full addresses only in the >> config. In addition, you will not be able to get to some other >> features like singleton instance setting, throttling, etc. >> >> thanks, >> >> Juval Lowy. >> >>> Hi, >>> >>> Has anyone written a host that will read the config file at runtime >>> and >>> create a service host instance for all services/endpoints in >>> app.config? If so, please point me to the code. If not, how would >>> I >>> go about it? I see there is a ServiceModel.Configuration namespace >>> - >>> could I use that? >>> Thanks, >>> Damon |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: "Virtual Server 2005 R2 SP1" on "Windows Web Server 2008" host? | Virtual Server | |||
| Is it possible to install a Vista "Recovery Console" in the boot menu, as in WinXP? | Vista General | |||
| Vista cannot find a suitable driver for a "Generic Serial" port | Vista General | |||
| Info : "Console based intellisense" Tabcompletion for PowerShell | PowerShell | |||
| "<SPACE> next page; <CR> next line; Q quit" not cleared in console | PowerShell | |||