使用LightInject (IoC)服务,不需要.svc和.config

本文关键字:不需要 svc config 服务 LightInject IoC 使用 | 更新日期: 2023-09-27 18:14:35

我需要在代码中为我的WCF服务创建服务端点和servicebehavior,这些服务是用LightIject(IoC容器)创建的,所以它们没有。svc文件。

可以用代码创建这些行为,而不需要.config文件吗?

使用LightInject (IoC)服务,不需要.svc和.config

是的,这是可能的代码。你需要的类都在系统里。ServiceModel和System.ServiceModel.Description命名空间。一个例子是(这还没有经过测试):

string endPointAddress = "http://localhost:8000/MyAwesomeService"
var host = new ServiceHost(typeof(MyAwesomeService));
var endpoint = host.AddServiceEndpoint(typeof (MyAwesomeService), new WebHttpBinding(), new Uri(endPointAddress));
endpoint.Behaviors.Add(new WebHttpBehavior());

这里是一系列关于WCF可扩展性的MSDN文章