# WebService authentication issue

**URL:** <https://forums.powershell.org/t/webservice-authentication-issue/11099>\
**Category:** PowerShell Help\
**Created:** [August 8, 2018, 6:21am UTC](https://forums.powershell.org/t/webservice-authentication-issue/11099 "2018-08-08T06:21:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulfallows1980](https://avatars.discourse-cdn.com/v4/letter/p/839c29/32.png) [@paulfallows1980](https://forums.powershell.org/u/paulfallows1980)\
**Post date:** [August 8, 2018, 6:21am UTC](https://forums.powershell.org/t/webservice-authentication-issue/11099/1 "2018-08-08T06:21:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [August 8, 2018, 6:28am UTC](https://forums.powershell.org/t/webservice-authentication-issue/11099/2 "2018-08-08T06:28:32Z")

</div>

Does the tip from [jrv](https://social.technet.microsoft.com/profile/jrv/?ws=usercard-mini) not help?  
[https://social.technet.microsoft.com/Forums/en-US/887fe68c-302a-474a-86b1-211e26349dbb/webservice-authentication-issue?forum=winserverpowershell#7a29fdbc-65c0-4e98-98b0-deec23ce40cf](https://social.technet.microsoft.com/Forums/en-US/887fe68c-302a-474a-86b1-211e26349dbb/webservice-authentication-issue?forum=winserverpowershell#7a29fdbc-65c0-4e98-98b0-deec23ce40cf)

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:34pm UTC](https://forums.powershell.org/t/webservice-authentication-issue/11099/3 "2024-05-16T20:34:49Z")

</div>


