今天做一个WCF文件传输的案例,使用tcp方式传输,最后为了生成客户端配置文件 采用svcutil工具 一直出问题,最后发现是mex端点没配置。
Setting environment for using Microsoft Visual Studio 2008 x86 tools.
E:\DevelopPath\Program Files\Microsoft Visual Studio 9.0\VC>svcutil net.tcp://localhost:8000/service /config: app.config /out:Proxy.cs
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation,版本 3.0.4506.2152]
版权所有(c) Microsoft Corporation。保留所有权利。
正在尝试使用 WS-Metadata Exchange 从“net.tcp://localhost:8000/service”下载元数据。此 URL 不支持 DISCO。
Microsoft (R) Service Model Metadata Tool[Microsoft (R) Windows (R) Communication Foundation,版本 3.0.4506.2152] 版权所有(c) Microsoft Corporation。保留所有权利。
错误: 无法从 net.tcp://localhost:8000/service 获取元数据
如果是您有权访问的 Windows (R) Communication Foundation 服务,请检查是否已启用在指定地址发布元数据。有关启用元数据发布的帮助,请参阅http://go.microsoft.com/fwlink/?LinkId=65455上的 MSDN 文档。
WS-Metadata Exchange 错误
URI: net.tcp://localhost:8000/service
元数据包含无法解析的引用:“net.tcp://localhost:8000/service”。
没有终结点在侦听可以接受消息的 net.tcp://localhost:8000/service。这通常是由于不正确的地址或者 SOAP 操作导致的。如果存在此情况,请参阅 InnerException 以了解详细信息。
如果希望获取更多帮助,请键入“svcutil /?”
一查原来是没配置元数据端点,这是我重新更改后正确的服务端配置文件,可以比对一下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NewBinding0" maxReceivedMessageSize="1073741824" transferMode="Streamed" />
</netTcpBinding>
</bindings>
<services>
<service name="FileService2.FileSave" behaviorConfiguration="mexConfig" >
<endpoint address="FileSave"
binding="netTcpBinding"
bindingConfiguration="NewBinding0"
name="FileSaveName"
contract="FileInterface.IFileInterface" />
<endpoint address="mex"
binding="mexTcpBinding"
name="MEX"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8000/service" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexConfig">
<serviceDebug includeExceptionDetailInFaults="True"/>
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
红色部分是后来添加上去的,至此就成功了。