WCF配置文件---netTcpBinding

sdf4r4t 2015-10-05 11:10:41
一个服务端配置文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<customErrors mode="Off" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="netTcpBindingConfiguration">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647 " maxArrayLength="2147483647 " maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="Services.MyService" behaviorConfiguration="metadataBehavior">
<endpoint address="MyService" binding="netTcpBinding" contract="Contracts.IService" bindingConfiguration="netTcpBindingConfiguration" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9999/"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>

上面是WCF服务端配置文件,添加了2个终结点,一个采用的是netTcpBinding协议,一个采用的是mexTcpBinding协议。
那传输的时候,到底使用的是哪个协议啊?address为什么写成mex啊?
...全文
266 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
宝_爸 2015-10-07
  • 打赏
  • 举报
回复
添加引用其实就是visual studio帮你生成代理类,然后,你就可以像使用本地class那样使用web service/wcf. WCF/web service本身并不能描述自己,因此会有wsdl这种标准来描述web service. 而mex是比wsdl更新的描述定义。 添加Service reference...就是根据wsdl/mex对于service 描述生成代理类。真正调用service的时候还是调用MyService那个endpoint. 我这边创建了一个新的WCF 工程做了下测试: 1. 删除mex endpoint和设置serviceMetadata为false <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false"/> 这个是生成wsdl的配置。 启动 WCF Test Client, 得到下面的错误 Error: Cannot obtain Metadata from http://localhost:63246/Service1.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:63246/Service1.svc Metadata contains a reference that cannot be resolved: 'http://localhost:63246/Service1.svc'. Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:63246/Service1.svc. The client and service bindings may be mismatched. The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..HTTP GET Error URI: http://localhost:63246/Service1.svc The HTML document does not contain Web service discovery information. 2. enable mex 和serviceMetadata任何一个 启动WCF Test client, 没有任何问题,任何一个WCF方法都可以调用成功 3. a enable mex 和serviceMetadata b启动WCF Test client, 这时候调用方法没有问题 c 不要关闭WCF Test Client, . 删除mex endpoint和设置serviceMetadata为false d 调用WCF方法,依旧可以成功。 这是因为客户端的代理类已经在步骤b生成完成,即使步骤c删除了mex和serviceMetadata, wcf service本身依然可用。 希望这个解释能让你明白mex的作用,你也可以自己创建个测试工程把玩一下。
ajianchina 2015-10-06
  • 打赏
  • 举报
回复
1、一个wcf服务可以有多个终节点,你可以认为终节点就是服务的接口,你这里配置了两个终结点,就意味着你的服务实现两个服务接口,同时两种binding可以提供两种不同的方式访问。 2、address="mex"这其实是一个相对地址,相对的是基地址localhost:9999/,所以他真实的完整地址是localhost:9999/mex。 3、从address="mex"这一地址的契约设定为"IMetadataExchange"来看,这一地址专门提供了一个元数据交换的服务契约接口,通过这一地址服务发布元数据。
ajianchina 2015-10-06
  • 打赏
  • 举报
回复
1、一个wcf服务可以有多个终节点,你可以认为终节点就是服务的接口,你这里配置了两个终结点,就意味着你的服务实现两个服务接口,同时两种binding可以提供两种不同的方式访问。 2、address="mex"这其实是一个相对地址,相对的是基地址localhost:9999/,所以他真实的完整地址是localhost:9999/mex。 3、从address="mex"这一地址的契约设定为"IMetadataExchange"来看,这一地址专门提供了一个元数据交换的服务契约接口,通过这一地址服务发布元数据。
宝_爸 2015-10-06
  • 打赏
  • 举报
回复
你说的找不到服务是说调用时找不到,还是添加引用时找不到?
sdf4r4t 2015-10-06
  • 打赏
  • 举报
