簡體   English   中英

Java WS上的身份驗證問題

[英]Problem with authentication on java ws

我有使用Java WS的C#應用​​程序。 在將WS配置為使用身份驗證之前,一切工作正常。 現在,我應該使用用戶登錄名i密碼來執行WS中的方法,但是我不確定該怎么做。 我嘗試過

var client = new MyBeanClient();
                    client.ClientCredentials.UserName.UserName = "admin";
                    client.ClientCredentials.UserName.Password = "";
                    client.addConsumer("whatever", "", "", "");

但是我收到了SecurityMessageException-{“ HTTP請求是使用客戶端身份驗證方案'Anonymous'未經授權的。從服務器收到的身份驗證標頭是'Negotiate,NTLM'。”} InnerException-(WebException)-{“遠程服務器返回錯誤:(401)未經授權。”}。

怎么了?

謝謝

嘗試這個:

var credentialCache = new CredentialCache();
var credentials = new NetworkCredential("username", "password", "domain");
credentialCache.Add(new Uri(client.Url), "NTLM", credentials);
client.Credentials = credentialCache;
client.addConsumer("whatever", "", "", "");

更新:

抱歉,在我的第一篇文章中,我認為您正在使用 wsdl.exe生成客戶端代理。 對於WCF客戶端,您需要配置端點:

 
 
 
  
  var basicHttpBinding = new BasicHttpBinding(); basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; var endpoint = new EndpointAddress("http://example.com/myWindowsAuthN"); var client = new MyBeanClient(basicHttpBinding, endpoint); client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; client.ChannelFactory.Credentials.Windows.ClientCredential.Domain = "domain"; client.ChannelFactory.Credentials.Windows.ClientCredential.UserName = "username"; client.ChannelFactory.Credentials.Windows.ClientCredential.Password = "password";
 
  


UPDATE2:

我使用以下配置來調用受NTLM身份驗證保護的Web服務。 在客戶端的app.config中放入以下內容:

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="NtlmBinding">
        <security mode="TransportCredentialOnly">
          <transport clientCredentialType="Ntlm" />
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>
  <client>
    <endpoint
      address="http://example.com/SomeWindowsAuthenticatedService"
      binding="basicHttpBinding"
      bindingConfiguration="NtlmBinding"
      contract="IOperationContractOfTheService"
      name="WSTestSoap" />
  </client>
</system.serviceModel>

然后可以在調用該方法之前設置相應的憑據:

using (var client = new MyBeanClient())
{
    client.ChannelFactory.Credentials.Windows.ClientCredential = 
        new NetworkCredential("username", "password", "DOMAIN");
    client.addConsumer("whatever", "", "", "");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM