客户端身份验证方案 'Negotiate' - 从服务器收到的身份验证 header 是 'Basic realm=\“EJBWebServiceEndpointServlet Realm\”'

Client authentication scheme 'Negotiate' - The authentication header received from the server was 'Basic realm=\“EJBWebServiceEndpointServlet Realm\”'

以下 SOAP 操作采用搜索参数和 returns 搜索结果 object:

public static void SearchWebServiceClient()
{
    SearchWebServiceClient client = new SearchWebServiceClient(); // Creates client

    client.ClientCredentials.UserName.UserName = "someUsername"; // Assigns client credentials
    client.ClientCredentials.UserName.Password = "somePassword";

    client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

    searchForComponents componentSearch = new searchForComponents(); // Creates operation
    searchForComponentsResponse componentSearchResponse = new searchForComponentsResponse(); // Creates operation response

    componentSearch.searchTerm = "someSearchTerm"; // The parameter being passed to the operation

    componentSearchResponse = client.searchForComponents(componentSearch); // Sends request. Exception happens here.
}

发出请求时,导致此异常:

$exception {"The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Basic realm=\"EJBWebServiceEndpointServlet Realm\"'."} System.Exception {System.ServiceModel.Security.MessageSecurityException}

App.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
  </startup>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="SearchWebServiceBinding"
                 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="TransportCredentialOnly">
            <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
            <message clientCredentialType="UserName" algorithmSuite="Default"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://someaddress.com:80/somedirectory/somedirectory/search-service?wsdl"
          binding="basicHttpBinding" bindingConfiguration="SearchWebServiceBinding"
          contract="SearchWebService.SearchWebService" name="Search" />
    </client>
  </system.serviceModel>
</configuration>

服务器在我的网络外部托管,我无法view/edit它的配置。

有谁知道这可能是什么原因造成的?提前致谢!

问题出在这一行:

<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>

您想进行Windows身份验证,即Negotiate。尝试将其更改为:

<transport clientCredentialType="Basic" proxyCredentialType="None" realm=""/>