0

如果我有一个托管在 IIS 上的 WCF 应用程序,我该如何处理 UnknownMessageReceived事件?

当我构建控制台主机时,我知道该怎么做。

4

1 回答 1

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
    }
}
于 2012-07-09T20:55:00.097 回答