title: how to pass basic authentication in webservice?
body: <p>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</p>
  
  <pre><code>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();
  </code></pre>
  
  <p>But through this way I am not able to call the webmethod. Is there any way to achieve the same.</p>
  
  <p>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="</p>
  
  <pre><code> ICredentials creds;
   creds = new
   NetworkCredential("username", "password", "domain");
   proxy.Credentials = creds;
   string str=proxy.helloworld();
  </code></pre>
  
  <p>please let me know if there is any way to achieve this..any help is appreciated.</p>
  
  <p>thanks </p>