找不到与net.tcp协议匹配的基址。

35

我已经将我的文件传输服务从basicHttpBinding更改为netTcpBinding,因为我正在尝试设置双工模式通道。我还启动了net.tcp端口共享服务。

目前我在开发阶段,并且在xp桌面自主托管,直到将应用程序移动到开发服务器之前,所以现在我没有访问IIS的权限。

在配置我的服务后:

<service behaviorConfiguration="transferServiceBehavior" name="API.FileTransfer.FileTransferService">
        <endpoint name="MyFileTransferEP"
                  address  = ""
                  binding  = "netTcpBinding"
                  bindingConfiguration="MyFileTransferNetTcpEP"
                  behaviorConfiguration="NetTcpEPBehavior"
                  contract="API.FileTransfer.IFileTransferService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8001/project/filetransfer.svc" />
          </baseAddresses>
        </host>
</service>

我的绑定如下:

<netTcpBinding>
        <binding name="MyFileTransferNetTcpEP"
                 hostNameComparisonMode="StrongWildcard"
                 closeTimeout="00:01:00"
                 openTimeout="00:01:00" 
                 receiveTimeout="00:10:00" 
                 sendTimeout="00:01:00"
                 maxReceivedMessageSize="2147483647"
                 transferMode="Streamed"
                 portSharingEnabled="true">
          <security mode="None">
            <transport clientCredentialType="None" />
            <message clientCredentialType="None" />
          </security>
        </binding>
</netTcpBinding>
当我右键并浏览SVC文件时,出现以下错误:
“无法找到与NetTcpBinding绑定的端点匹配的基址,其方案为net.tcp。已注册的基址方案为[http]。”
在线阅读的建议是,为了解决这个问题,我需要在IIS中将net.tcp绑定添加到应用程序的绑定中。但是,如果我是自托管并且没有访问IIS,我该怎么办呢?顺便说一句,如果您正在阅读此内容并且“有”IIS,请执行以下操作:右键单击IIS中的虚拟目录/应用程序->管理应用程序->高级设置。在启用协议部分中,添加net.tcp。
有什么想法吗?
更新:我以为它已经可以工作了,但它仍然不能正常工作。现在我的情况如下:我仍然收到“找不到与方案net.tcp匹配的基址”的错误。我已更改所有基址以反映您的建议。现在这是我的配置:
<service behaviorConfiguration="transferServiceBehavior" name="API.FileTransfer.FileTransferService">
            <endpoint name="MyJSONFileTransferEP"
                      address="json"
                      binding="webHttpBinding"
                      bindingConfiguration="jsonWeb"
                      behaviorConfiguration="WebHttpEPBehavior"
                      contract="API.FileTransfer.IJSONFileTransferService" />
            <endpoint name="MyPOXFileTransferEP"
                      address="pox"
                      behaviorConfiguration="WebHttpEPBehavior"
                      binding="webHttpBinding"
                      bindingConfiguration="poxWeb"
                      contract="API.FileTransfer.IPOXFileTransferService" />
            <endpoint name="MySOAPFileTransferEP"
                      address="filetransfer"
                      binding="netTcpBinding"
                      bindingConfiguration="netTcpWeb"
                      behaviorConfiguration="NetTcpEPBehavior"
                      contract="API.FileTransfer.ISOAPFileTransferService" />
            <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
            <host>
              <baseAddresses>
                <add baseAddress="net.tcp://localhost:2544/filetransfer/" />
              </baseAddresses>
            </host>
          </service>

我已经尝试过"net.tcp://localhost:2544"和"net.tcp://localhost:8001"两种方式。

我需要在防火墙设置中添加(允许)一些内容吗?还有其他建议吗?

这是我的App.config文件中filetransferservice的mexTcpBinding:

<endpoint address="net.tcp://localhost:2544/filetransfer/mex"
        binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange"
        name="filetransfermex">
        <identity>
          <certificateReference storeName="My" storeLocation="LocalMachine"
            x509FindType="FindBySubjectDistinguishedName" />
        </identity>
      </endpoint>

我仍然无法在我的Web应用程序中引用FileTransferServiceClient。

再次感谢。


