title: Calling a web service that requires credentials: Error: A security token is required
body: <p>When I try to call a [Java] web service from .NET, I am getting what appears to be a security credentials issue. </p>
  
  <pre><code>CWWSS5509E: A security token whose type is [http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken] is required.
  </code></pre>
  
  <p>Is it even picking up the credentials that I am trying to pass? At this point, I just want to make contact with the web service and get access. In my example, ServiceReference1 is a generated Web proxy class.</p>
  
  <pre><code>Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  
      Dim myLocateProfileBySourceSystemId As New ServiceReference1.locateProfileBySourceSystemId
  
      Dim myLocateProfileBySourceSystemIdRequestType As New ServiceReference1.LocateProfileBySourceSystemIdRequestType
  
      myLocateProfileBySourceSystemIdRequestType.includeEmailAddress = True
  
      myLocateProfileBySourceSystemId.locateProfileBySourceSystemId1 = myLocateProfileBySourceSystemIdRequestType
  
      System.Net.ServicePointManager.ServerCertificateValidationCallback = New System.Net.Security.RemoteCertificateValidationCallback(AddressOf ValidateRemoteCertificate)
  
      Dim myNetworkCredential As New System.Net.NetworkCredential
      myNetworkCredential.UserName = "MyUsernameGoesHere"
      myNetworkCredential.Password = "MyPasswordGoesHere"
  
      Dim myWebProxy As New WebProxy()
      myWebProxy.Credentials = myNetworkCredential
      WebRequest.DefaultWebProxy.Credentials = myNetworkCredential
  
      Dim myIndividualProfileSoapClient As New ServiceReference1.IndividualProfileSoapClient
      Dim myLocateProfileBySourceSystemIdResponse As ServiceReference1.locateProfileBySourceSystemIdResponse = myIndividualProfileSoapClient.locateProfileBySourceSystemId(myLocateProfileBySourceSystemId)
  
  End Sub
  
  Private Shared Function ValidateRemoteCertificate(ByVal sender As Object,
                                                ByVal certificate As X509Certificate,
                                                ByVal chain As X509Chain,
                                                ByVal policyErrors As SslPolicyErrors) As Boolean    
       ' allow any old dodgy certificate...
       Return True
  
  End Function
  </code></pre>
  
  <p>What should my App.Config settings be?</p>
  
  <pre><code>            &lt;security mode="Transport"&gt;
                  &lt;transport clientCredentialType="None" proxyCredentialType="None"
                      realm="" /&gt;
                  &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt;
              &lt;/security&gt;
  </code></pre>