运行有错
Big鹏 2008-06-09 06:59:27 Exception in thread "main" AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.generalException
faultSubcode:
faultString: java.lang.NoClassDefFoundError: Book; nested exception is:
java.lang.NoClassDefFoundError: Book
程序功能:给定一个ISBN号,查出图书名称
代码如下:\
共三个类import java.io.Serializable;
public class Book implements Serializable {
private String name;
private String ISBN;
public Book()
{}
public Book(String name,String ISBN)
{
this.name=name;
this.ISBN=ISBN;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getISBN() {
return ISBN;
}
public void setISBN(String isbn) {
ISBN = isbn;
}
public String toString(Book b)
{
return b.toString();
}
}
第二个类
import java.util.*;
public class bookInput {
Vector vector=new Vector();
public bookInput()
{
Book book1=new Book("Java2实用教程","7-302-04723-5");
Book book2=new Book("C++程序设计","7-302-08456-4");
vector.add(book1);
vector.add(book2);
}
public String getBookinfo(String isbn)
{
for(int i=0;i<2;i++)
{
String isbn1=((Book)vector.get(i)).getISBN();
if (isbn1.equals(isbn))
{
return (((Book)vector.get(i)).getName());
}
}
return "";
}
}
第三个类
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.utils.Options;
import javax.xml.namespace.*;
import javax.xml.rpc.ParameterMode;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
public class Bookservice
{
public static void main(String [] args) throws Exception {
String host = "http://localhost:";
String wsdlUrl= "http://localhost:8080/axis/bookInput?wsdl";
String nameSpaceUri = "http://localhost:8080/axis/bookInput";
String servicepath = "/axis/bookInput.jws";
Options options = new Options(args);
int port = options.getPort();
String endpoint = host + port + servicepath;
String method = null;
args = options.getRemainingArgs();
if (args == null || (!((method = args[0])).equals("getBookinfo")) )
{
System.err.println("no book information");
return;
}
String op1 = null;
if (method.equals("getBookinfo")) {
op1 = args[1];
}
String ret = null;
Service service = new Service();
Call call = (Call) service.createCall();
QName qn = new QName("urn:BeanService","Book");
call.registerTypeMapping(Book.class,qn,new BeanSerializerFactory(Book.class, qn),new BeanDeserializerFactory(Book.class, qn));
call.setTargetEndpointAddress(new java.net.URL (endpoint));
//call.setOperationName("getBookinfo");
call.setOperationName(new QName(nameSpaceUri, "getBookinfo"));
if (op1 != null) {
call.addParameter("op1", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
ret = (String) call.invoke(new Object [] {op1});
} else {
call.setReturnType(XMLType.XSD_INT);
ret = ((Integer) call.invoke((Object[])null)).toString();
}
System.out.println("Got result : " + ret);
}
}