0

我正在尝试在我的 VB.Net 应用程序中使用安全的第三方 Web 服务(我无法控制),并且在尝试调用该服务时出现以下错误:

从另一方收到不安全或不正确安全的故障。有关故障代码和详细信息,请参阅内部 FaultException。

内部异常:

{“必须理解标头:[{ http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd }Security] 不被理解。”}

该服务通过用户/通行证和证书进行保护。我通过 wsdl 创建了 WCF 服务引用就好了,下面是我用来设置服务的代码。我对 Web 服务的经验很少,而且我不知道该尝试什么。另外,如果有帮助的话,我正在使用 .NET 3.5。代码抛出异常就行了;

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

完整代码:

Private Function GetVendorService() As Services.ServiceClient
    Dim binding As New BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential)

    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>
    <binding name="ServiceSoapBinding1" 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="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="https://url-d.menards.net:8443/cxf/Service/v1/ws"
    binding="basicHttpBinding" bindingConfiguration="ServiceSoapBinding"
    contract="Services.Service"
    name="ServiceSoapPort" />
</client>

4

0 回答 0