如何在一个连接中使用多个SOAP Web服务?

时间:2020-08-14 18:32:17

标签: jax-ws spring-ws java-ws

我正在尝试使用Web服务,但是要使用Web服务,我需要登录。问题是登录服务未返回令牌等。因此,我需要在连接时发送登录请求和其他Web服务请求。就像数据库连接一样。 login(),sendRequest(),logout()。

使用标准的WebServiceTemplate.marshalSendAndReceive()方法,我会收到 org.springframework.ws.soap.client.SoapFaultClientException:需要会话错误消息。 后来,我发现 WebServiceConnection 有用,但无法实现。我不知道是不是出于这个目的。

那么,在春季如何使用WebServiceTemplate或其他方式实现这一目标?

其他信息

登录服务:https://erpefaturatest.cs.com.tr:8043/efatura/ws/userService?wsdl

Web服务:https://erpefaturatest.cs.com.tr:8043/efatura/ws/connectorService?wsdl

他们在文档中为Java提供了此功能,

public class Login8043 {
    
    public Login8043() {}
    
    Connector8043.ConnectorService port;

    public Login8043(String usrname, String pass) {
        try {
            Connector8043.ConnectorService_Service service = new Connector8043.ConnectorService_Service();
            this.port = service.getConnectorServicePort();
            this.port = setAuthToPort(port, usrname, pass);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static Connector8043.ConnectorService setAuthToPort(Connector8043.ConnectorService port, String username, String password) {
        BindingProvider bp = (BindingProvider) port;
        Binding binding = bp.getBinding();
        List<Handler> handlerChain = new ArrayList<>();
        WebServiceSecurityHeaderHandler wsSecurity = new WebServiceSecurityHeaderHandler(username, password);
        handlerChain.add(wsSecurity);
        binding.setHandlerChain(handlerChain);

        return port;
    }
}

在提供的代码中,我无法弄清楚“ Connector8043.ConnectorService端口”对象是什么,因此,我无法实现该对象。等待您的帮助。

0 个答案:

没有答案