回复
引用 5 楼 findcaiyzh 的回复:
[quote=引用 4 楼 sdf4r4t 的回复:] [quote=引用 3 楼 findcaiyzh 的回复:] mexTcpBinding是看接口信息的,是由.net帮你实现的。 你自己那个是<endpoint address="MyService"  binding="netTcpBinding" contract="Contracts.IService" b
我试了一下删除mexTcpBinding那个endpoint,结果客户端添加服务的时候就找不到服务,这是为什么呢? 如果加上mexTcpBinding那个endpoint的话,这个WCF服务是不是还是采用的netTcpBinding协议呢? 如果加上mexTcpBinding那个endpoint的话,在客户端添加服务的URL地址为:net.tcp://localhost:9999/mex,如果是http://localhost:9999/MyService则又是找不到服务,为什么会是这样的啊,没有MyService做限制,怎么知道调用的是哪个WCF服务呢?[/quote] 添加服务的时候需要知道这个服务的方法名称,参数等等,是描述服务的,由mex提供。应该不影响调用你的服务http://localhost:9999/MyService。 调用服务使用的是MyService endpoint. 获得服务描述信息的时候用的是mex endpoint.[/quote] 说错了,应该是net.tcp://localhost:9999/MyService,为什么这个URL在客户端找不到服务呢,而需要net.tcp://localhost:9999/mex才能找到服务?
宝_爸 2015-10-06
  • 打赏
  • 举报
回复
引用 4 楼 sdf4r4t 的回复:
[quote=引用 3 楼 findcaiyzh 的回复:] mexTcpBinding是看接口信息的,是由.net帮你实现的。 你自己那个是<endpoint address="MyService"  binding="netTcpBinding" contract="Contracts.IService" b
我试了一下删除mexTcpBinding那个endpoint,结果客户端添加服务的时候就找不到服务,这是为什么呢? 如果加上mexTcpBinding那个endpoint的话,这个WCF服务是不是还是采用的netTcpBinding协议呢? 如果加上mexTcpBinding那个endpoint的话,在客户端添加服务的URL地址为:net.tcp://localhost:9999/mex,如果是http://localhost:9999/MyService则又是找不到服务,为什么会是这样的啊,没有MyService做限制,怎么知道调用的是哪个WCF服务呢?[/quote] 添加服务的时候需要知道这个服务的方法名称,参数等等,是描述服务的,由mex提供。应该不影响调用你的服务http://localhost:9999/MyService。 调用服务使用的是MyService endpoint. 获得服务描述信息的时候用的是mex endpoint.
sdf4r4t 2015-10-06
  • 打赏
  • 举报
回复
引用 10 楼 findcaiyzh 的回复:
添加引用用到的是mex那个endpoint
添加引用用到的是mex那个endpoint?为什么不能添加MyService那个endpoint呢? 为什么不能添加MyService那个endpoint呢?
sdf4r4t 2015-10-06
  • 打赏
  • 举报
回复
引用 3 楼 findcaiyzh 的回复:
mexTcpBinding是看接口信息的,是由.net帮你实现的。 你自己那个是<endpoint address="MyService"  binding="netTcpBinding" contract="Contracts.IService" b
我试了一下删除mexTcpBinding那个endpoint,结果客户端添加服务的时候就找不到服务,这是为什么呢? 如果加上mexTcpBinding那个endpoint的话,这个WCF服务是不是还是采用的netTcpBinding协议呢? 如果加上mexTcpBinding那个endpoint的话,在客户端添加服务的URL地址为:net.tcp://localhost:9999/mex,如果是http://localhost:9999/MyService则又是找不到服务,为什么会是这样的啊,没有MyService做限制,怎么知道调用的是哪个WCF服务呢?
宝_爸 2015-10-06
  • 打赏
  • 举报
回复
mexTcpBinding是看接口信息的,是由.net帮你实现的。 你自己那个是<endpoint address="MyService"  binding="netTcpBinding" contract="Contracts.IService" b
宝_爸 2015-10-06
  • 打赏
  • 举报
回复
添加引用用到的是mex那个endpoint
宝_爸 2015-10-06
  • 打赏
  • 举报
回复
难道net.tcp不一样?记得http的输入.svc的地址就可以了。
sdf4r4t 2015-10-06
  • 打赏
  • 举报
回复
引用 7 楼 findcaiyzh 的回复:
你说的找不到服务是说调用时找不到,还是添加引用时找不到?
添加引用找不到

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