Parameter Names in WSDL with significant name

梦想的初衷 提交于 2020-01-13 07:44:29

问题


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?

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(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

<?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 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>

回答1:


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:

@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.



来源:https://stackoverflow.com/questions/11198486/parameter-names-in-wsdl-with-significant-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!