【发布时间】:2010-09-14 11:59:27
【问题描述】:
我创建了一个简单的 web 服务,它实现了添加操作,并使用 wsimport 创建了一些客户端文件。现在我想包含尽可能少的 wsdl 特定工件。以下是如何调用 Web 服务的示例:
String serviceNamespace = "http://jws.samples.geronimo.apache.org/";
String serviceName = "CalculatorServiceService";
QName serviceQN = new QName(serviceNamespace, serviceName);
Service service = Service.create(new URL("http://localhost:8080/WebService/calculator?wsdl"), serviceQN);
String portNamespace = "http://jws.samples.geronimo.apache.org/";
String portName = "CalculatorServicePort";
QName portQN = new QName(portNamespace, portName);
Calculator myProxy = (Calculator) service.getPort(portQN, Calculator.class);
但似乎我必须为每条消息包含包装类。例如添加操作的结果消息:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "addResponse", propOrder = { "_return" })
public class AddResponse {
@XmlElement(name = "return")
protected int _return;
public int getReturn() {
return _return;
}
public void setReturn(int value) {
this._return = value;
}
}
这些包装器在服务接口的注解中使用:
@WebService(name = "Calculator", targetNamespace = "http://jws.samples.geronimo.apache.org/")
public interface Calculator {
@WebMethod
@RequestWrapper(className = "org.example.webservices.clients.dynamicproxy.Add")
@ResponseWrapper(className = "org.example.webservices.clients.dynamicproxy.AddResponse")
public int add(
@WebParam(name = "value1", targetNamespace = "")
int value1,
@WebParam(name = "value2", targetNamespace = "")
int value2);
}
如果注释被删除,Web 服务将不会运行。
com.sun.xml.ws.model.RuntimeModelerException:运行时建模器错误:未找到包装类 org.example.webservices.clients.dynamicproxy.jaxws.Add。你有没有运行 APT 来生成它们?
但是为什么我需要那些包装器呢? JAX-WS 不能即时创建这些包装器吗?您是否看到任何无法从 wsdl 文件中检索到的信息?
【问题讨论】:
-
找到一份值得一读的文件。 pic.dhe.ibm.com/infocenter/wasinfo/v7r0/…
标签: java web-services jax-ws