title: Getting Web Service to Authenticate using Network Credentials VB.Net
body: <p>the following VB.net code is working to authenticate to a web service - and it works great however i am having to use default network Credentials ( the logged in user the code runs under )</p>
  
  <p>I would like to pass network Creds to the web service and the following should work but does not. This is the working code using default credentials.</p>
  
  <pre><code>    Dim URL As String = "http://server/MBSDKService/MsgSDK.asmx?WSDL"
      Dim myService As New LANDeskMBDSK.MBSDK
      myService.Url = URL
      Dim CredCache As New System.Net.CredentialCache
      myService.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
  </code></pre>
  
  <p>This is what i want to work but does not...</p>
  
  <pre><code>    Dim URL As String = "http://server/MBSDKService/MsgSDK.asmx?WSDL"
      Dim myService As New LANDeskMBDSK.MBSDK
      myService.Url = URL
      Dim Cred As New System.Net.NetworkCredential("domain\user", "password")
      Dim CredCache As New System.Net.CredentialCache
      CredCache.Add(New Uri(myService.Url), "Basic", Cred)
      myService.Credentials = CredCache
  </code></pre>
  
  <p>Does anyone know what I am doing wrong?</p>
  
  <p>The rest of the code works perfectly so it is a case of what i have to add to the above to get it to work like the default credentials do.</p>
  
  <p>Thanks!</p>
  
  <p>Thanks to George this is the solution...</p>
  
  <pre><code>    Dim URL As String = "http://server/MBSDKService/MsgSDK.asmx?WSDL"
      Dim myService As New LANDeskMBDSK.MBSDK
      myService.Url = URL
      Dim Cred As New System.Net.NetworkCredential("user", "password")
      Dim CredCache As New System.Net.CredentialCache
      CredCache.Add(New Uri(myService.Url), "Basic", Cred)
      myService.Credentials = Cred
  </code></pre>