對於無.SVC檔案的配置只需要指定以.svc結尾的相對位址和服務實現的完整名稱即可。可問題恰恰出在這裡,之前需要在<system.serviceModel>
複製代碼 代碼如下:<services>
<host>
<baseAddresses>
<add baseAddress="http://localhost:10045/TestService/TestService" />
<add baseAddress="net.tcp://localhost:10046/TestService/TestService" />
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="WsHttpSession" contract="xxx.xxx.IConnectService" />
</services>
這種配置方式對於特定的協議明確的指定了終結點的binding,但是用無.svc配置方式的終結點是由AppFabric產生的不需要在設定檔中配置,對於綁定只提供了基於介面配置的方式並且沒有明確指定綁定的具體類型。像如上這個問題就是因為開發的WCF需要會話,而基於HTTP協議的預設綁定BasicHttpBinding不支援會話所致,那麼如何解決這個問題,只需要修改http協議的預設綁定即可。
解決方案:
在web.config設定檔中找到<system.serviceModel>段。
在<system.serviceModel></system.serviceModel>之間加上 複製代碼 代碼如下:<protocolMapping>
<add scheme="http" binding="wsHttpBinding" bindingConfiguration="WsHttpSession"/>
</protocolMapping>
協議映射配置,這樣伺服器在接收到http協議的請求時 會按照所設定的binding進行處理而不再是預設binding了。