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

6 months, 1 week ago.

  • Author
  • #107861

    Points: 0
    Rank: Member


    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); }
               { throw new ApplicationException("No network credentials"); }
               return request;

    Can something similar be done in PowerShell?



  • #107863

    Points: 642
    Helping Hand
    Rank: Major Contributor

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

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort