Blog de Francisco Velázquez

otro blog personal

Posts Tagged ‘SOAP

Consumir un WebService con autenticación básica desde .NET

leave a comment »

El título describe bastante bien lo que vamos a solucionar en este post.

public class SecureWebService : ThirdPartyWebService
{
    protected override WebRequest GetWebRequest(Uri uri)
    {
        HttpWebRequest webRequest = (HttpWebRequest)base.GetWebRequest(uri);
        NetworkCredential credentials = Credentials as NetworkCredential;
        if (credentials != null)
        {
            string authInfo =
            ((credentials.Domain != null) && (credentials.Domain.Length > 0) ?
            credentials.Domain + @"\" : string.Empty) +
            credentials.UserName + ":" + credentials.Password;
            authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
            webRequest.Headers["Authorization"] = "Basic " + authInfo;
        }
        return webRequest;
    }
}

via.

Advertisements

Written by fravelgue

October 5, 2010 at 12:38 pm

Posted in .net

Tagged with , , ,

POST multipart message MIME

leave a comment »

Written by fravelgue

March 2, 2009 at 10:29 am

Posted in development

Tagged with , , , , ,