暴露的net.tcp端点 [英] exposing net.tcp endpoint

查看:144
本文介绍了暴露的net.tcp端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点困惑如何揭露WCF端点



我有一个TCP端点和MEX TCP端点。

 <服务名称=MessageReaderService.MessageReaderService> 
<端点名称=NetTcpReaderService
地址=ReaderService
结合=NetTcpBinding的bindingConfiguration =
合同=Contracts.IMessageReaderService/>
<端点名称=netTcpMex
地址=MEX
结合=mexTcpBindingbindingConfiguration =
合同=IMetadataExchange接口/>
<主机>
< baseAddresses>
<添加baseAddress =的net.tcp://本地主机:8082/>
< / baseAddresses>
< /主机>
< /服务>

当我尝试在服务主机我得到下面的异常运行此:




合同名称'IMetadataExchange接口无法通过该服务MessageReaderService实施合同
列表中找到。一个的ServiceMetadataBehavior添加到结果
的配置文件或直接的ServiceHost启用此合约的支持。




所以,我从这个错误,我需要添加一个服务行为暴露的元数据得出结论



所以我添加的行为:

 <行为NAME =ServiceBehavior> 
< serviceMetadata httpGetEnabled =真/>
< /行为>



但后来我得到一个不同的错误:



< BLOCKQUOTE>

的ServiceMetadataBehavior的HttpGetEnabled属性设置为true,并且
HttpGetUrl属性是相对地址,但没有HTTP基址。无论是
供应的HTTP基地址或HttpGetUrl到一个绝对地址。





  1. 所以,现在我有实际添加另一个端点(HTTP)暴露在mexhttpbinding元数据?

  2. 有一个简单的方法来揭露端点通过TCP?


解决方案

两件事情:



(1)一旦你定义的服务行为,你当然还必须应用到服务

 <!服务名称= MessageReaderService.MessageReaderService
behaviorConfiguration =ServiceBehavior>



(2)你不需要HTTP端点 - 你不需要有一个HTTP URL - 只是这样定义该服务行为:

 <行为NAME =ServiceBehavior> 
< serviceMetadata />
< /行为>

您的元数据现在可以通过 mexTcpBinding 端点 - 您可以使用HTTP无法浏览到,但客户绝对可以连接到它,使用它



您可以通过使用的 WCF测试客户端并打算为

 的net.tcp://本地主机:8082(基地址)

 的net.tcp://本地主机:8082 / MEX(MEX的地址),

在这两种情况下,WCF测试客户端现在应该找到你的服务,并能发现它的能力。


I'm a bit confused of how to expose an endpoint in WCF

I've got a tcp endpoint and a mex tcp endpoint.

<service name="MessageReaderService.MessageReaderService">
    <endpoint name="NetTcpReaderService" 
        address="ReaderService" 
        binding="netTcpBinding" bindingConfiguration=""
        contract="Contracts.IMessageReaderService" />
    <endpoint name="netTcpMex" 
        address="mex" 
        binding="mexTcpBinding" bindingConfiguration=""
        contract="IMetadataExchange" />
    <host>
       <baseAddresses>
           <add baseAddress="net.tcp://localhost:8082" />
       </baseAddresses>
    </host>
 </service>

When I try to run this in the service host I get the following exception :

The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by the service MessageReaderService. Add a ServiceMetadataBehavior to the
configuration file or to the ServiceHost directly to enable support for this contract.

So I conclude from this error that I need to add a service behavior to expose metadata.

So I added the behavior :

<behavior name="ServiceBehavior">
    <serviceMetadata httpGetEnabled="true"/>                  
</behavior> 

but then I get a different error :

The HttpGetEnabled property of ServiceMetadataBehavior is set to true and the HttpGetUrl property is a relative address, but there is no http base address. Either supply an http base address or set HttpGetUrl to an absolute address.

  1. So now I have to actually add another endpoint (http) to expose the metadata over mexhttpbinding ?
  2. is there a simple way to expose the endpoint over tcp ?

解决方案

Two things:

(1) once you've defined the service behavior, you of course must also apply it to the service!

<service name="MessageReaderService.MessageReaderService"
         behaviorConfiguration="ServiceBehavior">

(2) you don't need an HTTP endpoint - you don't need to have an HTTP URL - just define this service behavior like this:

<behavior name="ServiceBehavior">
    <serviceMetadata />
</behavior> 

Your metadata is now available over a mexTcpBinding endpoint - you cannot browse to it using HTTP, but a client can definitely connect to it and use it!

You can verify this by using the WCF Test Client and going to either

net.tcp://localhost:8082        (the base address)

or

net.tcp://localhost:8082/mex    (the mex address)

in both cases, the WCF Test Client should now find your service and be able to discover its capabilities.

这篇关于暴露的net.tcp端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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