简体   繁体   English

Java WS上的身份验证问题

[英]Problem with authentication on java ws

I have application in C# that consume Java WS. 我有使用Java WS的C#应用​​程序。 Everything worked fine until WS was configured to use authentication. 在将WS配置为使用身份验证之前,一切工作正常。 Now I should user login i password to execute methods from WS but I'm not sure how to do it. 现在,我应该使用用户登录名i密码来执行WS中的方法,但是我不确定该怎么做。 I've try 我尝试过

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

But I get SecurityMessageException-{"The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'."} InnerException - (WebException) - {"The remote server returned an error: (401) Unauthorized."}. 但是我收到了SecurityMessageException-{“ HTTP请求是使用客户端身份验证方案'Anonymous'未经授权的。从服务器收到的身份验证标头是'Negotiate,NTLM'。”} InnerException-(WebException)-{“远程服务器返回错误:(401)未经授权。”}。

What's wrong? 怎么了?

Thanks 谢谢

Try this: 尝试这个:

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", "", "", "");

UPDATE: 更新:

Sorry in my first post I thought you were using wsdl.exe to generate the client proxy. 抱歉,在我的第一篇文章中,我认为您正在使用 wsdl.exe生成客户端代理。 For a WCF client you need to configure the endpoint: 对于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: UPDATE2:

I've used the following configuration to invoke web services protected with NTLM authentication. 我使用以下配置来调用受NTLM身份验证保护的Web服务。 In app.config of the client put the following: 在客户端的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>

and then you could set the corresponding credentials before invoking the method: 然后可以在调用该方法之前设置相应的凭据:

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