为什么 WCF 测试客户端工具在调试时仅显示多个端点的单个端点基地址?
我的 Windows 服务托管的 WCF 服务有以下配置:
<services>
<service name="MyService" behaviorConfiguration="MyServiceBehavior">
<endpoint address=""
binding="netTcpBinding"
bindingConfiguration="WindowsClientOverTcp"
name="WindowsClientOverTcp"
contract="IMyService" />
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="WindowsClientOverHttps"
name="WindowsClientOverHttps"
contract="IMyService">
</endpoint>
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="https://MyMachine:8250/Services/MyService/Https" />
<add baseAddress="net.tcp://MyMachine:8250/Services/MyService/tcp" />
</baseAddresses>
</host>
</service>
第一:一切正常。不过我有一个问题。当开始在 VS.NET 2010 中调试服务并出现“WCF Test Client”工具时,树顶部仅显示单个“net.tcp://MyMachine:8250/Services/MyService/tcp”地址导航,并且两个端点都显示为子元素(WindowsClientOverTcp 和 WindowsClientOverHttps)。现在两个基地址都是可消耗的并且可用,因此不存在重大问题。但是,为什么工具中只显示单个地址?我认为这可能是 .config 中显示的顺序,所以我交换了它们,但这并没有改变任何东西。
有人知道当单个服务公开多个端点时,为什么两个基地址都不会显示在 WCF 测试客户端工具中?
谢谢!
I have the following configuration for my Windows Service hosted WCF service:
<services>
<service name="MyService" behaviorConfiguration="MyServiceBehavior">
<endpoint address=""
binding="netTcpBinding"
bindingConfiguration="WindowsClientOverTcp"
name="WindowsClientOverTcp"
contract="IMyService" />
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="WindowsClientOverHttps"
name="WindowsClientOverHttps"
contract="IMyService">
</endpoint>
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="https://MyMachine:8250/Services/MyService/Https" />
<add baseAddress="net.tcp://MyMachine:8250/Services/MyService/tcp" />
</baseAddresses>
</host>
</service>
1st: Everything works. However I have a question. When starting to debug the service in VS.NET 2010 and the "WCF Test Client" tool appears, only the single "net.tcp://MyMachine:8250/Services/MyService/tcp" address is displayed at the top of the tree navigation, and both endpoints displayed as child elements (WindowsClientOverTcp & WindowsClientOverHttps). Now both base addresses are consumable and usable so there is no major issue. However, why is it only showing the single address in the tool? I thought it might be the order displayed in the .config so I switched them around but that didn't change anything.
Anyone know why both base addresses do not display in the WCF Test Client tool when having a single service exposing multiple endpoints?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WcfTestClient 根据您提供的 MEX 端点的传输来提供服务。如果您提供基于 HTTP 的端点,它会显示该端点,如果您提供 NET.TCP 端点,则仅此而已。
如果您查看服务生成的 WSDL,您将只能找到该传输的端点描述。并不是 WcfTestClient 受到限制,而是 WSDL 受到限制。
The WcfTestClient is presenting the service based on the transport of the MEX endpoint you are giving it. If you give the HTTP based endpoint it'll present that one, give the NET.TCP one and that's all it presents.
If you look at WSDL generated by the service, you'll find only the endpoint description for that transport. It's not that WcfTestClient that is limited, its the WSDL.
该线程的答案包含我原来问题的答案:
多个基址和多个WCF 中的端点
我很困惑,我可以创建一个具有多个端点和多个 mex 端点的单个服务,但其行为仍然像两个都实现相同合同的服务一样。但是我不喜欢这样,因为当您使用我的服务(通过 net.tcp 或 https)时,两个端点配置都会添加到客户端。我认为我要做的是创建 2 个不同的服务配置,每个配置仍然实现相同的合约,但只是具有唯一的名称和绑定。
WCF 测试客户端在仅读取单个 mex 端点的基础上很好地准确地表示了正在发生的情况,但仍然公开了两个主要服务端点。我真的不喜欢客户端在单个服务中使用多个绑定时获取所有绑定配置(这不是一件坏事,只是不是我想要的方式,因为我的场景中的客户端会不要在单个应用程序中途在绑定类型之间切换)。
因此,总而言之,我将分解配置以公开具有单独端点及其自己的 mex 端点的 (2) 服务,因此使用客户端(和 WCF 测试客户端)对于使用的每个地址将仅获得单个端点配置。
为了做到这一点,我必须进行一些修改,因为两个服务配置不能指向相同的“服务名称”,这是实现合同的实际类。在我的场景中,由于这两个服务仍将实现相同的合同,因此我需要一种方法来为它们提供唯一的名称。我添加了 2 个从原始合约继承的合约(每个服务 1 个)和 2 个从主实现类继承的新类。他们实际上什么也不做,只是为 WCF 服务配置创建单独的占位符。然后每个服务配置都有新类的名称,使它们能够区分。
现在,通过此配置,WCF 测试客户端将每个主要服务端点显示为其自己的实体。如果您不介意客户端获取单个服务的所有端点配置,则不必执行此操作,但在我的情况下,我想要不同的服务地址及其单个下载的配置,但仍执行相同的总体合同。
就此写一点:
在 WCF 中为同一服务类公开多个绑定类型:
http://allen-conway- dotnet.blogspot.com/2011/09/exusing-multiple-binding-types-for.html
This thread's answer contains the answer to my original question:
Multiple Base Addresses and Multiple Endpoints in WCF
I was confused that I could create a single service with multiple endpoints and multiple mex endpoints to still behave like 2 services both implementing the same contract. However I do not like this because when you consume my service (either via net.tcp or https) both endpoint configurations are added to the client. I think what I am going to do is create 2 different service configurations, each still implementing the same contract but just with unique names and bindings.
The WCF Test client did a good job of representing exactly what was occuring, based on only reading the single mex endpoint, but yet still exposing both main service endpoints. I don't really like the fact the client gets all the binding configurations when using multiple bindings within a single service (it's not a bad thing, just not the way I intended because a client in my scenario will not switch between binding types mid-way through a single application).
So in conclusion I will break out the configuration to expose (2) services with separate endpoints and their own mex endpoints, so the consuming client (and WCF Test Client) will get only a single endpoint configuration for each address consumed.
In order to do this though I have to make some modifications, because 2 service configurations can not point to the same "Service Name" which is the actual class implementing the contract. In my scenario since both services will still implement the same contract I need a way to give them unique names. I added 2 more contracts that inherit from the original contract (1 for each service) and 2 new classes that inherit from the main implementation class. They really don't do anything but create separate placeholders for the WCF service configuration. Then each service configuration has the name of the new class allowing them to be distinct.
And now with this configuration, the WCF Test Client shows each main service endpoint as its own entity. This again does not have to be done if you don't mind the client getting all the endpoint configurations for a single service, but in my case I wanted distinct service addresses, with their single downloaded configuration, yet still implementing the same overall contract.
A little write up on this:
Exposing Multiple Binding Types For The Same Service Class In WCF:
http://allen-conway-dotnet.blogspot.com/2011/09/exposing-multiple-binding-types-for.html