嗯,如果你的基地址是"net.tcp://localhost:2544/filetransfer/",而且在你的端点上地址是"filetransfer",那么你的完整URL将会是"net.tcp://localhost:2544/filetransfer/filetransfer" - 你试过连接那里了吗? - marc_s
谢谢 - 犯了一个愚蠢的错误。我通常在那里放“soap”,现在已经改回去了。我花了过去一个小时仔细检查我的App.config和Web.config文件,最终让它编译通过了。当我“添加服务引用”时,我能够引用../trade/mex和.../auth/mex,但我的net.tcp .../filetransfer/mex从未显示为选项。所以,一切都很好地编译了,除了我无法从我的Web应用程序访问FileTransferServiceClient。有任何想法为什么.../filetransfer/mex没有显示出来吗?我正在使用mexTcpBinding,并已发布了我的问题的外观。再次感谢。 - Peter
10个回答

44

错误(WCF): 无法找到与 NetTcpBinding 绑定的端点匹配的基址方案 net.tcp。已注册的基址方案为 [http]。

步骤1: 注意,仅以下平台支持 WAS(Windows进程激活服务) 或非HTTP协议支持: • Windows Vista • Windows 7 • Windows Server 2008

  1. 转到打开或关闭 Windows 功能
  2. 转到 Microsoft .NET Framework 3.5
  3. 选中 Windows Communication Foundation HTTP Activation
  4. 选中 Windows Communication Foundation Non-HTTP Activation

步骤2: IIS > WCF 主机网站 > 管理应用程序 > 高级设置 > 启用协议 > 将值设置为 HTTP,NET.TCP


3
谢谢你,阿米尔。第二步是帮助我的那一步。 - Dev
第二步更有问题:使用PowerShell解决 https://dev59.com/U2jWa4cB1Zd3GeqPpU9P#12473835 - fiat

26

你只需要定义服务的基础地址(而不是整个地址),然后在服务终结点中定义其余部分。你使用以filetransfer.svc结尾的地址不是有效的基础地址(实际上是一个文件地址)。

<service behaviorConfiguration="transferServiceBehavior" 
         name="API.FileTransfer.FileTransferService">
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:8001/project/" />
      </baseAddresses>
    </host>
    <endpoint name="MyFileTransferEP"
              address  = "filetransfer"
              binding  = "netTcpBinding"
              bindingConfiguration="MyFileTransferNetTcpEP"
              behaviorConfiguration="NetTcpEPBehavior"
              contract="API.FileTransfer.IFileTransferService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>

通过这种方式,使用自托管,您的服务将可在完整地址上使用:

net.tcp://localhost:8001/project/filetransfer

由于这是 net.tcp 并且你在自主托管,所以根本不需要 svc 文件。

更新: 如果您想在 net.TCP 基址上获取元数据,则需要在 <service> 部分中添加以下 net.Tcp MEX 端点:

        <endpoint name="NetTcpMEX"
                  address="netTcpMex"
                  binding="mexTcpBinding"
                  contract="IMetadataExchange" />

好像我仍然在收到这个错误。我尝试了你的建议,但似乎没用。我已经更新了我的问题 - 还有其他建议吗?再次感谢。 - Peter
嘿,再次感谢。我现在能够编译我的代码了,但是似乎无法在服务引用UI中添加我的net.tcp服务。此外,我的服务中有 <serviceMetadata httpGetEnabled="True"/>。当我尝试在浏览器中导航到我的url:"net.tcp://localhost:2544/filetransfer/soap"时,它告诉我“Firefox不知道如何打开此地址”。当我尝试从filetransfer.svc文件中浏览(我知道这并不必要)时,我会看到熟悉的错误提示:“找不到与绑定NetTcpBinding的端点匹配的基址。” - Peter
好的,问题已解决(感谢您的回答)。我有一个相关的问题,但我会重新发布。再次感谢。 - Peter
@CodeSherpa,请指导一下您是如何解决“找不到与 NetTcpBinding 绑定的端点的基址”问题的。我已经尝试了这个答案,但它并没有起作用。 - Donald N. Mafa

18

在IIS的“启用协议”条目中出现空格 => 选择虚拟目录/应用程序 => 高级设置 => 启用协议。 例如http,net.tcp。 (协议文本之间有空格)

应将其更改为http,net.tcp(即,协议文本之间没有空格)


10

