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 程序處理:
如果沒有上面的三個處理程序,則可以判定 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> ....... <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"/>
七、測試程序
新建一個默認的wcf service
配置如下:
<?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>
這個配置會有錯誤:
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>
八、完整源代碼:
接口源代碼:
GetData( boolValue = stringValue = { { boolValue = { { stringValue =
服務源代碼:
GetData( .Format( (composite == ArgumentNullException(+=
web.config 配置:
<?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>
九、HTTP 與 NET.TCP 通信效率的差別:
本文標題:WCF4.0安裝NET.TCP啟用及常見問題
本文路徑:http://m.2m8n56k.cn/article22/jjdcjc.html
成都網站建設公司_創新互聯,為您提供全網營銷推廣、關鍵詞優化、網站營銷、、虛擬主機、定制開發
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:[email protected]。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