WCF4.0安装NET.TCP启用及常见问题

WCF4.0安装及NET.TCP启用

创新互联建站专业为企业提供巴彦淖尔网站建设、巴彦淖尔做网站、巴彦淖尔网站设计、巴彦淖尔网站制作等企业网站建设、网页设计与制作、巴彦淖尔企业网站模板建站服务,10年巴彦淖尔做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

 

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 程序处理:

 WCF4.0安装 NET.TCP启用及常见问题

 如果没有上面的三个处理程序,则可以判定 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:

 

 WCF4.0安装 NET.TCP启用及常见问题

 

 

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

 

 

1)绑定808:*端口:

 WCF4.0安装 NET.TCP启用及常见问题

 

 

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].

 

WCF4.0安装 NET.TCP启用及常见问题

 

五、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

WCF4.0安装 NET.TCP启用及常见问题

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

WCF4.0安装 NET.TCP启用及常见问题

 

 

 六、其他可能的错误:

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>
.......
<serviceHostingEnvironmentmultipleSiteBindingsEnabled="true" />
</system.serviceModel>

 

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

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

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

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

 <serviceMetadatahttpGetEnabled="false"/>

 

WCF4.0安装 NET.TCP启用及常见问题

 

 

七、测试程序

新建一个默认的wcf service

配置如下:

 

WCF4.0安装 NET.TCP启用及常见问题

<?xml version="1.0"?><configuration>

  <system.web>
    <compilationdebug="true" targetFramework="4.0" />
  </system.web>
    <system.serviceModel>
      <protocolMapping>
        <addscheme="tcp" binding="netTcpBinding"/>
      </protocolMapping>
      <bindings>
        <netTcpBinding>
          <bindingname="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">

            <readerQuotasmaxDepth="2147483647"
                                      maxStringContentLength="2147483647"
                                      maxArrayLength="2147483647"
                                      maxBytesPerRead="2147483647"
                                      maxNameTableCharCount="2147483647" />
            <reliableSessionordered="true"  inactivityTimeout="00:01:00" enabled="false" />
            <securitymode="None">
              <transportclientCredentialType="Windows" protectionLevel="EncryptAndSign"  />
              <messageclientCredentialType="Windows"  />
            </security>
          </binding>
        </netTcpBinding>
      </bindings>
      <services>

        <servicebehaviorConfiguration="MyBehavior" name="WcfServiceOfMyTest.Service_Test_NetTcp"> <!--这个服务名字不是随便取得,要跟你的class文件里的类的名字一致!-->
          <endpointaddress="" binding="netTcpBinding" contract="WcfServiceOfMyTest.IJustAnInterface" bindingConfiguration="netTcpBindConfig"></endpoint>
          <endpointaddress="mex" binding="mexTcpBinding" contract="IMetadataExchange" ></endpoint>
        </service>

      </services>
      <behaviors>
        <serviceBehaviors>
          <behaviorname="MyBehavior" >
            <serviceMetadatahttpGetEnabled="false"/>
            <serviceDebugincludeExceptionDetailInFaults="true" />
            <dataContractSerializermaxItemsInObjectGraph="6553600"/>
          </behavior>
        </serviceBehaviors>
      </behaviors>
      <serviceHostingEnvironmentmultipleSiteBindingsEnabled="true" />
    </system.serviceModel>

  <system.webServer>
    <modulesrunAllManagedModulesForAllRequests="true"/>
  </system.webServer></configuration>

WCF4.0安装 NET.TCP启用及常见问题

这个配置会有错误:

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类型不一致。将他们改为一致。如下:
 <servicebehaviorConfiguration="MyBehavior" name="WcfServiceOfMyTest.Service_Test_NetTcp">
      <endpointaddress="" binding="netTcpBinding" contract="WcfServiceOfMyTest.IJustAnInterface" bindingConfiguration="netTcpBindConfig"></endpoint>
      <endpointaddress="mex" binding="netTcpBinding" contract="IMetadataExchange"  bindingConfiguration="netTcpBindConfig" ></endpoint>
 </service>

 

八、完整源代码:

接口源代码:

WCF4.0安装 NET.TCP启用及常见问题

  GetData(  boolValue =  stringValue =   {  { boolValue =  {  { stringValue =

WCF4.0安装 NET.TCP启用及常见问题

 

服务源代码:

WCF4.0安装 NET.TCP启用及常见问题

       GetData( .Format( (composite ==   ArgumentNullException(+=

WCF4.0安装 NET.TCP启用及常见问题

 

web.config 配置:

WCF4.0安装 NET.TCP启用及常见问题

<?xml version="1.0"?><configuration>

  <system.web>
    <compilationdebug="true" targetFramework="4.0" />
  </system.web>
    <system.serviceModel>
      <protocolMapping>
        <addscheme="tcp" binding="netTcpBinding"/>
      </protocolMapping>
      <bindings>
        <netTcpBinding>
          <bindingname="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">

            <readerQuotasmaxDepth="2147483647"
                                      maxStringContentLength="2147483647"
                                      maxArrayLength="2147483647"
                                      maxBytesPerRead="2147483647"
                                      maxNameTableCharCount="2147483647" />
            <reliableSessionordered="true"  inactivityTimeout="00:01:00" enabled="false" />
            <securitymode="None">
              <transportclientCredentialType="Windows" protectionLevel="EncryptAndSign"  />
              <messageclientCredentialType="Windows"  />
            </security>
          </binding>
        </netTcpBinding>
      </bindings>
      <services>

        <servicebehaviorConfiguration="MyBehavior" name="WcfServiceOfMyTest.Service_Test_NetTcp">
          <endpointaddress="" binding="netTcpBinding" contract="WcfServiceOfMyTest.IJustAnInterface" bindingConfiguration="netTcpBindConfig"></endpoint>
          <endpointaddress="mex" binding="netTcpBinding" contract="IMetadataExchange"  bindingConfiguration="netTcpBindConfig" ></endpoint>
        </service>

      </services>
      <behaviors>
        <serviceBehaviors>
          <behaviorname="MyBehavior" >
            <serviceMetadatahttpGetEnabled="false"/>
            <serviceDebugincludeExceptionDetailInFaults="true" />
            <dataContractSerializermaxItemsInObjectGraph="6553600"/>
          </behavior>
        </serviceBehaviors>
      </behaviors>
      <serviceHostingEnvironmentmultipleSiteBindingsEnabled="true" />
    </system.serviceModel>

  <system.webServer>
    <modulesrunAllManagedModulesForAllRequests="true"/>
  </system.webServer></configuration>

WCF4.0安装 NET.TCP启用及常见问题

 

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

 

WCF4.0安装 NET.TCP启用及常见问题

 

本文标题:WCF4.0安装NET.TCP启用及常见问题
本文路径:https://www.cdcxhl.com/article22/jjdcjc.html

成都网站建设公司_创新互联,为您提供全网营销推广关键词优化网站营销虚拟主机定制开发

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

h5响应式网站建设