協定需要會話,但是綁定“BasicHttpBinding”不支援它或者因配置不正確而無法支援它

來源:互聯網
上載者:User

對於無.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了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.