代码之家  ›  专栏  ›  技术社区  ›  user24359

使用代码添加wcf服务行为

  •  22
  • user24359  · 技术社区  · 16 年前

    我知道我可以通过一些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();
    
    2 回复  |  直到 8 年前
        1
  •  33
  •   Timores    16 年前
    host.Description.Behaviors.Add(debug);
    
        2
  •  2
  •   helpME1986    8 年前

    你也可以为你的服务写一个特写。

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