WCF4.0安装及NET.TCP启用

WCF 4.0 一般默认安装.net Framework 4.0的时候已经安装。

但如果先装.net framework 4.0,后装IIS,就会出现问题。需要重新注册WCF4.0。

WCF4.0 已经是.net 4.0的一个内部组件,不需要.net3.5 那样麻烦先装windows组件。

一、确认是否安装WCF4.0:

如下图,查看*.svc 后缀的文件是否被svc-Integrated-4.0 或 svc-ISAPI-4.0_64/32bit 程序处理:

 如果没有上面的三个处理程序,则可以判定 wcf 4.0 没有安装。

二、安装WCF 4.0

找到对应的.net framework 目录,运行命令:

"%WINDIR%\Microsoft.Net\Framework\v4.0.30319\aspnet_regiis" –i –enable

"%WINDIR%\Microsoft.Net\Framework\v4.0.30319\ServiceModelReg.exe" -r

Running the command aspnet_regiis –i –enable will make the Default App Pool run using .NET Framework 4, which may produce incompatibility issues for other applications on the same computer.

如果你有另外的app Pool,可以不用管这个 –enable,可以手动去设置那个pool的.net 版本是4.0.

 

三、启动服务:NetTCP Listener Adapter 和 Net TCp Port Sharing Service:

 

四、为IIS站点配置NETTCP协议支持:

1)绑定808:*端口:

2)启用net.tcp协议:

如果不配置会出现下面错误:

Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].

五、WCF3.0 和WCF 4.0 冲突:

如果有.net 3.5 和.net 4.0同时存在,有可能程序会找错对应的处理程序。

Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′.

重新注册就可以:

"%WINDIR%\Microsoft.Net\Framework\v4.0.30319\aspnet_regiis" –i –enable

"%WINDIR%\Microsoft.Net\Framework\v4.0.30319\ServiceModelReg.exe" -r

我有参考这篇文章:http://www.cnblogs.com/Gyoung/archive/2012/12/11/2812555.html

在 WCF 4.0 启用NET.TCP  不需要 这2个操作:

1) 安装WAS

2) 确定WCF是否启用Non-Http支持

六、其他可能的错误:

1) IIS站点多主机头绑定的错误:

Server Error in '/WcfServiceOfMyTest' Application.

This collection already contains an address with scheme http. There can be at most one address per scheme in this collection. If your service is being hosted in IIS you can fix the problem by setting 'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled' to true or specifying 'system.serviceModel/serviceHostingEnvironment/baseAddressPrefixFilters'.
Parameter name: item

方法是:在config的</system.serviceModel> 里面允许多主机头绑定:

</system.serviceModel>
.......
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

2) 为什么测试界面的协议不一样

svcutil.exe http://localhost/WcfServiceOfMyTest/Service1.svc?wsdl

svcutil.exe net.tcp://dst52382.cn1.global.ctrip.com/WcfServiceOfMyTest/Service1.svc/mex

区别在协议 http 和 net.tcp 的是否启用,配置在这里会影响:

 <serviceMetadata httpGetEnabled="false"/>

七、测试程序

新建一个默认的wcf service

配置如下:

<?xml version="1.0"?>
<configuration> <system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<protocolMapping>
<add scheme="tcp" binding="netTcpBinding"/>
</protocolMapping>
<bindings>
<netTcpBinding>
<binding name="netTcpBindConfig" closeTimeout="00:30:00" portSharingEnabled="true"
openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxConnections="100" maxReceivedMessageSize="2147483647"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="100"> <readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:01:00" enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<services> <service behaviorConfiguration="MyBehavior" name="WcfServiceOfMyTest.Service_Test_NetTcp"> <!--这个服务名字不是随便取得,要跟你的class文件里的类的名字一致!-->
<endpoint address="" binding="netTcpBinding" contract="WcfServiceOfMyTest.IJustAnInterface" bindingConfiguration="netTcpBindConfig"></endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" ></endpoint>
</service> </services>
<behaviors>
<serviceBehaviors>
<behavior name="MyBehavior" >
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel> <system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer> </configuration>

这个配置会有错误:

There is no compatible TransportManager found for URI 'net.tcp://dst52382.cn1.global.ctrip.com/WcfServiceOfMyTest/Service1.svc/mex'. This may be because that you have used an absolute address which points outside of the virtual application, or the binding settings of the endpoint do not match those that have been set by other services or endpoints. Note that all bindings for the same protocol should have same settings in the same application.

对应的中文描述:

