我的方法是通过message header 发送username 和password
服务器端:
var current = WebOperationContext.Current;
var userName = current.IncomingRequest.Headers["USERNAME"];
var password = current.IncomingRequest.Headers["PASSWORD"];
if (Membership.ValidateUser(userName, password))
{
throw new WebFaultException<string>("Access denied, unknown user name or password.", HttpStatusCode.Unauthorized);
}
客户端:
WebClient webClient = new WebClient();
webClient.Headers.Add("USERNAME", userName);
webClient.Headers.Add("PASSWORD", password);