Consume WebService passing object as parameter

1

I have the WebService and I send the object Cliente as a paramenter, I would like to know how I can make it work, and it create a WSDL that suits when I run the Server, so that I can make the call in a WebService Client.

@WebService
public interface UCClienteWS {
    @WebMethod public Cliente cadastrarCliente(Cliente cli);
    @WebMethod public Cliente obterTelefonesDoCliente(Cliente cli);
    @WebMethod public Cliente obterClientePorID(Cliente cli);
    @WebMethod public Cliente obterClientePorNome(Cliente cli);
    @WebMethod public boolean excluirClientePorID(Cliente cli);
    @WebMethod public ArrayList<Cliente> obterTodosClientes();
}

.

@WebService(endpointInterface = "webservice.cliente.UCClienteWS")
public class UCClienteImpl implements UCClienteWS{

    @Override
    public Cliente cadastrarCliente(Cliente cli) {
        UCCliente ucCliente = new UCCliente();
        return ucCliente.cadastrarCliente(cli);
    }

    @Override
    public Cliente obterTelefonesDoCliente(Cliente cli) {
        UCCliente ucCliente = new UCCliente();
        return ucCliente.obterTelefonesDoCliente(cli);
    }

    @Override
    public Cliente obterClientePorID(Cliente cli) {
        UCCliente ucCliente = new UCCliente();
        return ucCliente.obterClientePorID(cli);
    }

    @Override
    public Cliente obterClientePorNome(Cliente cli) {
        UCCliente ucCliente = new UCCliente();
        return ucCliente.obterClientePorNome(cli);
    }

    @Override
    public boolean excluirClientePorID(Cliente cli) {
        UCCliente ucCliente = new UCCliente();
        return ucCliente.excluirClientePorID(cli);
    }

    @Override
    public ArrayList<Cliente> obterTodosClientes() {
        UCCliente ucCliente = new UCCliente();
        return ucCliente.obterTodosClientes();
    }

}
    
asked by anonymous 03.02.2016 / 13:55

1 answer

1

Well, I'm going to share with you how I use a WS from a client application.

Well, let's start Mass. : -D

There is a tool that already comes within the JDK that is simple, easy and free to generate the client (consumer) classes of your Web service. It is the wsimport tool via DOS command line (Windos) or terminal (Linux). Make sure that JAVA_HOME is configured in your system variables, if not, you will have to add JAVA_HOME in your environment variables.

Well, let's get down to business. : -D

I will consider that your Web service is already developed and ready to be consumed and is already published.

1- access your service through the browser such as link

2 - Save this URL with .wsdl extension as UCClientWS.wsdl (save preferably within your client application, because if you are using SVN or something else, it is already versioned.)

3 - Access the cmd or terminal (according to your environment) and go to where your wsdl file is saved.

4 - type wsimport -keep -verbose UCClienteWS.wsdl This will create a folder structure for you with the client classes inside.

5- Copy and paste this package into your client application.

6 - calling the methods and passing its object:

6.1- Within this structure a Client Class was created that is the object that the service accepts. In this class there are some annotations saying that it will become an XML object when it is sent to the service.

6.2 - calling the service

Cliente cli = new Cliente();
cli.setNome("Zé");
cli.setRenda("1.000.000,00");

UCClienteWSService service = new UCClienteWSService();
UCClienteWS ucCliente= UCClienteWSService .getUCClienteWSPort();

ucCliente.cadastrarCliente(cli);

That's the way to go.

Anything google search something about wsimport. è susse. I hope you have helped.

Embrace ..

    
03.02.2016 / 21:32