gpt4 book ai didi

c# - WCF 无法从 net.tcp 获取元数据

转载 作者:可可西里 更新时间:2023-11-01 02:46:05 25 4
gpt4 key购买 nike

我正在努力让基本的 WCF 服务通过 net.tcp 协议(protocol)工作。我用 VS2017 创建了一个新的 WCF 项目,并且根本没有更改模板代码。在 web.config 中设置绑定(bind)以分别使用 netTcpBindingmexTcpBinding 后,我收到以下错误:

Error: Cannot obtain Metadata from net.tcp://localhost/WcfSecurityTest/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: net.tcp://localhost/WcfSecurityTest/Service1.svc Metadata contains a reference that cannot be resolved: 'net.tcp://localhost/WcfSecurityTest/Service1.svc'. The message could not be dispatched because the service at the endpoint address 'net.tcp://localhost/WcfSecurityTest/Service1.svc' is unavailable for the protocol of the address.

样板服务代码:

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) {...}
}
}

服务 1.svc:

<%@ ServiceHost Language="C#"
Debug="true"
Service="WcfSecurityTest.Service.Service1"
CodeBehind="Service1.svc.cs" %>

网络配置:

<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 在 IIS 中启用了端口 808 并且安装了非 HTTP 激活。

enter image description here

显然我在这里做错了什么,但我能找到的关于 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

关于c# - WCF 无法从 net.tcp 获取元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47531028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com