![](/img/trans.png)
[英]Cannot obtain Metadata from net.tcp://127.0.0.1ServiceName
[英]WCF Cannot obtain Metadata from net.tcp
我正在努力通过net.tcp协议获得基本的WCF服务。 我用VS2017创建了一个新的WCF项目,并没有改变模板代码。 在web.config
设置绑定以分别使用netTcpBinding
和mexTcpBinding
,我收到以下错误:
错误:无法从net.tcp获取元数据://localhost/WcfSecurityTest/Service1.svc如果这是您有权访问的Windows(R)Communication Foundation服务,请检查您是否已在指定地址启用元数据发布。 有关启用元数据发布的帮助,请参阅http://go.microsoft.com/fwlink/?LinkId=65455上的MSDN文档.WS-Metadata Exchange错误URI:net.tcp://localhost/WcfSecurityTest/Service1.svc元数据包含无法解析的引用:'net.tcp://localhost/WcfSecurityTest/Service1.svc'。 无法分派消息,因为端点地址'net.tcp://localhost/WcfSecurityTest/Service1.svc'上的服务不可用于地址协议。
Boilerplate服务代码:
namespace WcfSecurityTest.Service
{
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
}
public class Service1 : IService1
{
public string GetData(int value) {...}
public CompositeType GetDataUsingDataContract(CompositeType composite) {...}
}
}
Service1.svc:
<%@ ServiceHost Language="C#"
Debug="true"
Service="WcfSecurityTest.Service.Service1"
CodeBehind="Service1.svc.cs" %>
web.config中:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="behaviourConfig">
<serviceMetadata />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="netTcpBindingConfig">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="WcfSecurityTest.Service.Service1"
behaviorConfiguration="behaviourConfig">
<endpoint address=""
contract="WcfSecurityTest.Service.IService1"
binding="netTcpBinding"
bindingConfiguration="netTcpBindingConfig" />
<endpoint address="mex"
contract="IMetadataExchange"
binding="mexTcpBinding" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:808/WcfSecurityTest/Service1.svc" />
</baseAddresses>
</host>
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
</system.serviceModel>
我正在使用WCF测试客户端进行测试,当我尝试添加端点时会出现错误: net.tcp://localhost:808/WcfSecurityTest/Service1.svc
。
net.tcp在端口808上的IIS中启用,并且安装了非HTTP激活。
显然我在这里做错了,但我可以找到关于SO和网络文章的每个相关问题都表明这应该有效。
我也遇到过mexTcpBinding的问题。 我通过使用netTcpBinding来实现它。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<protocolMapping>
<clear/>
</protocolMapping>
<bindings>
<netTcpBinding>
<binding name="MyNetTcpBinding"
receiveTimeout="00:15:00" sendTimeout="00:15:00" closeTimeout="00:15:00" openTimeout="00:01:00"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
listenBacklog="10">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="MyDefaultServiceBehaviour">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MyDefaultServiceBehaviour" name="MyWcfService.Contract.MyWcfServiceExternal">
<clear />
<!-- SOAP Endpoints-->
<endpoint address="net.tcp://host/{path}/"
binding="netTcpBinding" bindingConfiguration="MyNetTcpBinding"
name="MyNetTcp" contract="MyWcfService.Contract.IMyWcfServiceSoap"
listenUriMode="Explicit">
</endpoint>
<endpoint address="net.tcp://host/{path}/mex"
binding="netTcpBinding" bindingConfiguration="MyNetTcpBinding"
name="MyMexNetTcp" contract="IMetadataExchange" />
<host>
<timeouts closeTimeout="23:59:59" />
</host>
</service>
</services>
</system.serviceModel>
</configuration>
我没有使用baseAddress
因为我需要更好地控制多个端点,因此{path}
占位符。 这也适用于baseAdress
。
您没有实现元数据端点。
<behaviors>
<serviceBehaviors>
<behavior name="behaviourConfig">
<serviceMetadata />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
它应该是
<behaviors>
<serviceBehaviors>
<behavior name="behaviourConfig">
<serviceMetadata httpGetEnabled="false" >
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
如果要检查是否公开了tcp元数据,请从Visual Studio命令提示符启动wcftestclient.exe并添加代理,您应该更好地进行上述更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.