2010-10-04 135 views
1

我正嘗試使用WCF創建自定義ASP.NET窗體身份驗證服務。我通過只包含一行JS的測試頁調用它(ScriptManager腳本除外)。問題是服務器返回響應代碼500並且響應正文爲空。我的斷點在服務方法和Global.asax中的Application_Error沒有被擊中。使用WCF自定義ASP.NET窗體身份驗證服務

Sys.Services.AuthenticationService.login('user', 'pass', false, null, null, null, null, null); 

可以看我的請求轉到服務器在瀏覽器工具有以下請求主體:

{"userName":"user","password":"pass","createPersistentCookie":false} 

在請求端其他的事情似乎也不錯。

下面是配置服務:

<system.serviceModel> 
    <behaviors> 
    <endpointBehaviors> 
     <behavior name="BtxAuthenticationEndpointBehavior"> 
     <webHttp/> 
     </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
    </serviceBehaviors> 
    </behaviors> 
    <services> 
    <service name="MyNamespace.BtxAuthenticationService"> 
     <endpoint contract="MyNamespace.IBtxAuthenticationService" binding="webHttpBinding" behaviorConfiguration="BtxAuthenticationEndpointBehavior"/> 
    </service> 
    </services> 
</system.serviceModel> 

和接口的聲明:

[ServiceContract] 
public interface IBtxAuthenticationService 
{ 
    [OperationContract] 
    [WebInvoke] 
    bool Login(string username, string password, bool createPersistentCookie); 

    [OperationContract] 
    [WebInvoke] 
    void Logout(); 
} 

實施:

public class BtxAuthenticationService : IBtxAuthenticationService 
{ 
    public bool Login(string username, string password, bool createPersistentCookie) 
    { 
     ... irrelevant because this is never hit 
    } 

    public void Logout() 
    { 
    } 
} 

有人能告訴我如何配置此或指向我一種調試方法。有關使用WCF服務實現自定義表單身份驗證的文章也會受到歡迎。我嘗試過使用各種其他設置進行試驗,其中包括我可以找到的所有異常細節設置,但無法取得任何進展(儘管我能夠做出一些迴歸並獲得不同的例外,例如缺少端點等)。

謝謝你的時間。

回答

1

不知道這是否有幫助。我從來沒有寫過這樣的服務,但是你的配置創建了WCF服務,而不是ASP.NET AJAX就緒,並且使用XML而不是JSON。嘗試使用此代替webHttp行爲:

<endpointBehaviors> 
    <behavior name="BtxAuthenticationEndpointBehavior"> 
    <enableWebScript /> 
    </behavior> 
</endpointBehaviors> 
+0

我已經試過這個。當我到達工作機器時,我會再試一次,但我相信enableWebScript負責提供在這種情況下不需要的JS代理。我可能在這方面是錯誤的,但即使這是問題,我應該能夠看到一些更多的描述性錯誤。 – Stilgar 2010-10-04 17:21:24

+0

是的,你是對的。 EnableWebScript允許將服務作爲對ScriptManager的引用並提供JS代理。但它也將消息格式切換爲JSON。您也可以通過設置請求和響應格式在WebInvoke屬性中執行此操作。也嘗試打開AspNetCompatibility級別。 – 2010-10-04 18:14:39

+0

我試圖通過webHttp元素設置格式(它有一個屬性),但這沒有幫助。 – Stilgar 2010-10-04 18:35:44