WCF 发现客户端无法找到可单独访问的服务
我正在尝试将临时发现添加到简单的 WCF 服务客户端设置(当前通过控制台应用程序中的自托管实现)。在 Windows 7 上使用 VS2010 进行调试,并执行我在在线教程中可以找到的任何操作,但发现客户端仍然什么也没找到。不用说,如果我打开客户端到正确的服务端点,我就可以从客户端访问该服务。
服务代码:
using (var selfHost = new ServiceHost(typeof(Renderer)))
{
try
{
selfHost.Open();
...
selfHost.Close();
service app.config:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="TestApp.Renderer">
<host>
<baseAddresses>
<add baseAddress="http://localhost:9000" />
</baseAddresses>
</host>
<endpoint address="ws" binding="wsHttpBinding" contract="TestApp.IRenderer"/>
<endpoint kind="udpDiscoveryEndpoint"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceDiscovery/>
<serviceMetadata httpGetEnabled="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
客户端发现代码:
DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
var criteria = new FindCriteria(typeof(IRenderer)) { Duration = TimeSpan.FromSeconds(5) };
var endpoints = discoveryClient.Find(criteria).Endpoints;
“端点”集合始终为空。我尝试过从调试器、从命令行、从管理命令行运行服务和客户端 - 一切,但无济于事(当然,所有这些都在本地计算机上,更不用说我需要它在最终我的整个子网)
任何帮助将不胜感激:-)
I'm trying to add ad-hoc discovery to a simple WCF service-client setup (currently implemented by self hosting in a console app). Debugging using VS2010 on windows 7, and doing whatever I can find in online tutorial, but still - the discovery client simply finds nothing. Needless to say if I open a client to the correct service endpoint I can access the service from the client.
service code:
using (var selfHost = new ServiceHost(typeof(Renderer)))
{
try
{
selfHost.Open();
...
selfHost.Close();
service app.config:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="TestApp.Renderer">
<host>
<baseAddresses>
<add baseAddress="http://localhost:9000" />
</baseAddresses>
</host>
<endpoint address="ws" binding="wsHttpBinding" contract="TestApp.IRenderer"/>
<endpoint kind="udpDiscoveryEndpoint"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceDiscovery/>
<serviceMetadata httpGetEnabled="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
client discovery code:
DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
var criteria = new FindCriteria(typeof(IRenderer)) { Duration = TimeSpan.FromSeconds(5) };
var endpoints = discoveryClient.Find(criteria).Endpoints;
The 'endpoints' collection always comes out empty. I've tried running the service and client from the debugger, from a command line, from an admin command line - everything, but to no avail (all on the local machine, of course, not to mantion I'll need it running on my entire subnet eventually)
Any help would be appreciated :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个超级简单的发现示例。它不使用配置文件,都是 C# 代码,但您可以将这些概念移植到配置文件中。
在主机和客户端程序之间共享此接口(现在复制到每个程序)
将此代码放在主机程序中
将此代码放在
主机上的客户端程序中,只需调用 WcfTestHost_Open() 函数,然后永远休眠什么的。
在客户端上运行这些函数。主机打开需要一段时间,因此这里有几次延迟。
主机输出应该看起来像
客户端输出应该看起来像
这确实是我可以为发现示例提出的最小值。这些东西很快就会变得非常复杂。
Here is a super simple discovery example. It does not use a config file, it is all c# code, but you can probably port the concepts to a config file.
share this interface between host and client program (copy to each program for now)
put this code in the host program
put this code in the client program
on the host, simply call the WcfTestHost_Open() function, then sleep forever or something.
on the client, run these functions. It takes a little while for a host to open, so there are several delays here.
host output should look like
client output should look like
this is seriously the minimum I could come up with for a discovery example. This stuff gets pretty complex fast.
该死!这是防火墙的原因...由于某种原因,所有 UDP 通信都被阻止 - 禁用防火墙解决了问题。现在我只需要找出正确的防火墙配置......
Damn! it was the firewall... for some reason all UDP communication was blocked - disabling the firewall solved the problem. Now I only need to figure out the correct firewall configuration...