使用 Java 使用 NTLM 身份验证调用 Navision Web 服务上的方法

call a method on Navision webservice using NTML authentication using Java

我在 Netbeans 上创建了一个 SOAP 网络服务客户端。 Web 服务通过 NTML 身份验证在 Navision 上公开。在 class 生成期间,登录弹出窗口会选择所需的凭据并将其用于身份验证。 问题是一旦生成 classes 并且我尝试调用任何方法;

    ServicePort webservice_port = new WService().getServicePort();
    webservice_port.retrieveData();

我遇到异常。

java.io.IOException: Server returned HTTP response code: 401 for URL: ...

Exception in thread "main" com.sun.xml.ws.wsdl.parser.InaccessibleWSDLException: 2 counts of InaccessibleWSDLException.
    at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:275)
    at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:246)
    at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:209)
    at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:178)
    at com.sun.xml.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:363)
    at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:321)
    at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:230)
    at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:211)
    at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:207)
    at com.sun.xml.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:114)
    at javax.xml.ws.Service.<init>(Service.java:57)
    at com.ntml.remote.MSACCO.<init>(MSACCO.java:42)

这是 NTLM 身份验证的问题还是有其他方法来传递凭据?

找到了可行的解决方案。正在使用 Web 服务端口向客户端注入身份验证机制。

        Port webservice_port = new Wservice().getServicePort();
        Client client = ClientProxy.getClient(webservice_port);
        HTTPConduit conduit = (HTTPConduit) client.getConduit();
        AuthorizationPolicy authorization = conduit.getAuthorization();
        authorization.setUserName(username);
        authorization.setPassword(password);
        conduit.getClient().setAllowChunking(false);
        conduit.getClient().setAutoRedirect(true);
        webservice_port.callWebMethod();