Consume Web Service SGS Banco Central Brasil - Dollar Quotation

Asked

Viewed 1,928 times

2

I was able to generate the (java) client in Eclipse, available in WSDL https://www3.bcb.gov.br/sgspub/JSP/sgsgeral/FachadaWSSGS.wsdl.

The following classes were generated:

package br.gov.bcb.pec.sgs.casosdeuso.ws.comum;  
    WSValorSerieVO  
    WSSerieVO  

package br.gov.bcb.www3.wssgs.services.FachadaWSSGS  
    interface FachadaWSSGS   
    interface FachadaWSSGSService  
    classe FachadaWSSGSServiceLocator  
    classe FachadaWSSGSProxy  
    classe FachadaWSSGSSoapBindingStub 

My question now is how to instantiate these classes and use the service. My goal is to get the dollar quote on a specific date dd-mm-aaaa

Someone can give a boost?

I think it would be something close to:

public class main {
public static void main(String[] args) throws ServiceException {    
    FachadaWSSGSProxy proxy = new FachadaWSSGSProxy();
    FachadaWSSGSServiceLocator service = new FachadaWSSGSServiceLocator();
    FachadaWSSGSSoapBindingStub stub = (FachadaWSSGSSoapBindingStub) service.getPort(proxy.getEndpoint(),FachadaWSSGSService.class );       
    try {
        System.out.println(stub.getValor (1,"24/01/2017").toString());
    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

But this doesn’t work.

  • Hello Itamar, post more details about your problem. You generated the Java code how? Eclipse allows generating clients in the wsimport standard / JAX-RS (wsimport), Axis Standard (Wsdl2java ), etc. The call you are looking for is getValor with in0 = 1 (Exchange rate series code) and in1 = date in format dd/MM/aaaa

  • For more details about the WSSGS see help page

  • Dear Anthony, I managed the client on the Apache Axis and Client Type = Java Proxy standard. My question is how to instantiate the Service and Stub to be able to use the getValor method.

  • What exactly didn’t work? Edit the question and paste the stack trace of the error.

  • In the can not even run, because the excerpt of code posted above, was just an example of how I imagine the instantiation of classes, but I have no idea the correct way to do.

  • Itamar, I’m not realizing the problem... Unfortunately there is one more way to use the customer correctly. Are you afraid to run your code (if it goes wrong nothing bad will happen)? Or are you looking for examples to compare to your version? Follows a trivial example using Proxy and another using Locator.

Show 1 more comment

2 answers

3


I generated a JAR containing the available classes in : (https://github.com/wmixvideo/cotacao), and then I instituted normally the Wsconsulta object, passing the desired parameters.

System.out.println(" dolar: "+(String.valueOf(new WSConsulta().getCotacao(Indice.DOLAR_COMPRA, LocalDate.of(2017, 01, 10)))));

Worked perfectly.

Note: One should be careful with the consultations in days not useful, because it returns null.

-1

Good morning, my friend! You must implement in this way:

public class Main {

    public static void main(String[] args) {
           FachadaWSSGSProxy proxy = new FachadaWSSGSProxy();
            try {
                System.out.println(proxy.getValor (1,"24/01/2017").toString());
            } catch (RemoteException e) {
                e.printStackTrace();
                System.out.println(e.getMessage());
            }
    }

}

Browser other questions tagged

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