由於項目需要把WCF部署外網,在公司完成程式,測試沒有問題,wsDualHttpBinding 雙工通訊
用戶端配置:
<system.serviceModel> <bindings> <wsDualHttpBinding> <binding name="hhh_IBLLServiceContract" closeTimeout="00:01:00" openTimeout="00:51:00" receiveTimeout="00:50:00" sendTimeout="00:51:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true"> <readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> <reliableSession ordered="true" inactivityTimeout="00:50:00" /> <security mode="None"> <message clientCredentialType="Windows" negotiateServiceCredential="true" /> </security> </binding> </wsDualHttpBinding> </bindings> <client> <endpoint address="http://192.168.9.29:8081/Service1.svc" binding="wsDualHttpBinding" bindingConfiguration="hhh_IBLLServiceContract" contract="IBLLServiceContract" name="hhh_IBLLServiceContract"> </endpoint> </client> </system.serviceModel>
伺服器端配置:
<system.serviceModel> <bindings> <wsDualHttpBinding> <binding name="hhh" messageEncoding="Mtom"> <security mode="None"/> </binding> </wsDualHttpBinding> </bindings> <services> <service behaviorConfiguration="serviceBehavior" name="RNOP.WCF.Service.BLLService"> <endpoint address="Service1.svc" binding="wsDualHttpBinding" bindingName="hhh" bindingConfiguration="hhh" contract="RNOP.WCF.ServiceInterface.IBLLServiceInterface" > </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" > </endpoint> <host> <baseAddresses> <add baseAddress="http://192.168.9.180:8081/" /> </baseAddresses> </host> </service> </services> <behaviors> <serviceBehaviors > <behavior name="serviceBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="False" /> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
內網測試沒有問題,部署到外網,就報逾時異常operation may have been a portion of a longer timeout
檢查伺服器和用戶端防火牆是否關閉,防火牆都關閉,依然串連失敗;
檢查連接埠是否被佔用,更換連接埠,錯誤依然;
探索服務的網頁上中繼資料地址使用的是電腦名稱,而電腦名稱在外網是無法訪問,於是搜尋,在網上發現一篇文章:http://www.cnblogs.com/lensso/archive/2011/08/01/2124095.html
遠程用戶端由於中繼資料地址主機名稱為伺服器電腦名稱而無法解析WCF服務中繼資料的解決辦法
安裝文章方法解決的了中繼資料的位址解析問題。
但是用戶端依然無法串連服務端,再次
http://www.cnblogs.com/bryant/archive/2011/09/22/2185621.html
http://social.msdn.microsoft.com/Forums/en-US/wcfzhchs/thread/0d663107-b47e-464b-82dc-6f191c484870
所以在外網的情況下,程式能正常的工作必須確保:1.用戶端沒安裝IIS6以下的版本,即80連接埠要被空出來;2是在違反1的條件下,80連接埠被佔用,讓你的clientBaseAddress能被伺服器所識別。
於是設定地址,用戶端正常串連上服務端,問題解決。