當我嘗試從.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