views:

100

answers:

1

Hello,

I am currently building a custom binding which gets HTTP requests from a different source than from a listening TCP socket. When I access and open a channel directly, there are no problems. However, problems occur when I try to host my binding in an endpoint of a WebServiceHost.

I've inserted Console.WriteLine() debug messages into every function of my custom binding's code. Everything works fine until after the OnOpen() function of my ChannelListener has been called. Afterwards, the ServiceModel just doesn't want to invoke the OnAcceptChannel() method. No exceptions, no error message; it just hangs there and doesn't call any other function of my binding anymore. I've commented the output of the application into the code below.

WebServiceHost host = new WebServiceHost(
    typeof(MyService), new Uri("http://localhost:80"));
host.AddServiceEndpoint(typeof(MyService), new MyWebHttpBinding(), "");
// BINDING CONSTRUCTOR
// BINDINGELEMENT CONSTRUCTOR
host.Open();
// BINDING: CreateBindingElements (multiple times)
// BINDINGELEMENT: Clone
// BINDINGELEMENT CONSTRUCTOR
// BINDINGELEMENT: CanBuildChannelListener
// BINDINGELEMENT: Clone
// BINDINGELEMENT CONSTRUCTOR
// BINDINGELEMENT: CanBuildChannelListener
// BINDINGELEMENT: Clone
// BINDINGELEMENT CONSTRUCTOR
// BINDINGELEMENT: Clone
// BINDINGELEMENT CONSTRUCTOR
// BINDINGELEMENT: Clone
// BINDINGELEMENT CONSTRUCTOR
// BINDINGELEMENT: BuildChannelListener
// CHANNELLISTENER CONSTRUCTOR
// BINDINGELEMENT: Clone
// BINDINGELEMENT CONSTRUCTOR
// BINDING: CreateBindingElements (multiple times)
// CHANNELLISTENER: OnOpen
// CHANNELLISTENER: OnOpen END (function completes properly. last output)

Does anybody of you know what I have to change in my application that the OnAcceptChannel method gets called properly?

Cheers

+1  A: 

Are you logging calls to the Async version of the ChannelListener methods? I seem to remember ServiceHost trying to call OnBeginAcceptChannel normally instead of OnAcceptChannel.

Also, are you attaching a handler to the ServiceHost.Faulted event? It could be that it's faulting and you won't necessarily get an external exception during the opening of the host.

tomasr
You are right. Didn't log the calls to the async version of the methods. protected override System.IAsyncResult OnBeginAcceptChannel(System.TimeSpan timeout, System.AsyncCallback callback, object state) { Console.WriteLine("CHANNELLISTENER: OnBeginAcceptChannel"); throw new System.NotImplementedException(); }I've inserted this one and now it shows up. Nevertheless, I am wondering why I don't receive a report of this Exception. Do I have to enable throwing of such exceptions manually? If yes, then where?Thanks very much for your answer!
Etan
Could solve the exception problem. In VS 2008 under Ctrl+D, E, I had to activate the checkbox beside the System.NotImplementedException().
Etan
Any exceptions there would cause the ServiceHost to fault, and that's where you'd see that information. As for the rest, well, yes, you're better off implementing all the async calls since ServiceHost depends on them (not only on the listener, but also on the channels themselves).
tomasr