WebServiceHost 不调用自定义 ChannelListener 的 OnAcceptChannel
我目前正在构建一个自定义绑定,它从与侦听 TCP 套接字不同的源获取 HTTP 请求。 当我直接访问并打开频道时,没有任何问题。 但是,当我尝试在 WebServiceHost 的端点中托管绑定时,会出现问题。
我已将 Console.WriteLine() 调试消息插入到自定义绑定代码的每个函数中。 一切正常,直到调用 ChannelListener 的 OnOpen() 函数之后。 之后,ServiceModel 只是不想调用 OnAcceptChannel() 方法。 无异常,无错误信息; 它只是挂在那里,不再调用我的绑定的任何其他函数。 我已将应用程序的输出注释到下面的代码中。
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)
你们中有人知道我必须在应用程序中更改什么才能正确调用 OnAcceptChannel 方法吗?
干杯
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否正在记录对 ChannelListener 方法的异步版本的调用? 我似乎记得 ServiceHost 尝试正常调用 OnBeginAcceptChannel 而不是 OnAcceptChannel。
另外,您是否将处理程序附加到 ServiceHost.Faulted 事件? 可能是它出现了故障,并且您在打开主机期间不一定会遇到外部异常。
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.