我知道可以通过一些XML配置来添加服务行为,但我想用一段类似于添加终结点行为的C#代码来完成。不过我不确定该如何做。
换句话说,我该如何添加我已经实例化的调试行为?
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();
.Add()
,因为这个行为已经存在了。但是这个方法很有效:host.Description.Behaviors.Find<ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true
。 - user24359