开发者

WCF: convert programmatically configured server to a config file?

开发者 https://www.devze.com 2023-03-08 03:05 出处:网络
I\'ve got a project running some WCF stuff in a console application. Everything is done programmatically (both the service and the client) and I was wondering how put all the code regarding configurin

I've got a project running some WCF stuff in a console application. Everything is done programmatically (both the service and the client) and I was wondering how put all the code regarding configuring and launching the servic开发者_如何学Pythone/client in a config file.

Should it work if I just add a .config file to my project and just edit it through the WCF service configuration editor?

Here is some piece of code from the service:

        using (ServiceHost host = new ServiceHost(typeof(StringReverser), new Uri[]{ new Uri("net.tcp://192.168.0.120:8999") }))//192.168.0.120:8999
        {
            // Add a ServiceDiscoveryBehavior
            host.Description.Behaviors.Add(new ServiceDiscoveryBehavior());
            // Add a UdpDiscoveryEndpoint
            host.AddServiceEndpoint(new UdpDiscoveryEndpoint());

            host.AddServiceEndpoint(typeof(IStringReverser), new NetTcpBinding(), "TCPReverse");

            host.Open();

            Console.WriteLine("Service is available. " + "Press <ENTER> to exit.");
            Console.ReadLine();

            host.Close();
        }

Which part can I have in a config file and not in my program?

Thanks in advance


Yes, you can put your service endpoint, behaviour configurations and binding configurations in a config file. In fact, you should! It makes post-deployment maintenance so much easier.

The Configuration Editor Tool will help you to easily set up your config file. It's really simple.

0

精彩评论

暂无评论...
验证码 换一张
取 消