开发者

Adding WCF service behaviors with code

开发者 https://www.devze.com 2022-12-22 21:55 出处:网络
I know I can add service behaviors with some XML configuration, but I\'d like to do it with a piece of C#, similar how you can add endpoint behaviors. I\'m not sure how to do that, though.

I know I can add service behaviors with some XML configuration, but I'd like to do it with a piece of C#, similar how you can add endpoint behaviors. I'm not sure how to do that, though.

In other words, how can I add the debug behavior I've instantiated below?

var host = new ServiceHost(typeof(MyService));
var endpoint = host.AddServiceEndpoint(typeof (MysService), 
    new WebHttpBinding(), new Uri(myURL));
endpoint.Behaviors.Add(new WebHttpBehavi开发者_JAVA技巧or());
var debug = new ServiceDebugBehavior
{
    IncludeExceptionDetailInFaults = true
};
//WHAT DO I PUT HERE?
host.Open();


host.Description.Behaviors.Add(debug);


Also you can write an atrribute for your service e.g.

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号