C# 使用代码添加WCF服务行为
我知道我可以通过一些XML配置添加服务行为,但我想用一段C#来完成,类似于添加端点行为的方式。不过,我不知道该怎么做 换句话说,如何添加我在下面实例化的调试行为C# 使用代码添加WCF服务行为,c#,wcf,C#,Wcf,我知道我可以通过一些XML配置添加服务行为,但我想用一段C#来完成,类似于添加端点行为的方式。不过,我不知道该怎么做 换句话说,如何添加我在下面实例化的调试行为 var host = new ServiceHost(typeof(MyService)); var endpoint = host.AddServiceEndpoint(typeof (MysService), new WebHttpBinding(), new Uri(myURL)); endpoint.Behaviors
var host = new ServiceHost(typeof(MyService));
var endpoint = host.AddServiceEndpoint(typeof (MysService),
new WebHttpBinding(), new Uri(myURL));
endpoint.Behaviors.Add(new WebHttpBehavior());
var debug = new ServiceDebugBehavior
{
IncludeExceptionDetailInFaults = true
};
//WHAT DO I PUT HERE?
host.Open();
你也可以为你的服务写一份广告,例如
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class Service1 : IServiceChild
谢谢事实证明,我无法执行.Add(),因为该行为已经存在。但这非常有效:
host.Description.Behaviors.Find().IncludeExceptionDetailInFaults=true
如果此行为是在configuration中定义的,但服务是在代码中定义的,该怎么办?如何使用代码将其添加到WCF主机?
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class Service1 : IServiceChild