As you know, on .NET CF 3.5 you can use WCF only as a standard web service along the SOAP path. Therefore, you cannot use any WCF security resources.
I figured out how to use Basic Http Authentication , setting up the client and server sides, and I can explain this as follows:
Client side
Client-side (on your device with .Net CF 3.5) is easy. Just provide your credentials by setting up your clientServiceProxy using:
var service = new YourServiceNamespace.YourService(); service.Credentials = new NetworkCredential("login", "12345"); service.PreAuthenticate = true;
This will force your client to process the "WWW-Authenticate" header from the server response and automatically pass your credentials through the "Authorization: basic" response header.
Server side
In the WCF configuration on your web.config, you should configure security only for transport and use HTTPS (this is enough to protect your message from sniffers).
<basicHttpBinding> <binding> <security mode="Transport"> <transport clientCredentialType="None" /> </security> </binding> </basicHttpBinding>
Now, since WCF does not have native support for Basic Http Authentication, we must use a custom HTTP module to handle it.
public class BasicHttpAuthentication : IHttpModule { public delegate bool AuthenticateDelegate( string username, string password ); public static AuthenticateDelegate AuthenticateMethod; public void Dispose() { } public void Init( HttpApplication application ) { application.AuthenticateRequest += this.OnAuthenticateRequest; application.EndRequest += this.OnEndRequest; } private void DenyAccess( HttpApplication app ) { app.Response.StatusCode = 401; app.Response.StatusDescription = "Access Denied";
To enable the HTTP module, add the following to the web.config file in the system.webServer section:
<system.webServer> <modules> <add name="BasicHttpAuthentication" type="BasicHttpAuthentication, YourAssemblyName"/> </modules>
Now you need to tell the module the function that will be used to verify the credentials from the client. You can see that there is a static delegate inside the module called "AuthenticateMethod", so you can report your Application_Start function to your global.asax:
BasicHttpAuthentication.AuthenticateMethod = ( username, password ) => username == "login" && password == "12345";