Web服务客户端错误

时间:2011-05-08 20:05:44

标签: java web-services jax-ws

嗨,有人可以帮助我使用这个webservice贝司我在netbeans上部署了这个web服务,它运行良好 但是,当我想在下面创建一个基于此Web服务的Web服务客户端时,它给了我错误消息:

  

JAXWS导入实用程序无法创建Webserice客户端    原因:文件过早结束    在java atifacts创建期间可能存在问题,例如生成的类中的名称冲突

它还继续说。

  

要检测问题,请参阅输出窗口中的错误消息,您可以在WSDL中修复问题     自定义对话框(编辑webservices属性操作)或手动编辑本地WSDL     或使用JAXB自定义的模式文件本地wsdl和模式文件位于xml资源目录中。

package emp;
import java.util.*;
import java.io.*;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import java.util.List;
/**
 *
 * @author Frederick Carter
 */
@WebService()
public class BankWS {
private static Vector<Employee> staff = new Vector<Employee>();

    @WebMethod(operationName = "readChoice" )
    public static int readChoice() {
    Scanner scnnr = new Scanner(System.in);
    return scnnr.nextInt();
    }

    @WebMethod(operationName = "readInput" )

        public static String readInput() {
        Scanner scnnr = new Scanner(System.in);
        return scnnr.nextLine();
    }


    @WebMethod(operationName = "readFileForStaff")

    public static Vector<Employee> readFileForStaff() throws IOException {





        String strFilePath = "./src/staff.txt";
        final String NEW_LINE = "\n";
        final String COMA = ",";
        final String id = "id";
        Vector<String> v = new Vector<String>();


        Vector<Employee> empl = new Vector<Employee>();
        String[] tmpString;

        // reads file
        Scanner fileScaner = new Scanner(new File(strFilePath));
        // reads each line
        fileScaner.useDelimiter(NEW_LINE);

        while (fileScaner.hasNext()) {
            v.add(fileScaner.next());
        }
        fileScaner.close(); // closes scanner
        for (int i = 0; i < v.size(); i++) {
            Employee em = new Employee();
            // splits string into substrings
            tmpString = v.get(i).split(COMA);
            if (tmpString[0].equals(id)) {
                em.setName(tmpString[1]);
                em.setPassword(tmpString[2]);
                empl.add(em);
            }
        }
        return empl;
    }

    @WebMethod(operationName = "readFileForCustomer")
        public static Vector<Customer> readFileForCustomer() throws IOException {

        String strFilePath = "./src/customer.txt";
        final String NEW_LINE = "\n";
        final String COMA = ",";
        final String id = "id";
        Vector<String> v = new Vector<String>();
        Vector<Customer> cstmr = new Vector<Customer>();
        String[] tmpString;

        // reads file
        Scanner fileScaner = new Scanner(new File(strFilePath));
        // reads each line
        fileScaner.useDelimiter(NEW_LINE);

        while (fileScaner.hasNext()) {
            v.add(fileScaner.next());
        }
        fileScaner.close(); // closes scanner
        for (int i = 0; i < v.size(); i++) {
            Customer csr = new Customer();
            // splits string into substrings
            tmpString = v.get(i).split(COMA);
            if (tmpString[0].equals(id)) {
                csr.setName(tmpString[1]);
                csr.setSurname(tmpString[2]);
                csr.setAccount(tmpString[3]);
                csr.setBalance(Integer.parseInt(tmpString[4]));
                cstmr.add(csr);
            }
        }
        return cstmr;
    }



    @WebMethod(operationName = "writeToFile")
    public static void writeToFile() throws IOException {
        String strFilePath = "./src/staff.txt";
        BufferedWriter writer = new BufferedWriter(new FileWriter(strFilePath));
        for (int i = 0; i < staff.size(); i++) {
            writer.write("id," + staff.get(i).getName() + "," + staff.get(i).getPassword()+"\n");
        }
        writer.close();
    }
   @WebMethod(operationName = "writeToCustomerFile")

  public static void  writeToCustomerFile (@WebParam(name = "customer") List<Customer> customers) throws IOException
    {
    String strFilePath = "./src/customer.txt";
        BufferedWriter writer = new BufferedWriter(new FileWriter(strFilePath));



for (Customer cust : customers) {
    writer.write("id," + cust.getName() + "," + cust.getSurname() + "," +
        cust.getAccount() + "," + cust.getBalance() + "\n");
}
writer.close();
}
   @WebMethod(operationName = "checkEmployee")
 public static boolean checkEmployee(@WebParam(name = "em") String em, @WebParam(name = "psswd") String psswd) {
        for (int i = 0; i < staff.size(); i++) {
            if (staff.get(i).getName().equalsIgnoreCase(em) && staff.get(i).getPassword().equalsIgnoreCase(psswd)) {
                return true;
            }
        }
        return false;
    }
   @WebMethod(operationName = "register")

  public static void register(@WebParam(name = "n") String n, @WebParam(name = "p") String p) throws IOException {
        Employee e = new Employee();
        e.setName(n);
        e.setPassword(p);
        staff.add(e);
        writeToFile();
    }
   @WebMethod(operationName = "showEmployees")

   public static void showEmployees() {
        System.out.println("No of employees: " + staff.size());
        for (int i = 0; i < staff.size(); i++) {
            System.out.println("Employee: " + staff.get(i).getName() + " " + staff.get(i).getPassword());
        }
    }
   @WebMethod(operationName = "Initialise")
   public static void Initialise() throws IOException {
        staff = readFileForStaff();
    }
}

0 个答案:

没有答案