Tôi đang cố gắng sử dụng dịch vụ web của bên thứ ba được bảo mật với người dùng/thẻ. Tôi tin rằng tôi đã thực hiện những gì cần thiết để xác thực và đặt người dùng và vượt qua, nhưng có vẻ như không bao gồm họ trong tiêu đề http hoặc ...WCF - BasicHttpBinding, Không có tên người dùng và/hoặc mật khẩu có sẵn, tên: null, mật khẩu: null
Khi cố gắng gọi;
nameList.AddRange(service.getBlobNameByIdAndSectionId(section, id))
Tôi gặp lỗi này;
No user name and/or password is available, name: null, password: null
Toàn mã:
Private Function GetVendorService() As Services.ServiceClient
Dim binding As New BasicHttpBinding(BasicHttpSecurityMode.Transport)
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic
Dim ea As New EndpointAddress(GetVendorServiceURL())
Dim service As New Services.ServiceClient(binding, ea)
service.ClientCredentials.UserName.UserName = "user"
service.ClientCredentials.UserName.Password = "password"
Return service
End Function
Public Function GetVendorServiceURL() As String
Select Case Informix.HostType
Case HostServerType.Stage
Return "https://url-s.net:8443/cxf/Service/v1/ws"
Case HostServerType.Dev
Return "https://url-d.net:8443/cxf/Service/v1/ws"
Case Else 'Live
Return "https://url.net:8443/cxf/Service/v1/ws"
End Select
End Function
Private Function GetPdfListById(ByVal Id As Integer, ByVal Section As SectionId) As List(Of Services.blobName)
Dim service As Services.ServiceClient = GetVendorService()
Dim nameList As New List(Of Services.blobName)
service.Open()
nameList.AddRange(service.getBlobNameByIdAndSectionId(section, id))
service.Close()
Return nameList
End Function
app.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ServiceSoapBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://url.net:8443/cxf/Service/v1/ws"
binding="basicHttpBinding" bindingConfiguration="ServiceSoapBinding"
contract="Services.Service"
name="ServiceSoapPort" />
</client>
Vâng, để loại bỏ một số nhầm lẫn tiềm ẩn, định nghĩa liên kết thứ hai của bạn ('ServiceSoapBinding1') hiện không được tham chiếu (trong mã bạn đã hiển thị), vì vậy sẽ bị bỏ qua và bạn có thể xóa nó một cách an toàn. – paul
Cảm ơn, đã bỏ lỡ khi đăng bài. Đã xóa nó khỏi ví dụ. – Tomcat
Câu hỏi ngu ngốc, nhưng bạn có tài liệu nào về cách thực hiện việc này không? Bên thứ ba nói gì? –