therefore, when trying to instantiate an object of the class, the error is
Cannot instantiate the type
Does anyone know why Eclipse would generate an interface instead of a class? The web service was originally written in VB.Net but can be replicated following the simple example given here
Write the code...
package test; import NET.webserviceX.www.CurrencyConvertor; import NET.webserviceX.www.CurrencyConvertorSoap; import NET.webserviceX.www.Currency; public class Convert { public static void main(String[] args) { CurrencyConvertor cc = new CurrencyConvertor(); // Gets an implementation of the interface we can use // to contact the web service. CurrencyConvertorSoap ccs = cc.getCurrencyConvertorSoap(); // Send the SOAP request to the server and get the result from the web service double conversionRate = ccs.conversionRate(Currency.GBP, Currency.USD); System.out.println("£1 is worth $" + conversionRate ); } }
What's happening is the CurrencyConverter.java is imported as an interface, so it can't be instantiated.
It should be imported as a class. Why isn't it?
I cannot reproduce your pb, but if you use java 1.6+ then you can generate your types with wsimport tool provided in JDK.
use following command in a terminal:
Windows:
"C:\Program Files\Java\jdk1.6.0_45\bin\wsimport.exe" -keep http://www.webservicex.net/CurrencyConvertor.asmx?WSDL
Linux:
pathToJDK/bin/wsimport -keep http://www.webservicex.net/CurrencyConvertor.asmx?WSDL
You'll see some warnings, just ignore them. Then you'll get your class CurrencyConvertor.
I've tried this on my machine and it works!
--updated 27/07/2015---
I saw you're trying to us wscompile
. In fact, this tool had been replaced by wsimport
long time ago. see oracle documentation:
http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/2.0/jaxws/UsersGuide.html
Part 1.1.2 Fully Dynamic Runtime
It should also be noted that wscompile has been replaced by two new tools: wsimport and wsgen. wsimport is used for importing WSDLs and generating the portable artifacts.
Have to use wscompile from "java web services developer pack" which requires a JDK 5... and was designed for pre-win 7 OS.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.