WebService authentication issue

Welcome Forums General PowerShell Q&A WebService authentication issue

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
3 months, 1 week ago.

  • Author
    Posts
  • #107861

    Participant
    Points: 0
    Rank: Member


    Hi

    I have been having issues connecting to an internal webservice – 401 Unauthorized.  I get this connecting from PowerShell and from a Project created using Visual Studio.

    For some reason it looks like basic authentication is not being used so adding the following in the Visual Studio Project (Reference.cs created from wsdl file) works:

    public partial class testServiceNoKeepAlive : testService
       {
           protected override System.Net.WebRequest GetWebRequest(Uri uri)
           {
               System.Net.HttpWebRequest request;
               request = (System.Net.HttpWebRequest)base.GetWebRequest(uri);
               request.KeepAlive = false;
    
               System.Net.NetworkCredential networkCredentials = Credentials.GetCredential(uri, "Basic");
    
               if (networkCredentials != null)
    
               { byte[] credentialBuffer = new UTF8Encoding().GetBytes(networkCredentials.UserName + ":" + networkCredentials.Password); request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(credentialBuffer); }
    
               else
    
               { throw new ApplicationException("No network credentials"); }
    
               return request;
           }
    
       }
    

    Can something similar be done in PowerShell?

    Thanks

    Paul

  • #107863

    Participant
    Points: 134
    Helping Hand
    Rank: Participant

The topic ‘WebService authentication issue’ is closed to new replies.