当客户端有多个 IP 地址时 WCF 服务问题
我需要一些帮助来解决桌面客户端与 IIS 上托管的 WCF 服务的通信所面临的问题。
我在测试用例中尝试执行的操作:
- 服务器托管 WSDualHttpBinding 服务
- 客户端通过提供包含客户端 IP 地址的回调 uri 来建立与此的连接(调用 Register 方法)
- 建立连接后,将显示一个网页由客户端应用程序启动。用户在文本框中输入一些文本并单击“发送”。该网页将文本发送到所有注册的桌面客户端。
问题:
在步骤 2 中,一台 PC 可能有多个 IP 地址(以太网适配器、环回适配器等)。如果在注册调用期间,在回调url中发送了此列表中的IP,而该IP无法从服务器回调(例如环回适配器IP),则会抛出超时异常。经过几次这样的尝试后,服务器无法再接受来自客户端的调用(无论是否有效的 IP)。有时会抛出“服务器太忙”异常。
(由于 DNS/WINS 配置问题导致服务器无法将计算机名称解析为正确的 IP 地址,因此我无法在回调 uri 中使用计算机的完全限定名称)。
如何重现:
一个。在 IIS 上发布服务器。从具有多个 IP 地址的不同计算机执行客户端。客户端抛出超时异常,尝试3次后程序退出 b. App.Config 中的参数允许输入正确的 IP 地址(要使用的 IP)。现在,如果程序启动,一切正常。
c.如果我删除上面指定的此 IP 地址,从而使用不正确的 IP,则会再次发生步骤 a。在此模式下运行程序2-3次。
d.按照步骤 b 进行更改并运行程序。有时我会遇到超时异常。其他时候,网站就会出现。但是,当输入并发送文本时,它不会到达客户端。 (即使 Web 服务没有收到任何调用,注册方法仍然有效。由于 Web 服务上没有注册客户端,发送功能失败。
我不确定为什么会发生这种情况以及如何解决它。这是我的 Visual Studio 解决方案- http://bit.ly/atKfOS
非常感谢任何意见和评论。 环境:服务器 - Windows XP (IIS 5)、Windows Server 2008 SP2 x64 (IIS 7)、客户端:Windows XP
谢谢 气相色谱
I need some help in resolving an issue I'm facing an with communication of a desktop client with WCF service hosted on IIS.
What I'm trying to do in my test case:
- Server hosts a WSDualHttpBinding service
- Client establishes a connection (calls Register method) to this by providing its callback uri which contains the client’s IP Address
- Once connection is established, a web page is launched by the client application. User types some text into the textbox and clicks Send. The web page sends the text to all registered desktop clients.
Issue:
In step 2, a PC may have multiple IP Addresses (Ethernet adapter, loopback adapters etc). If during the registration call, an IP from this list is sent in the callback url which cannot be called back from the server (e.g. loopback adapter IP), a timeout exception is thrown. After a few such attempts, the server cannot accept calls from clients anymore (whether valid IP or otherwise). Sometimes “server too-busy” exception was thrown.
(I cannot use machine’s fully qualified name in the callback uri due to DNS/WINS configuration issues causing the server to not not resolve machine name to the correct IP address).
How to reproduce:
a. Publish the server on IIS. From a different machine with multiple IP addresses, execute the client. The client throws timeout exceptions and program exits after 3 tries
b. A parameter in the App.Config allows one to type in the right IP address (IP to use). Now if the program is launched, everything works fine.
c. If I remove this IP address specified above so that an incorrect IP is used, again step a happens. Run the programs 2-3 times in this mode.
d. Make changes as in step b and run the program. Sometimes I get a timeout exception. Other times, the web site comes up. However when text is entered and sent, it doesn't come to the client. (The register method worked even though web service did not receive any call. Sending function fails as there are no registered clients on the web service.
I’m not sure why exactly this happens and how to address it. Here is my Visual studio solution - http://bit.ly/atKfOS
Highly appreciate any inputs, comments.
Environment: Server - Windows XP (IIS 5), Windows Server 2008 SP2 x64 (IIS 7), Client: Windows XP
Thanks
GC
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我想主要问题是这样的:当服务器尝试回调客户端并且失败时,两者之间的通道将变得“故障”,并且变得无用。
发生此类事件后,您必须处置客户端代理,并重新创建它 - 或者优雅地处理服务器上的超时异常(捕获它,将其转换为 SOAP 错误,记录它 - 无论如何 - 只是不要让未过滤的 .NET TimeoutException 传回客户端,这将使通道出现故障)。
当发生这样的 TimeoutException 时,您在服务器端会做什么?您是否确保不会将该异常一直冒泡到通道?
Well, I guess the main problem is this: when the server tries to call back to the client and fails, the channel between the two will become "faulted", and rendered useless.
After such an event happens, you have to dispose the client side proxy, and recreate it - or gracefully handle the timeout exception on the server (catch it, turn it into a SOAP fault, log it - whatever - just don't let the unfiltered .NET TimeoutException pass back to the client, this will fault the channel).
What do you do on your server side when such a TimeoutException happens? Do you make sure not to bubble up that exception all the way up to the channel??