Spero che tu mi possa ancora aiutare. Ho realizzato un webservice che restituisce la somma di due numeri interi ed ho un problema con l'esecuzione del client, ovvero
1. con il comando C:\projects\Somma>java org.apache.axis.wsdl.WSDL2Java -t -W -p client Somma.wsdl ho determinato la creazione della cartella client la quale contiene i seguenti file:
1. SommaService.java
2. Somma_PortType.java
3. SommaServiceLocator.java
4. SommaServiceTestCase.java
5. SommaSoapBindingStub.java
2. di tali file ho modificato il file SommaServiceTestCase.java nella seguente maniera:
codice:
/**
* SommaServiceTestCase.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.2 May 03, 2005 (02:20:24 EDT) WSDL2Java emitter.
*/
package client;
public class SommaServiceTestCase extends junit.framework.TestCase {
public SommaServiceTestCase(java.lang.String name) {
super(name);
}
public void testSommaWSDL() throws Exception {
javax.xml.rpc.ServiceFactory serviceFactory = javax.xml.rpc.ServiceFactory.newInstance();
java.net.URL url = new java.net.URL(new client.SommaServiceLocator().getSommaAddress() + "?WSDL");
javax.xml.rpc.Service service = serviceFactory.createService(url, new client.SommaServiceLocator().getServiceName());
assertTrue(service != null);
}
public int test1SommaGetSomma(int x, int y) throws Exception {
client.SommaSoapBindingStub binding;
try {
binding = (client.SommaSoapBindingStub)
new client.SommaServiceLocator().getSomma();
}
catch (javax.xml.rpc.ServiceException jre) {
if(jre.getLinkedCause()!=null)
jre.getLinkedCause().printStackTrace();
throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
}
assertNotNull("binding is null", binding);
// Time out after a minute
binding.setTimeout(60000);
// Test operation
int value = 0;
value = binding.getSomma(x, y);
// TBD - validate results
return value;
}
}
3. Ho creato la classe Client contenente il metodo main() :
codice:
package client;
public class Client {
public static void main (String[] args) throws Exception {
SommaServiceTestCase sstc = new SommaServiceTestCase("");
int somma = sstc.test1SommaGetSomma(3, 4);
System.out.println("La somma risulta: "+somma);
}
}
4. Ho compilato i file del package client nella seguente maniera:
codice:
C:\projects\Somma\client>javac -Xlint *.java
SommaServiceLocator.java:116: warning: [unchecked] unchecked call to add(E) as a
member of the raw type java.util.HashSet
ports.add(new javax.xml.namespace.QName("urn:com.dominio.service.som
ma", "Somma"));
^
SommaServiceLocator.java:10: warning: [serial] serializable class client.SommaSe
rviceLocator has no definition of serialVersionUID
public class SommaServiceLocator extends org.apache.axis.client.Service implemen
ts client.SommaService {
^
2 warnings
5. ma quando vado ad eseguire il main mi viene sollevata la seguente eccezione:
codice:
C:\projects\Somma\client>java Client
Exception in thread "main" java.lang.NoClassDefFoundError: Client (wrong name: c
lient/Client)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)