Consume Webservice passing object as parameter

Asked

Viewed 940 times

1

I have the Webservice and send the object Cliente as a parameter, I would like to know how to make it work, and it create a suitable WSDL when running Server, so I can make the call on a Client Webservice.

@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();
    }

}

1 answer

1


Good, I will share with you how I use a WS from a client application.

Well, let’s start mass. -D

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

Let’s get down to business. -D

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

1- access your service from the browser as for example http://ingo.com/myapp/UCClienteWS?wsdl

2- saved that URL with extension . wsdl as Ucclientews.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 goes to where your wsdl file is saved.

4- 4 wsimport -keep -verbose UCClienteWS.wsdl this will create a folder structure for vc with the client classes inside.

5- copy and paste this folder (package) into your client application.

6- calling the methods and passing their object:

6.1- Within this structure, a Customer Class was created, which is the object that the service accepts. In this class there are annotations saying that it will become an XML object when 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.

Any google search something about wsimport. è susse. I hope it helped.

Hug..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.