找不到与端点的scheme net.tcp匹配的基址

时间:2012-03-15 14:09:40

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

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

  <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].

为什么?

2 个答案:

答案 0 :(得分:2)

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

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

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

答案 1 :(得分:1)

您需要将协议映射添加到配置文件中,以告诉它“net.tcp”协议是什么。在<bindings>部分之后添加以下内容:

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