gpt4 book ai didi

vb.net - WCF - BasicHttpBinding,没有可用的用户名和/或密码,名称 : null, 密码:空

转载 作者:行者123 更新时间:2023-12-04 11:54:21 25 4
gpt4 key购买 nike

我正在尝试使用受用户/通行证保护的第三方 Web 服务。我相信我已经完成了验证和设置用户并通过所需的工作,但似乎没有将它们包含在 http header 或其他内容中...

尝试调用时;

nameList.AddRange(service.getBlobNameByIdAndSectionId(section, id))

我收到这个错误;
No user name and/or password is available, name: null, password: null

完整代码:
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

应用程序配置文件
<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>

最佳答案

经过很多问题,我发现由于某种原因,授权 header 没有被发送到服务。为了包含它,我必须为调用该服务执行以下操作。我仍然困惑的是为什么这是一个问题。我认为 BasicHttpBinding 应该默认在 header 中包含凭据?任何人对为什么这对我来说是一个问题的任何见解都将不胜感激。一个很好的答案可能仍然会得到+50。

Private Function GetPdfListById(ByVal Id As Integer, ByVal Section As SectionId) As List(Of VendorGuideService.vogBlobName)
Using service As Service.ServiceClient = GetVendorService()
Dim nameList As New List(Of Service.blobName)
Using scope As ServiceModel.OperationContextScope = New ServiceModel.OperationContextScope(service.InnerChannel)
Dim request As New ServiceModel.Channels.HttpRequestMessageProperty()
request.Headers.Add("Authorization", "Basic " & Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(service.ClientCredentials.UserName.UserName & ":" & _
service.ClientCredentials.UserName.Password)))
ServiceModel.OperationContext.Current.OutgoingMessageProperties(ServiceModel.Channels.HttpRequestMessageProperty.Name) = request
nameList.AddRange(service.getBlobNameByIdAndSectionId(section, id))
End Using
Return nameList
End Using
End Function

关于vb.net - WCF - BasicHttpBinding,没有可用的用户名和/或密码,名称 : null, 密码:空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16303950/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com