Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Following are the sample code from this post.
Firstly a method to encode the credentials:
private string EncodeBasicAuthenticationCredentials(string username, string password)
{
//first concatenate the user name and password, separated with :
string credentials = username + ":" + password;
//Http uses ascii character encoding, WP7 doesn’t include
// support for ascii encoding but it is easy enough to convert
// since the first 128 characters of unicode are equivalent to ascii.
// Any characters over 128 can’t be expressed in ascii so are replaced
// by ?
var asciiCredentials = (from c in credentials
select c <= 0x7f ? (byte)c : (byte)'?').ToArray();
//finally Base64 encode the result
return Convert.ToBase64String(asciiCredentials);
}
Now that we have a means of encoding our credentials we just need to add them to the headers of our WCF request. We can easily do this by wrapping the call in an OperationContextScope:
var credentials = EncodeBasicAuthenticationCredentials("username", "password");
using (OperationContextScope scope =
new OperationContextScope(service.InnerChannel))
{
HttpRequestMessageProperty request = new HttpRequestMessageProperty();
request.Headers[System.Net.HttpRequestHeader.Authorization] = "Basic " + credentials;
OperationContext.Current.OutgoingMessageProperties.Add(
HttpRequestMessageProperty.Name, request);
service.DoSomethingAsync();
}