Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF:是否将编程配置的服务器转换为配置文件?_C#_Wcf - Fatal编程技术网

C# WCF:是否将编程配置的服务器转换为配置文件?

C# WCF:是否将编程配置的服务器转换为配置文件?,c#,wcf,C#,Wcf,我有一个项目在控制台应用程序中运行一些WCF东西。一切都是以编程方式完成的(包括服务和客户机),我想知道如何将有关配置和启动服务/客户机的所有代码放在配置文件中 如果我只是在项目中添加一个.config文件,然后通过WCF服务配置编辑器对其进行编辑,那么它是否有效 以下是服务中的一些代码: using (ServiceHost host = new ServiceHost(typeof(StringReverser), new Uri[]{ new Uri("net.tcp://

我有一个项目在控制台应用程序中运行一些WCF东西。一切都是以编程方式完成的(包括服务和客户机),我想知道如何将有关配置和启动服务/客户机的所有代码放在配置文件中

如果我只是在项目中添加一个.config文件,然后通过WCF服务配置编辑器对其进行编辑,那么它是否有效

以下是服务中的一些代码:

        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();
        }
使用(ServiceHost host=newservicehost)(typeof(StringReverser),newuri[]{newuri(“net”)。tcp://192.168.0.120:8999") }))//192.168.0.120:8999
{
//添加ServiceDiscoveryBehavior
host.Description.Behaviors.Add(新服务发现行为());
//添加UdpDiscoveryEndpoint
AddServiceEndpoint(新的UdpDiscoveryEndpoint());
AddServiceEndpoint(typeof(IStringReverser),new NetTcpBinding(),“TCPReverse”);
host.Open();
Console.WriteLine(“服务可用。”+“按退出”);
Console.ReadLine();
host.Close();
}
我可以在配置文件中有哪些部分而不在程序中


提前感谢

是的,您可以将服务端点、行为配置和绑定配置放在配置文件中。事实上,你应该!它使部署后维护变得更加容易

将帮助您轻松设置配置文件。这真的很简单