有人请帮助我克服我遇到的这个错误。我是 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);
}
}