views:

42

answers:

1

I am trying to create a custom ASP.NET Forms Authentication Service using WCF. I am calling it via a test page that contains only a single line of JS (except for the ScriptManager scripts). The problem is that the server returns response code 500 and the response body is empty. My breakpoints in the service method and in the Application_Error in Global.asax are not being hit.

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

I can see the request go to the server in the browser tools with the following request body:

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

Other things on the request side also seem fine.

Here is the configuration service:

<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>

And the declaration of the interface:

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

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

The implementation:

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

    public void Logout()
    {
    }
}

Can someone tell me how to configure this or point me to a way to debug it. An article about implementing custom Forms Authentication with a WCF service will be welcome too. I've tried experimenting with various other settings including all the exception details settings I could find but could not make any progress (though I was able to make some regress and get different exceptions like missing endpoints and so on).

Thank you for your time.

+1  A: 

Not sure if this helps. I have never written such service but your configuration creates WCF service wich is not ASP.NET AJAX ready and works with XML instead of JSON. Try to use this instead of webHttp behavior:

<endpointBehaviors> 
  <behavior name="BtxAuthenticationEndpointBehavior"> 
    <enableWebScript /> 
  </behavior> 
</endpointBehaviors>  
Ladislav Mrnka
I already tried this. I will try it again tomorrow when I get to my work machine but I believe that enableWebScript is responsible for providing the JS proxy which is not needed in this case. I may be wrong on this but even if this is the problem I should be able to see some more descriptive errors.
Stilgar
Yes you are right. EnableWebScript allows adding service as reference to ScriptManager and provides JS proxy. But it also switches message format to JSON. You can also do that in WebInvoke attribute by setting Request and Response formats. Also try to turn on AspNetCompatibility level.
Ladislav Mrnka
I tried setting the format via the webHttp element (it has an attribute for that) but this did not help.
Stilgar
You can try to turn on WCF tracing and check internal WCF error: http://msdn.microsoft.com/en-us/library/ms733025.aspx
Ladislav Mrnka
You were right. Adding ONLY enableWebScript fixed the problem. I had tried multiple times adding webHttp and enableWebScript and it does not work. I should stop trying to guess what WCF configuration options do and go read something about it. I was convinced I tried only enableWebScript but I tried it again just to make sure and it worked. Thank you very much.
Stilgar