使用NetTcpBinding的WCF服务库

Jos*_*osh 7 .net c# 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)
Run Code Online (Sandbox Code Playgroud)

当我使用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>
Run Code Online (Sandbox Code Playgroud)

小智 18

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


Bri*_*ian 7

在这个部分

<host>          
  <baseAddresses>            
    <add baseAddress="http://localhost:8731/.../" />   
  </baseAddresses>        
</host>
Run Code Online (Sandbox Code Playgroud)

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

<host>
  <baseAddresses>
    <add baseAddress="http://localhost:8732/" />
    <add baseAddress="net.tcp://localhost"/>
  </baseAddresses>
</host>
Run Code Online (Sandbox Code Playgroud)