TIPS-設定WCF使用Windows認證(補遺)

上次介紹過如何設定WCF使用Windows認證,今天處理一個WCF部署時,如法泡製卻一直撞壁... 呼叫MyDataService.svc時始終彈出:

Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.

比對與上回的WCF設定差異主要在於用的是basicHttpBinding,而不是上回說的webHttpBinding,所以我依經驗將web.config修改如下,但看來行不通。

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpEndpointBinding">
        <security mode="TransportCredentialOnly">
          <transport clientCredentialType="Windows" />
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyDataServiceBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service
        behaviorConfiguration="MyDataServiceBehavior" 
        name="MyDataService">
        <endpoint address="" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpEndpointBinding"
        name="BasicHttpEndpoint" contract="IMyDataService">
        </endpoint>              
        <endpoint address="mex" binding="mexHttpBinding" 
        contract="IMetadataExchange"/>
    </service>
  </services>
</system.serviceModel>

摸索加Google一陣子,找到一篇文章,提到mexHttpBinding預設會使用匿名存取,應該是導致前述問題的元凶,解決之道是比照basicHttpBinding也設成Windows驗證。

我評估部署的環境不需提供開發者WCF的Metadata,直接將<endpoint address="mex" ... />切除(其實是想偷懶),錯誤立刻消失,問題排除。

歡迎推文分享:
Published 14 July 2009 06:29 PM 由 Jeffrey
Filed under: ,
Views: 6,356



意見

沒有意見

你的看法呢?

(必要的) 
(必要的) 
(選擇性的)
(必要的) 
(提醒: 因快取機制,您的留言幾分鐘後才會顯示在網站,請耐心稍候)

5 + 3 =

搜尋

Go

<July 2009>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
 
RSS
創用 CC 授權條款
【廣告】
twMVC

Tags 分類檢視
關於作者

一個醉心技術又酷愛分享的Coding魔人,十年的IT職場生涯,寫過系統、管過專案, 也帶過團隊,最後還是無怨無悔地選擇了技術鑽研這條路,近年來則以做一個"有為的中年人"自許。

文章典藏
其他功能

這個部落格


Syndication