无法使用 WCF 通过网络访问
我在 Windows 窗体 应用程序中有一个 WCF 自托管服务。我将使用它,以便手持移动设备可以与应用程序进行基本的交互。
我已启用 basicHttp (http://localhost:8080/tagservice/basic
)、NetTCP (net.tcp://localhost:8888/tagservice
) 和 basicHttpMex 作为端点。
出于测试目的,我在网络上设置了一个虚拟机(并在物理机上重复了这些)。
这些端点都在托管服务的本地计算机上工作。
但是,当在远程计算机上运行 WCFTestClient 时,我得到的结果好坏参半。
- 使用上述端点,我可以连接到服务并查看服务合同,证明 mex (IMetadataExhange) 有效。但我不能使用 http 或 net.tcp。我收到错误消息
无法连接到http://localhost:8080/tagservice/basic。 TCP错误代码10061:无法建立连接,因为目标机器主动拒绝127.0.0.1:8080。
无法连接到 net.tcp://localhost:8888/tagservice。连接尝试持续的时间跨度为 00:00:01.0014400。 TCP错误代码10061:无法建立连接,因为目标机器主动拒绝127.0.0.1:8888。
将 localhost 更改为主机上 app.config 中的真实 IP 地址时,在本例中为 192.168.0.61。基本的 HTTP 工作正常。但是 net.icp 失败并显示
“服务器已拒绝客户端凭据。”
我的两个问题是:
- 为什么 net.tcp 失败?据我所知,我无法选择输入凭据。
- 鉴于 IP 地址可以更改,如何让 app.config 使用 DHCP 服务器分配的 IP 地址?一旦该软件从开发环境转移到生产环境,IP 地址就无法进行硬编码,因为它会发生变化。
I have a WCF self-hosted service in a Windows Forms application. I am going to be using it so a hand-held mobile device can interact with the application at a basic level.
I have enabled basicHttp (http://localhost:8080/tagservice/basic
), NetTCP (net.tcp://localhost:8888/tagservice
), and basicHttpMex as endpoints.
For testing purposes, I have setup a virtual machine on the network (and repeated these on a physical machine as well).
These endpoints all work on the local machine where the service is hosted.
However when running the WCFTestClient on remote machines I get mixed results.
- Using the above endpoints, I can connect to the service and see the service contracts, proving the mex (IMetadataExhange) works. But I cannot use either http or net.tcp. I get the error message
Could not connect to http://localhost:8080/tagservice/basic. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8080.
Could not connect to net.tcp://localhost:8888/tagservice. The connection attempt lasted for a time span of 00:00:01.0014400. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8888.
When changing localhost to the real IP address in the app.config on the host, in this case 192.168.0.61. Basic HTTP works. However net.icp fails with
"The server has rejected the client credentials."
My two questions are:
- Why is the net.tcp failing? I am not given a choice to enter credentials as far as I can tell.
- Given the IP address can change, how can I get the app.config to use the IP address it is assigned by the DHCP server? As once this software moves from development to production environment the IP address cannot be hardcoded as it will change.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在运行时构建和配置客户端绑定,以便您可以根据计算机信息以编程方式设置 URL
类似这样的事情应该可以工作
然后您只需将该端点附加到您的客户端,它就应该全部连接起来。
Build and configure the client binding at runtime, so you can programmatically set the URL based on the machine information
Something like this should work
Then you just attach that endpoint to your client and it should all hook up.
您可以将
localhost
替换为您的主机名(如果 IP 地址是动态的)或 IP 地址(如果是静态的)并重新编译您的客户端。You can replace
localhost
to your hostname (if IP address is dynamic) or IP address(if static) and recompile your client.