经过多次尝试之后,我在这个博客中找到了最终解决方案。不过,在此我将详细说明整个过程,您需要按照以下步骤进行操作:

第一步: Windows Process Activation Service(Windows进程激活服务)或非HTTP协议支持仅支持以下平台:• Windows Vista • Windows 7 • Windows Server 2008

  • 前往“打开或关闭Windows功能”
  • 前往Microsoft .NET Framework 3.5
  • 选中Windows Communication Foundation HTTP Activation
  • 选中Windows Communication Foundation Non-HTTP Activation

第二步: IIS > WCF Host Web Site > 管理应用程序 > 高级设置 > 已启用协议 > 将值设置为http、net.tcp

完成第二步后,请检查您的问题是否已得到解决。如果没有,请按以下步骤操作。

第三步: 在“管理员级别的命令提示符窗口”中运行以下命令。

%windir%\system32\inetsrv\appcmd.exe set site "Default Web Site" -+bindings.[protocol='net.tcp',bindingInformation='8082:*']

重新启动IIS一次,否则您现在可能会遇到“Failed to map the path '/'”的异常。

您应用程序的高级设置现在看起来像下面这样

输入图像描述


9

为了未来的读者。

请确保您不要使用IIS Express。

这是我遇到的“坑骗”。

参考:

http://www.iis.net/learn/extensions/introduction-to-iis-express/iis-express-faq

        Q: Does IIS Express support non-HTTP protocols such as net.tcp or MSMQ?
        A: No. IIS Express only supports HTTP and HTTPS as its protocol.

这是Visual Studio和web.csproj(或类似)属性下的一个属性,位于“Web”选项卡下。有一个名为“使用IIS Express”的复选框,请取消勾选。
取消勾选后,您仍需前往IIS(7),并将“启用的协议”设置为“http,net.tcp”(如其他答案所述)。
另外,如果出现了命名管道特定的错误:
无法找到与绑定NetNamedPipeBinding的端点匹配的基址方案net.pipe。
则需要将"net.pipe"添加到列表中。
示例:

http,net.tcp,net.pipe

以下是有关命名管道特定错误的信息。

将WCF配置为在IIS7上托管命名管道

另外,请检查这些相应的Windows服务(命名管道或TCP或两者兼备)

(命名管道Windows服务)

NetPipeActivator

Net.Pipe Listener Adapter

Receives activation requests over the net.pipe protocol and passes them to the Windows Process Activation Service.
< p >(TCP Windows 服务)< /p >
NetTcpActivator

Net.Tcp Listener Adapter

Receives activation requests over the net.tcp protocol and passes them to the Windows Process Activation Service.

5
请在控制面板中安装“非 Http 激活”窗口组件 -> 程序 -> 打开或关闭 Windows 功能 -> 功能 -> 添加功能 -> .NET Framework * 功能 -> WCF 激活 -> 非 Http 激活。

3

Windows 10 操作系统
步骤1:转到“打开或关闭 Windows 功能” > .Net Framework 4.6 高级服务 > WCF 服务 > TCP 激活。

步骤2:IIS > WCF 主机网站 > 管理应用程序 > 高级设置 > 启用的协议 > 将值设置为 net.tcp,http。

步骤3:使用管理员权限打开命令提示符 > 输入 iisreset。


1

我遇到了同样的问题(环境:Win7/IIS7.5 .NET4),通过使用位于目录"c:\Windows\System32\inetsrv"下的appcmd.exe配置绑定,我解决了这个问题。

"appcmd.exe set pp "WebsiteName/applicationName" /enabledProtocols:http,net.tcp"

注意:IIS配置是分层的,因此我们应该在可能的最低级别更改配置,以避免对其他应用程序造成不必要的更改/安全问题。

以下链接可能有所帮助: http://msdn.microsoft.com/en-us/library/ms788757.aspx http://support.microsoft.com/kb/2803161

希望这可以帮到你。 Albert


0

我在Windows 7上遇到了同样的错误,通过打开IIS,右键单击承载您应用程序的网站并选择“编辑绑定...”来解决它。我在这里添加了net.tcp绑定,问题得到了解决。

站点绑定截图


-1
<add baseAddress="net.tcp://localhost:8090" />

请按照配置文件中所示进行编辑。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接