How to get response from SOAP endpoint in java?

前端 未结 5 1642
悲哀的现实
悲哀的现实 2021-01-21 16:44

I am very new to SOAP, so was looking into some programs online, this is what I came up with but I get a null response, must be some silly thing, but need little help

Pl

5条回答
  •  旧巷少年郎
    2021-01-21 17:24

    What you want to do is auto-generate Java code for this web service. The WSDL is here: http://www.webservicex.net/periodictable.asmx?wsdl

    In Java, the tool to auto-generate the code is wsimport. You'll want to use something like this:

    wsimport http://www.webservicex.net/periodictable.asmx?wsdl -p com.company.whateveruwant -Xnocompile -d . -keep
    

    This will put the code you want in the specified package (here com.company.whateveruwant).

    From there, all you have to do is simply invoke the SOAP method like a normal Java library:

    PeriodictableSoap soap = new Periodictable().getPeriodictableSoap();
    System.out.println(soap.getAtomicNumber("Iron"));
    

    This prints out:

    
      26IronFe55.84733007.91.64000000000000011.1718087874

提交回复
热议问题