未找到 URI“net.tcp://gyoung/Service1.svc/mex”的兼容 TransportManager。这可能是因为使用了指向虚拟应用程序外部的绝对地址,或终结点的绑定设置与其他服务或终结点所设置的绑定设置不匹配。 请注意,同一协议的所有绑定在同一应用程序中应具有相同的设置。

这个错误的重点在后半句话,endpoint的binding配置需要一致,这里2个endpoint,一个是服务终结点,它的 maxConnections="100" 不是默认值10,另外一个是元数据终结点,这里的max connection默认是10.

<endpoint address="" binding="netTcpBinding"
<endpoint address="mex" binding="mexTcpBinding"

他们的binding类型不一致。将他们改为一致。如下:
 <service behaviorConfiguration="MyBehavior" name="WcfServiceOfMyTest.Service_Test_NetTcp">
<endpoint address="" binding="netTcpBinding" contract="WcfServiceOfMyTest.IJustAnInterface" bindingConfiguration="netTcpBindConfig"></endpoint>
<endpoint address="mex" binding="netTcpBinding" contract="IMetadataExchange" bindingConfiguration="netTcpBindConfig" ></endpoint>
</service>

八、完整源代码:

接口源代码:
namespace WcfServiceOfMyTest
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IJustAnInterface
{ [OperationContract]
string GetData(int value); [OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite); // TODO: Add your service operations here
} // Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello "; [DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
} [DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}
服务源代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text; namespace WcfServiceOfMyTest
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service_Test_NetTcp : IJustAnInterface
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
} public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
}

web.config 配置:

<?xml version="1.0"?>
<configuration> <system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<protocolMapping>
<add scheme="tcp" binding="netTcpBinding"/>
</protocolMapping>
<bindings>
<netTcpBinding>
<binding name="netTcpBindConfig" closeTimeout="00:30:00" portSharingEnabled="true"
openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxConnections="100" maxReceivedMessageSize="2147483647"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="100"> <readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:01:00" enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<services> <service behaviorConfiguration="MyBehavior" name="WcfServiceOfMyTest.Service_Test_NetTcp">
<endpoint address="" binding="netTcpBinding" contract="WcfServiceOfMyTest.IJustAnInterface" bindingConfiguration="netTcpBindConfig"></endpoint>
<endpoint address="mex" binding="netTcpBinding" contract="IMetadataExchange" bindingConfiguration="netTcpBindConfig" ></endpoint>
</service> </services>
<behaviors>
<serviceBehaviors>
<behavior name="MyBehavior" >
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel> <system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer> </configuration>

九、HTTP 与 NET.TCP 通信效率的差别

 

参考资料:

http://www.cnblogs.com/artech/archive/2009/06/21/1507945.html

http://www.cnblogs.com/Gyoung/archive/2012/12/11/2812555.html

http://blogs.msdn.com/b/swiss_dpe_team/archive/2008/02/08/iis-7-support-for-non-http-protocols.aspx

http://blogs.msdn.com/b/vivekkum/archive/2009/05/07/http-error-404-3-not-found-when-browsing-wcf-application-after-reinstalling-iis.aspx

http://galratner.com/blogs/net/archive/2010/10/08/setting-up-a-nettcpbinding-enabled-wcf-service-in-iis-7.aspx

http://www.cnblogs.com/webabcd/archive/2010/08/02/1790175.html

http://www.codeproject.com/Articles/16765/WCF-Windows-Communication-Foundation-Example

http://www.codeproject.com/Tips/90804/Using-WCF-without-a-generated-proxy-by-using-Chann

http://blogs.msdn.com/b/vipulmodi/archive/2006/11/16/dynamic-programming-with-wcf.aspx

http://www.codeproject.com/Articles/89312/Windows-Communication-Foundation-QuickStart-Multip

