【问题标题】:WCF call throws: "The provided URI scheme 'http' is invalid; expected 'net.tcp'." exceptionWCF 调用抛出:“提供的 URI 方案 'http' 无效;应为 'net.tcp'。”例外
【发布时间】:2026-02-03 21:10:01
【问题描述】:

我有一个托管在 IIS7 中的 WCF 服务。

这是我在 IIS 中托管的服务的 app.config

<system.serviceModel>
  <bindings />
  <services>
    <service behaviorConfiguration="querierSearch.Querier.WCF.QuerierBehavior"
      name="querierSearch.Querier.WCF.Querier">
      <endpoint 
         address="net.tcp://localhost:808/querierSearch.Querier.WCF/Querier.svc"
        binding="netTcpBinding" bindingConfiguration="" name="EndPointTCP"
        contract="querierSearch.Querier.WCF.IQuerier" />
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="querierSearch.Querier.WCF.QuerierBehavior">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

下面是客户端中引用 WCF 服务的 app.config。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="EndPointTCP" closeTimeout="00:01:00" 
          openTimeout="00:01:00"
          receiveTimeout="00:10:00" sendTimeout="00:01:00" 
          transactionFlow="false" transferMode="Buffered" 
          transactionProtocol="OleTransactions"
          hostNameComparisonMode="StrongWildcard" listenBacklog="10" 
          maxBufferPoolSize="524288"
          maxBufferSize="65536" maxConnections="10" 
          maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" 
          axArrayLength="16384" maxBytesPerRead="4096" 
          maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
            enabled="false" />
          <security mode="Transport">
            <transport clientCredentialType="Windows" 
            protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://localhost/Search.Querier.WCF/Querier.svc"
        binding="netTcpBinding" bindingConfiguration="EndPointTCP"
        contract="SearchQueryService.IQuerier"
        name="EndPointTCP">
        <identity>
          <userPrincipalName value="joeuser@company.com" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>

由于某种原因,我仍然收到“提供的 URI 方案 'http' 无效;应为 'net.tcp'。”例外。

我不知道为什么.....

【问题讨论】:

    标签: wcf wcf-client


    【解决方案1】:

    实际上,我错过了 mex 端点... 哎呀

    【讨论】:

      【解决方案2】:

      可能是这样

      <serviceMetadata httpGetEnabled="true" />
      

      您要求它在 TCP 服务上启用 HTTP,这似乎可能会导致一些问题。

      【讨论】:

        【解决方案3】:

        我的问题是我刷新Service References 后,web.config 中的behaviorConfiguration删除

        (我的behaviorConfiguration 使用clientVia 地址而不是标准端点地址来允许它穿越防火墙)。

        【讨论】:

          最近更新 更多