简体   繁体   English

WCF在IIS中使用netTcpBinding

[英]WCF use netTcpBinding in IIS

I follow this blog CONFIGURING WCF SERVICE WITH NETTCPBINDING step by step, when I add service reference from VS 2013, I got below error. 我按照博客逐步使用NETTCPBINDING配置WCF服务 ,当我从VS 2013添加服务引用时,出现以下错误。

The URI prefix is not recognized.
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost/WCFNetTcp/WCFNetTcpService.svc/mex'.
You have tried to create a channel to a service that does not support .Net Framing. It is possible that you are encountering an HTTP endpoint.
Expected record type 'PreambleAck', found '72'.  

My Service configure file is below: 我的服务配置文件如下:

  <system.serviceModel>
    <services>
      <service behaviorConfiguration="netTcpb" name="WCFNetTcp.WCFNetTcpService">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="portSharingBinding" contract="WCFNetTcp.IWCFNetTcpService" />
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
        <!--<endpoint address="mexHttp" binding="mexHttpBinding" contract="IMetadataExchange" />-->
        <host>
          <baseAddresses>
            <!--<add baseAddress="net.tcp://localhost:6666/WCFNetTcpService/"/>-->
            <add baseAddress="net.tcp://localhost:808/WCFNetTcp/WCFNetTcpService.svc" />
            <!--<add baseAddress="http://local/WCFNetTcp"/>-->
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="netTcpb">
          <serviceMetadata httpGetEnabled="false"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <netTcpBinding>
        <binding name="portSharingBinding" portSharingEnabled="true"/>
      </netTcpBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
      <baseAddressPrefixFilters>
        <add prefix="net.tcp://localhost:808"/>
      </baseAddressPrefixFilters>
    </serviceHostingEnvironment>
  </system.serviceModel>

I tried any net.tcp URL what I could think out, but all of them do not work. 我尝试了所有可以想到的net.tcp URL,但所有这些都无法正常工作。 It seems that basic address did not work when the service is hosted in IIS, it depends on the url in IIS. 当服务托管在IIS中时,基本地址似乎不起作用,它取决于IIS中的url。 If I create a service which is hosted in console application with below configuration file, it works. 如果我使用下面的配置文件创建了在控制台应用程序中托管的服务,则它将起作用。

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceMetadata httpGetEnabled="false"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
    <services>
        <service name="WCFNETTCP.Service1">
            <endpoint address="" binding="netTcpBinding" contract="WCFNETTCP.IService1">
            </endpoint>
            <!--comment out after you add service reference-->
            <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
            <host>
                <baseAddresses>
                    <add baseAddress="net.tcp://xxx:6666/WCFNETTCP/" />
                    <add baseAddress="http://xxx:6667/WCFNETTCIP"/>
                </baseAddresses>
            </host>
        </service>
    </services>
</system.serviceModel>

It would be appreciated if you could share us how to make it work under IIS. 如果您可以与我们分享如何使其在IIS下工作,将不胜感激。

It seems there is something wrong in my IIS. 看来我的IIS有问题。 I resolved this issue by below steps. 我通过以下步骤解决了此问题。

  1. reinstall IIS 重新安装IIS
  2. reinstall WCF Non-HTTP Activation in Windows features 在Windows功能中重新安装WCF非HTTP激活
  3. reregister asp.net in iis by this command 通过此命令在iis中重新注册asp.net

C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319>dism /online /enable-feature /featurename:IIS-ASPNET45 C:\\ Windows \\ Microsoft.NET \\ Framework64 \\ v4.0.30319> dism / online /启用功能/功能名称:IIS-ASPNET45

  1. Check the settings in IIS which there is no change at my side. 检查IIS中没有任何更改的设置。
  2. Rebuild my WCF Service, and add service reference successfully. 重建我的WCF服务,并成功添加服务引用。
    Hope it will be work for you. 希望对您有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM