【问题标题】:Could not find a base address that matches scheme net.tcp for the endpoint找不到与端点的方案 net.tcp 匹配的基地址
【发布时间】:2012-03-15 14:09:40
【问题描述】:

我有一个 Wcf 服务项目。 system.serviceModel 我的 web.config 中的标签是:

  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="RCISPNetTcpBinding" openTimeout="00:10:00" sendTimeout="00:10:00">
          <security mode="Transport">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign">
            </transport>
            <message clientCredentialType="Windows"/>
          </security>
        </binding>
      </netTcpBinding>
    </bindings>

    <services>
      <service behaviorConfiguration="RCISP.WcfServiceBehaviour" name="RCISP.WcfService.PersonWcfService">
        <endpoint address="PersonServices" binding="netTcpBinding" bindingConfiguration="RCISPNetTcpBinding"
          contract="RCISP.Common.ServiceContract.IPersonService" >
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:40003/"/>
          </baseAddresses>
        </host>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="RCISP.WcfServiceBehaviour">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceAuthorization principalPermissionMode="UseWindowsGroups" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

当我想为服务创建自托管时出现运行时错误。

    public class ServiceFactory : ServiceHostFactory
    {
       protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
       {
          if (!IsInitialised) InitialiseService();
             return base.CreateServiceHost(serviceType, baseAddresses);
       }

    }

异常消息是:

Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].

为什么?

【问题讨论】:

标签: c# asp.net wcf wcf-binding wcf-security


【解决方案1】:

您说您是自行托管服务(在您自己的进程中),但根据上面的代码,我认为您正在尝试将它托管在 Web 应用程序中。如果是这样,Visual Studio 的 Web 服务器不能托管 net.tcp 端点。您需要将项目设置为在 IIS 下运行。请按照here 的说明操作。

如果您是真正的自托管,那么您可以完全按照自己的方式保留配置并使用以下代码启动服务:

var host = new ServiceHost(typeof(Service1));
host.Open();

【讨论】:

    【解决方案2】:

    您需要在配置文件中添加一个协议映射来告诉它“net.tcp”协议是什么。在您的 &lt;bindings&gt; 部分之后添加以下内容:

    <protocolMapping>
      <add scheme="net.tcp" binding="netTcpbinding"/>
    </protocolMapping>    
    

    【讨论】:

      猜你喜欢
      • 2010-12-20
      • 2015-07-21
      • 2016-04-03
      • 2020-06-02
      • 1970-01-01
      • 2017-08-13
      • 1970-01-01
      • 2013-11-23
      • 1970-01-01
      相关资源
      最近更新 更多