如果我在IIS上托管了WCF应用程序,我该如何处理
UnknownMessageReceived
个事件?
我知道如何在构建控制台主机时执行此操作。
答案 0 :(得分:0)
您可以使用服务主机工厂来访问IIS下使用的服务主机实例。您可以在http://blogs.msdn.com/b/carlosfigueira/archive/2011/06/14/wcf-extensibility-servicehostfactory.aspx找到有关服务主机工厂的更多信息,下面的代码显示了一个监听UnknownMessageReceived
事件的工厂示例。
public class MyFactory : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
ServiceHost host = base.CreateServiceHost(serviceType, baseAddresses);
host.UnknownMessageReceived += new EventHandler<UnknownMessageReceivedEventArgs>(host_UnknownMessageReceived);
return host;
}
void host_UnknownMessageReceived(object sender, UnknownMessageReceivedEventArgs e)
{
// do something with the message
}
}