Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.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,我知道我可以通过一些XML配置添加服务行为,但我想用一段C#来完成,类似于添加端点行为的方式。不过,我不知道该怎么做 换句话说,如何添加我在下面实例化的调试行为 var host = new ServiceHost(typeof(MyService)); var endpoint = host.AddServiceEndpoint(typeof (MysService), new WebHttpBinding(), new Uri(myURL)); endpoint.Behaviors

我知道我可以通过一些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();

你也可以为你的服务写一份广告,例如

[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class Service1 : IServiceChild

谢谢事实证明,我无法执行.Add(),因为该行为已经存在。但这非常有效:
host.Description.Behaviors.Find().IncludeExceptionDetailInFaults=true
如果此行为是在configuration中定义的,但服务是在代码中定义的,该怎么办?如何使用代码将其添加到WCF主机?
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class Service1 : IServiceChild