使用NetTcpBinding的WCF服务库

时间:2009-08-19 04:04:26

标签: c# .net wcf wcf-binding

我在使用NetTcpBinding时遇到了困难。

当我运行我的WCF服务时,我得到了这个:

System.InvalidOperationException: Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].
   at System.ServiceModel.ServiceHostBase.MakeAbsoluteUri(Uri relativeOrAbsoluteUri, Binding binding, UriSchemeKeyedCollection baseAddresses)
   at System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress)
   at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, ServiceElement serviceSection)
   at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, String configurationName)
   at System.ServiceModel.ServiceHostBase.ApplyConfiguration()
   at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses)
   at System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses)
   at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
   at Microsoft.Tools.SvcHost.ServiceHostHelper.CreateServiceHost(Type type, ServiceKind kind)
   at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)

我在使用WCFSvcHost默认运行应用程序时遇到此问题。 没有额外的代码。只需要任何新的wcf服务的默认代码。 我想做的就是将绑定更改为tcp。

如何解决这个问题?

编辑:这是我的WCF的App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="tcpBinding" transferMode="Streamed" portSharingEnabled="false">
          <reliableSession enabled="true" />
          <security mode="None">
            <transport clientCredentialType="None" protectionLevel="None" />
            <message clientCredentialType="None" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="WcfServiceLibrary1.Service1Behavior"
        name="WcfServiceLibrary1.Service1">
        <endpoint address="" binding="wsHttpBinding" contract="WcfServiceLibrary1.IService1">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <endpoint address="Service" binding="netTcpBinding" bindingConfiguration="tcpBinding"
          name="testTcp" contract="WcfServiceLibrary1.IService1" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfServiceLibrary1.Service1Behavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

5 个答案:

答案 0 :(得分:18)

我相信你现在已经解决了这个问题,但它确实与baseAddresses无关,而这正是所有bullentin板引导你的。我在http://social.msdn.microsoft.com/forums/en-US/wcf/thread/c9f8d99d-89ee-4573-8528-a21b047bad11找到了答案。假设您使用的是IIS 7.x:右键单击IIS中的虚拟目录/应用程序,选择Manage application - &gt;高级设置。在'Enabled Protocols'部分中添加net.tcp,例如:http,net.tcp。即使您已在站点级别添加此协议,这也是必要的。

答案 1 :(得分:7)

在本节中

<host>          
  <baseAddresses>            
    <add baseAddress="http://localhost:8731/.../" />   
  </baseAddresses>        
</host>

添加net.tcp://基地址。

<host>
  <baseAddresses>
    <add baseAddress="http://localhost:8732/" />
    <add baseAddress="net.tcp://localhost"/>
  </baseAddresses>
</host>

答案 2 :(得分:3)

你可以共享端口,这不是太难。

确保在IIS中选择启用的协议(右键单击网站 - &gt;管理网站 - >高级设置),不要使用空间。如果你有“http,net.tcp”而不是“http,net.tcp”它将无法正常工作,而是给你这个确切的错误。

此处提供更多信息:http://www.weeksofprogramming.com/post/Could-not-find-a-base-address-Check-for-spaces-in-IIS7.aspx

答案 3 :(得分:2)

在IIS站点中配置net.tcp绑定,并将启用的协议设置为“http,使用高级设置的net.tcp”。它应该可以工作

答案 4 :(得分:1)

  1. 确认已在计算机上启动Net.Tcp端口共享服务
  2. 验证配置netTcpBinding portSharingEnabled属性是否为true。 (在WCF4中,如果希望此绑定规范成为net.tcp的默认规则,则无需在绑定元素上提供名称)