0

有人请帮助我克服我遇到的这个错误。我是 Java Web 服务的新手。我收到如下所述的错误。我正在使用 GlassFish 服务器和 NetBeans IDE。

CalculatorWSApplication a = port.setinfo(name, age);
required: CalculatorWSApplication
found:    CalculatorWSApplication_Type
1 error

这是服务器程序

package org.me.calculator;

import com.sun.tools.xjc.api.S2JJAXBModel;
import javax.annotation.*;
import javax.annotation.PreDestroy;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;

@WebService(serviceName = "CalculatorWSApplication")
@Stateless()
public class CalculatorWSApplication {
public String firstName;
public String secondName;

    /**
     * Web service operation
     */
    @WebMethod(operationName = "add")
    public int add(@WebParam(name = "i") int i, @WebParam(name = "j") int j) {
        //TODO write your implementation code here:
        int k = i + j;
        return k;
    }


    @WebMethod(operationName = "setinfo")
    public CalculatorWSApplication setinfo(@WebParam(name = "firstName") String firstName, @WebParam(name = "secondName") String secondName) {
        CalculatorWSApplication a = new CalculatorWSApplication();
        //TODO write your implementation code here:
        System.out.println("Called");
        a.firstName = firstName;
        a.secondName = secondName;
        System.out.println(a.firstName);
        System.out.println(a.secondName);
        return a;
    }

    @PostConstruct
    public void sayHello(){
        System.out.println("Hello");
    }

    @PreDestroy
    public void sayBye(){
        System.out.println("Bye");
    }
}

这里是 Client 程序包含两个 web 方法。第一个是 add,它返回 am Integer 第二个是 setFirstNameandLastName,它返回 CalculatorWSApplication 对象。

package calculatorws_client_application;

import org.me.calculator.CalculatorWSApplication;

public class CalculatorWS_Client_Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        try{
    int i = 3;
    int j = 4;
    int result = add(i, j);
    setFirstNameandLastName("Rajesh","Gubbianna");
    System.out.println("Result = " + result);

        } catch(Exception ex){
            System.out.println("Exception: " + ex);
            ex.printStackTrace();
        }
    }

    private static int add(int i, int j) {
        org.me.calculator.CalculatorWSApplication_Service service = new org.me.calculator.CalculatorWSApplication_Service();
        org.me.calculator.CalculatorWSApplication port = service.getCalculatorWSApplicationPort();
        return port.add(i, j);
    }

    private static void setFirstNameandLastName(String name, String age){
        org.me.calculator.CalculatorWSApplication_Service service = new org.me.calculator.CalculatorWSApplication_Service();
        org.me.calculator.CalculatorWSApplication port = service.getCalculatorWSApplicationPort();
        System.out.println(name + " " + age);
        CalculatorWSApplication a = port.setinfo(name, age);
    }
}
4

1 回答 1

0

一个有效的端点实现类必须满足以下要求:

  • 它必须带有 javax.jws.WebService 注释。
  • 它的任何方法都可以带有 javax.jws.WebMethod 注释。
  • 除了任何特定于服务的异常之外,它的所有方法都可能抛出 java.rmi.RemoteException。
  • 所有方法参数和返回类型都必须与 JAXB 2.0 Java 到 XML 模式映射定义兼容。
  • 方法参数或返回值类型不得直接或间接实现 java.rmi.Remote 接口。

Java 数据类型


boolean、byte、double、float、long、int、javax.activation.DataHandler、java.awt.Image、java.lang.Object、java.lang.String 等

有关更多信息和数据类型的完整列表,您可以查看此链接

点击这里

于 2013-09-27T13:12:28.810 回答