TIPS-設定WCF使用Windows認證

原本測試OK的WCF,在取消IIS匿名存取,改用整合式驗證後出現以下錯誤訊息:

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

爬了一下文,大致的心得是要在web.config改變安全設定。原本的設定是VS2008建立AJAX enabled WCF時自動產生的:

<system.serviceModel>
    <behaviors>
        <endpointBehaviors>
            <behavior name="WebApiAspNetAjaxBehavior">
                <enableWebScript/>
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <services>
        <service name="WebApi">
            <endpoint address="" behaviorConfiguration="WebApiAspNetAjaxBehavior" 
             binding="webHttpBinding" contract="WebApi"/>
        </service>
    </services>
</system.serviceModel>

要修改為:

<system.serviceModel>
    <behaviors>
        <endpointBehaviors>
            <behavior name="WebApiAspNetAjaxBehavior">
                <enableWebScript/>
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <services>
        <service name="WebApi">
            <endpoint address="" behaviorConfiguration="WebApiAspNetAjaxBehavior" 
              binding="webHttpBinding" contract="WebApi"
              bindingConfiguration="NTLMBinding"
              />
        </service>
    </services>
<bindings>
  <webHttpBinding>
    <binding name="NTLMBinding">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows"/>
      </security>
    </binding>
  </webHttpBinding>
</bindings>
</system.serviceModel>

醬就可以柳~~~ (羞昂風)

歡迎推文分享:
Published 20 June 2009 03:23 AM 由 Jeffrey
Filed under:


意見

# Alfred said on 22 June, 2009 01:08 AM

哈哈,看到羞昂我忍不住大笑

在上班耶,嗯湯啊嗯湯~

# chunwaitam said on 22 March, 2010 02:43 AM

我也是用這個方法...

但每當我的js file 呼叫wcf裏的方法時

它每次也會有兩個http request

第一個的回傳是HTTP/1.1 401 Unauthorized

而第二個的回傳是正常

請問大哥有遇到這問題嗎?

如有,請問你知道怎樣解決嗎

# Jeffrey said on 22 March, 2010 04:49 PM

to chunwaitam, 第一次IIS傳回401告知Browser需要驗證,第二次Browser送出夾帶身份驗證的Request,這算是正常的HTTP互動過程。

# chunwaitam said on 23 March, 2010 03:24 AM

o...thanks jeffrey

其實browse每1.5秒就要呼叫wcf...

請問有沒有方法在第一次呼叫時就把身份驗證夾在request裏?

因為network team 投訴我的application 佔用了很多bandwidth...

你的看法呢?

(必要的) 
(必要的) 
(選擇性的)
(必要的) 

請輸入以上的數字:

搜尋

Go

<June 2009>
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
 
RSS
【工商服務】

Tags 分類檢視
關於作者

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

文章典藏
其他功能

這個部落格


BlogLook Score and Rank

Syndication