您好,登錄后才能下訂單哦!
WCF4.0安裝及NET.TCP啟用
WCF 4.0 一般默認(rèn)安裝.net Framework 4.0的時(shí)候已經(jīng)安裝。
但如果先裝.net framework 4.0,后裝IIS,就會出現(xiàn)問題。需要重新注冊WCF4.0。
WCF4.0 已經(jīng)是.net 4.0的一個(gè)內(nèi)部組件,不需要.net3.5 那樣麻煩先裝windows組件。
一、確認(rèn)是否安裝WCF4.0:
如下圖,查看*.svc 后綴的文件是否被svc-Integrated-4.0 或 svc-ISAPI-4.0_64/32bit 程序處理:
如果沒有上面的三個(gè)處理程序,則可以判定 wcf 4.0 沒有安裝。
二、安裝WCF 4.0
找到對應(yīng)的.net framework 目錄,運(yùn)行命令:
"%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,可以不用管這個(gè) –enable,可以手動去設(shè)置那個(gè)pool的.net 版本是4.0.
三、啟動服務(wù):NetTCP Listener Adapter 和 Net TCp Port Sharing Service:
四、為IIS站點(diǎn)配置NETTCP協(xié)議支持:
1)綁定808:*端口:
2)啟用net.tcp協(xié)議:
如果不配置會出現(xiàn)下面錯(cuò)誤:
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同時(shí)存在,有可能程序會找錯(cuò)對應(yīng)的處理程序。
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個(gè)操作:
1) 安裝WAS
2) 確定WCF是否啟用Non-Http支持
六、其他可能的錯(cuò)誤:
1) IIS站點(diǎn)多主機(jī)頭綁定的錯(cuò)誤:
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> 里面允許多主機(jī)頭綁定:
</system.serviceModel> ....... <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel>
2) 為什么測試界面的協(xié)議不一樣
svcutil.exe http://localhost/WcfServiceOfMyTest/Service1.svc?wsdl
與
svcutil.exe ://dst52382.cn1.global.ctrip.com/WcfServiceOfMyTest/Service1.svc/mex
區(qū)別在協(xié)議 http 和 net.tcp 的是否啟用,配置在這里會影響:
<serviceMetadata httpGetEnabled="false"/>
七、測試程序
新建一個(gè)默認(rèn)的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"> <!--這個(gè)服務(wù)名字不是隨便取得,要跟你的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>
這個(gè)配置會有錯(cuò)誤:
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.
對應(yīng)的中文描述:
未找到 URI“net.tcp://gyoung/Service1.svc/mex”的兼容 TransportManager。這可能是因?yàn)槭褂昧酥赶蛱摂M應(yīng)用程序外部的絕對地址,或終結(jié)點(diǎn)的綁定設(shè)置與其他服務(wù)或終結(jié)點(diǎn)所設(shè)置的綁定設(shè)置不匹配。 請注意,同一協(xié)議的所有綁定在同一應(yīng)用程序中應(yīng)具有相同的設(shè)置。
這個(gè)錯(cuò)誤的重點(diǎn)在后半句話,endpoint的binding配置需要一致,這里2個(gè)endpoint,一個(gè)是服務(wù)終結(jié)點(diǎn),它的 maxConnections="100" 不是默認(rèn)值10,另外一個(gè)是元數(shù)據(jù)終結(jié)點(diǎn),這里的max connection默認(rèn)是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>
八、完整源代碼:
接口源代碼:
GetData( boolValue = stringValue = { { boolValue = { { stringValue =
服務(wù)源代碼:
GetData( .Format( (composite == ArgumentNullException(+=
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 通信效率的差別:
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。