当我尝试从.NET调用[Java] Web服务时,出现安全凭证问题。调用需要凭证的Web服务:错误:需要安全令牌
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.
它是否提取了我试图通过的凭据?此时,我只想与Web服务进行联系并获得访问权限。在我的示例中,ServiceReference1是生成的Web代理类。
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
我的App.Config设置应该是什么?
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
您应该能够作为一个属性添加凭据到myIndividualProfileSoapClient对象 – mikey
该对象是否具有ClientCrdedentials属性,它的类型是System.ServiceModel.Description.ClientCredentials的。它有一个无参数的构造函数,但该对象的用户名和密码属性是只读的。我如何创建这个对象? – ChadD