WCF发现返回硬编码的网址 [英] WCF Discovery returns hard-coded URL

查看:130
本文介绍了WCF发现返回硬编码的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

宏伟构想如下:


  1. 还有就是被安装为Windows服务的某些应用程序

  2. 有可能是其中的几个在网络上

  3. 他们每个人都暴露了一些接口到网络(认为它是遥控器或配置 - 那种事情)

  4. 再有就是作为该接口的客户端的另一个应用程序(使用相同的比喻 - 遥控器或配置工具)

  5. <利>后者的目的是嗅出前者的所有实例的网络上,它们显示作为列表向用户,并允许用户使用该曝光接口(即遥控或戳他们在不同的地方配置他们)
  6. 为了简单起见,我们假设每个人都在同一网络中 - 也就是说,每个人都可以听到对方的UDP广播

  1. There is certain application that gets installed as a Windows Service
  2. There may be several of these on the network
  3. Each of them exposes some interface to the network (think of it as "remote control" or "configuration" - that kind of thing)
  4. Then there is another application that acts as a client for that interface (using same analogies - "remote controller" or "configuration tool")
  5. The objective of the latter is to sniff out all instances of the former on the network, display them as a list to the user and allow the user to poke them in different places using that exposed interface (i.e. "remote control" or "configure" them)
  6. For the sake of simplicity, let's assume that everybody is in the same network - that is, everybody can hear each other's UDP broadcasts.

很简单,不是吗?我曾经在你们昔日的打建这样的事情,用滚我-自己的UDP-基于广播的发现机制。

Pretty straightforward, eh? I used to build this kind of things by the dozen in ye olden days, using roll-my-own UDP-broadcast-based discovery mechanism.

但现在我认为我倒是冷静和臀部,并与常规 WCF发现在Ad Hoc模式。和它的作品!谁可以告诉? : - )

But now I thought I'd be cool and hip, and go with the groovy WCF Discovery in Ad Hoc mode. And it works! Who could tell? :-)

但并不完全。
由于我之前提到这里 和< A HREF =htt​​p://stackoverflow.com/questions/3732489/wcf-discovery-finds-the-endpoint-but-the-address-is-localhost>那里中,发现返回硬编码从URL服务的配置。也就是说,如果服务< baseAddresses><添加baseAddress =的net.tcp://本地主机:1234 /我/服务/>< / baseAddresses> 在它的配置文件,那么这正是我打算从发现客户端获取 - 包括localhost的一部分。

But not quite. As was noted before me here and there, the discovery returns the hard-coded URL from service's config. That is, if the service has <baseAddresses><add baseAddress="net.tcp://localhost:1234/My/Service" /></baseAddresses> in it's config file, then that's exactly what I'm going to get from discovery client - including the "localhost" part.

不用说了,如果我尝试。使用该网址,结果是没有惊心动魄调用服务

Needless to say, if I try to call the service using that URL, the result is not thrilling.

所以,问题是:如何使发现客户给我使用的URL而不是本地主机?-ish垃圾

So the question is: how do I make the discovery client give me the usable URL instead of that localhost-ish garbage?

为了节省大家的时间,一对夫妇的想法,不工作:

To save everybody's time, a couple of thoughts that don't work:


  1. 更改服务的配置文件在部署时,编码它的真实IP地址或机器名称。结果
    不工作,因为IP和机器名可能会改变。

  2. 从代码(至少部分地)配置的服务,使用当前IP或者机器名构造URL。结果
    不工作。计算机名是没用的,因为有可能不是网络中的DNS。 IP是没用的,因为计算机可能会在几个网络一次,因此,有多个IP地址(这不是假设,我们实际上有这种情况)。使用哪一个呢?

  1. Change the service's config file at deployment time, encoding it's real IP address or machine name.
    Doesn't work, because both IP and machine name may change.
  2. Configure the service from code (at least partially), using current IP or machine name to construct the URL.
    Doesn't work. Machine name is useless, because there might not be a dns in the network. IP is useless, because the computer may be on several networks at once, and thus, have several IP addresses (this is not hypothetical, we actually do have this situation). Which one to use then?

在换句话说,我不需要调整服务,而是使发现客户给我该发现响应来自的地址。

In other words, I need not to tweak the service, but rather to make the discovery client give me the address that the discovery response came from.

推荐答案

您应该能够通过更换来解决这个本地主机使用通配符:

You should be able to fix this by replacing localhost with a wildcard:

<baseAddresses><add baseAddress="net.tcp://*:1234/My/Service" /></baseAddresses>

这篇关于WCF发现返回硬编码的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