How do I pass values to the constructor on my wcf service?

前端 未结 8 494
悲哀的现实
悲哀的现实 2020-11-22 13:09

I would like to pass values into the constructor on the class that implements my service.

However ServiceHost only lets me pass in the name of the type to create,

8条回答
  •  花落未央
    2020-11-22 13:36

    I use static variables of my type. Not sure if this is the best way, but it works for me:

    public class MyServer
    {   
        public static string CustomerDisplayName;
        ...
    }
    

    When I instantiate service host I do the following:

    protected override void OnStart(string[] args)
    {
        MyServer.CustomerDisplayName = "Test customer";
    
        ...
    
        selfHost = new ServiceHost(typeof(MyServer), baseAddress);
    
        ....
    }
    

提交回复
热议问题