2010-10-04 137 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