WCF4.0安装 NET.TCP启用及常见问题的更多相关文章

  1. centos7编译安装LNMP(nginx-1.16.0,mysql8.0.16,php-7.3.6)常见问题报错及解决方法

    LNMP的安装与配置 nginx-1.16.0安装及配置: 第一步:前往官网下载nignx源码包 下载完毕后上传至服务器(先安装lrzsz) yum -y install lrzsz 安装完毕后执行: ...

  2. WCF学习之旅—WCF4.0中的简化配置功能(十五)

    六 WCF4.0中的简化配置功能 WCF4.0为了简化服务配置,提供了默认的终结点.绑定和服务行为.也就是说,在开发WCF服务程序的时候,即使我们不提供显示的 服务终结点,WCF框架也能为我们的服务提 ...

  3. MySQL 6.0安装图解

    MySQL 6.0安装图解 由于免费,MySQL数据库在项目中用的越来越广泛,而且它的安全性能也特别高,不亚于oracle这样的大型数据库软件.可以简单的说,在一些中小型的项目中,使用MySQL ,P ...

  4. CentOS7.0安装EMQ代理服务

    CentOS7.0安装EMQ代理服务 安装文件下载 官网 : https://www.emqx.io/cn/ 下载地址: https://www.emqx.io/cn/downloads 选择需要的版 ...

  5. 烂泥:zabbix3.0安装与配置

    本文由ilanniweb提供友情赞助,首发于烂泥行天下 想要获得更多的文章,可以关注我的微信ilanniweb 这个月又快过完了,最近也比较忙,没时间写文章,今天挤点时间把zabbix3.0安装与配置 ...

  6. CentOS 7.0安装配置Vsftp服务器

    一.配置防火墙,开启FTP服务器需要的端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop fi ...

  7. zabbix3.0安装部署文档

    zabbix v3.0安装部署 摘要: 本文的安装过程摘自http://www.ttlsa.com/以及http://b.lifec-inc.com ,和站长凉白开的<ZABBIX从入门到精通v ...

  8. inux环境PHP7.0安装

    inux环境PHP7.0安装   PHP7和HHVM比较PHP7的在真实场景的性能确实已经和HHVM相当, 在一些场景甚至超过了HHVM.HHVM的运维复杂, 是多线程模型, 这就代表着如果一个线程导 ...

  9. CentOS 7.0安装配置LAMP服务器(Apache+PHP+MariaDB)

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止fir ...

随机推荐

  1. 【bzoj 2716】[Violet 3]天使玩偶 (CDQ+树状数组)

    题目描述 Ayu 在七年前曾经收到过一个天使玩偶,当时她把它当作时间囊埋在了地下.而七年后 的今天,Ayu 却忘了她把天使玩偶埋在了哪里,所以她决定仅凭一点模糊的记忆来寻找它. 我们把 Ayu 生活的 ...

  2. 0基础浅谈反射型xss (1)

    0X1:在学习xss之前,先快速学习相关的HTML代码 1.  <input>标签 文本域用法: <input  type="text" /> Type的作 ...

  3. django入门-表单-part4

    尊重作者的劳动,转载请注明作者及原文地址 http://www.cnblogs.com/txwsqk/p/6514113.html 完全翻译自官方文档 https://docs.djangoproje ...

  4. [转] 打开 CMD 时自动执行命令

    [转] 打开 CMD 时自动执行命令 问题描述 在Windows中打开一个command-prompt时,我正在寻找一种方法来执行一些控制台命令,特别是设置一些命令别名. 例如,当打开command- ...

  5. 调用jdbc已经写成的方法----jdbc工具类抽取方式一

    package web09; /*获取连接和释放资源的方法 */ import java.sql.Connection; import java.sql.DriverManager; import j ...

  6. linux下线程的分离和结合属性

    在任何一个时间点上,线程是可结合的(joinable),或者是分离的(detached).一个可结合的线程能够被其他线程收回其资源和杀死:在被其他线程回收之前,它的存储器资源(如栈)是不释放的.相反, ...

  7. 【转载】MSDN-MDX#001 - 多维表达式 (MDX) 参考

    摘录于MSDN MDX 的一些重要概念 1. MDX 介绍 多维表达式 (MDX) 是用于在 Microsoft SQL Server Analysis Services (SSAS) 中处理和检索多 ...

  8. 1091 N-自守数 (15 分)

    // 建一个判断函数,接受两个整形的变量,再通过循环按位判断相等与否,主体函数中调用被调函数,建立一个判断变量.#include <iostream> using namespace st ...

  9. (Android+IOS)正在做一个新闻App,做的差不多了,听听大家的建议 (图)

    (Android+IOS)正在做一个新闻App,做的差不多了,听听大家的建议! 新闻采集器做好了,前端展示APP界面感觉还不是很好,还需要改进改进,希望发布(Android和IOS版本)前听听大家的建 ...

  10. Memcahe安装与配置

    1.先启动Memcahe服务 (1)通过Memcahe文件夹下的memcahe.exe程序启动 (2)将Memcahe加到Windows服务中去 为了方便使用,大多数情况下,是使用第二种方式,来启动M ...