WCF服务库与NetTcpBinding技术

7
我正在遇到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>

你能否发布一下你的WCF配置文件(app/web.config)? - jrista
即使我发布了它,也无法看到它。 - Josh
添加后,请按代码按钮(将每行缩进4个空格并不解释xml)。 - Brian
明白了...谢谢...没意识到这个事实也适用于XML :) - Josh
5个回答

18

我相信你现在已经解决了问题,但这与所有公告板都会提到的 baseAddresses 没有任何关系。我在 http://social.msdn.microsoft.com/forums/en-US/wcf/thread/c9f8d99d-89ee-4573-8528-a21b047bad11 找到了答案。假设你正在使用 IIS 7.x:在 IIS 中右键单击虚拟目录/应用程序,选择“管理应用程序”->“高级设置”。在“启用的协议”部分中添加 net.tcp,例如:http、net.tcp。即使你已经在站点级别添加了此协议,这也是必需的。


我看到你在绑定中也将安全模式设置为“无”,这是我最初使用的方式,但是对于我的操作,我需要知道已验证的调用者。我通常从OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name获取此信息(http://www.leastprivilege.com/HostingWCFServicesInASPNETTheSurvivalGuide.aspx)。因此,我改变了*客户端和服务器*上的绑定,按照http://msdn.microsoft.com/en-us/library/ms733089.aspx进行了Windows身份验证的传输安全。 - Helder
如何在IIS6中实现这个?有什么想法吗? - NLV
谢谢...我已经盯着这个配置文件大约两个小时了,但是我还是无法弄清楚发生了什么... - SoftwareSavant
是的,是的,是的,千遍万遍的是;我忘记做这件事了,一直在努力想弄清楚我需要改变什么,因为我确信我不需要提供基地址。 - Bruno Brant

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>

添加不起作用。它显示端口正在使用的错误。你能帮我完成那一行吗?谢谢。 - Josh
System.ServiceModel.AddressAlreadyInUseException:TransportManager无法使用NetTcpPortSharing服务在提供的URI上进行侦听:服务侦听失败。 - Josh
请确保使用不同的端口(例如,如果http在8731上,则使用8732:net.tcp://localhost:8732/Yadda/Blah/)。 - Brian
我无法使用多个端口,因为我计划在部署的asp.net应用程序上使用它。我正在尝试使用net.tcp共享...但它也失败了。我已经在这里的另一个问题中询问了那个错误... https://dev59.com/l0jSa4cB1Zd3GeqPJ_RW - Josh
我在你的app.config中看到了portSharingEnabled=false。 话说,我不确定你是否可以这样共享http和tcp(不记得了)。 - Brian
请查看我在您的另一个帖子中回复的内容,以获取有关端口共享问题的答案:https://dev59.com/l0jSa4cB1Zd3GeqPJ_RW - jrista

3

2

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


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

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