java WSDL 中具有重要名称的参数名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11198486/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Parameter Names in WSDL with significant name
提问by user1084509
I am creating a WebService in Java using JAXWS RI. The WSDL file is created when deploying the application WAR automatically. The problem is that I want the arguments (that each operation recieves) in the WSDL file to have significant names, but they appear as arg0, arg1, arg2 ... Is there a way to define the names for this parameters and don't use the default names?
我正在使用 JAXWS RI 在 Java 中创建一个 WebService。WSDL 文件是在自动部署应用程序 WAR 时创建的。问题是我希望 WSDL 文件中的参数(每个操作接收到的)具有重要的名称,但它们显示为 arg0、arg1、arg2……有没有办法定义这个参数的名称而不是使用默认名称?
I have implemented the following:
我已经实现了以下内容:
The WebService Interface
网络服务接口
@WebService
@SOAPBinding(style = Style.RPC)
public interface WS2 {
@WebMethod String confirmaXML(String lrt_id);
}
The WebService Interface Implementation
WebService 接口实现
@WebService(endpointInterface = "vital.tde.ws2.WS2")
public class WS2Imp implements WS2{
public String confirmaXML(String lrt_id) {
String respuesta = null;
//CODE
return respuesta;
}
sun-jaxws.xml
sun-jaxws.xml
<?xml version="1.0" encoding="UTF-8"?>
<endpoints
xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
version="2.0">
<endpoint name="WS2" implementation="vital.tde.ws2.WS2Imp" url-pattern="/WS2" />
</endpoints>
web.xml
网页.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>WS2</display-name>
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>WS2</servlet-name>
<servlet-class>
com.sun.xml.ws.transport.http.servlet.WSServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>WS2</servlet-name>
<url-pattern>/WS2</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>120</session-timeout>
</session-config>
</web-app>
回答by Mac
If you're generating your WSDL from your web service class, you may add WebParam
annotations to the parameters of your methods to enforce naming in the WSDL. For example:
如果您从 Web 服务类生成 WSDL,则可以WebParam
向方法的参数添加注释以强制在 WSDL 中命名。例如:
@WebService
public class FooService
{
@WebMethod(operationName = "barMethod")
public void bar (@WebParam(name = "bazArg") int baz)
{
...
}
}
The above snippet configures JAX-WS to use the name "bazArg" for the method's parameter name in the WSDL.
上面的代码片段将 JAX-WS 配置为使用名称“bazArg”作为 WSDL 中方法的参数名称。