I have a webservice which has a method to return a value.Here my requirement is , I want to pass the authentication value in header for each and every web request i used the below given code for doing the same
req = WebRequest.Create(http://localhost/test/test.asmx); string _auth = string.Format("{0}:{1}", "username", "password"); string _enc = Convert.ToBase64String(Encoding.ASCII.GetBytes(_auth)); string _cred = string.Format("{0} {1}", "Basic", _enc); req.Headers[HttpRequestHeader.Authorization] = _cred; WebResponse response = (WebResponse)req.GetResponse(); But through this way I am not able to call the webmethod. Is there any way to achieve the same.
Also I tried to sending the authentication values with the help of ICredentials with the following given code , but i need the header values like "Authorization: Basic YWRtaW46YWRtaW4="
ICredentials creds; creds = new NetworkCredential("username", "password", "domain"); proxy.Credentials = creds; string str=proxy.helloworld(); please let me know if there is any way to achieve this..any help is appreciated.
thanks