我有一个@WebMethod 调用
@WebMethod
public int cancelCampaign(String campaignId, String reason);
我想将campaignId 字段标记为必填项。不知道该怎么做。
我正在使用 JBOSS 7.1 服务器。
最佳答案
我有一个类似的要求,从 SoapUI 我注意到我得到了
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:bus="http://business.test.com/">
<soapenv:Header/>
<soapenv:Body>
<!-- optional -->
<bus:addItem>
<bus:item>
<id>?</id>
<!-- optional -->
<name>?</name>
</bus:item>
<!-- optional -->
<itemType>?</itemType>
</bus:addItem>
</soapenv:Body>
</soapenv:Envelope>
代替
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:bus="http://business.test.com/">
<soapenv:Header/>
<soapenv:Body>
<bus:addItem>
<bus:item>
<id>?</id>
<name>?</name>
</bus:item>
<itemType>?</itemType>
</bus:addItem>
</soapenv:Body>
</soapenv:Envelope>
JAX-WS Metro 2.0 RI 中的一个出路是用
@XmlElement( required = true )
就我而言,我必须对所有必需的自定义类型的必需 WebMethod 参数和 getter 执行此操作,如下所示:
在网络服务中:
...
@WebMethod( operationName = "getItems" )
@WebResult( name = "item" )
public List<Item> getItems(
@WebParam( name = "itemType" ) @XmlElement( required = true ) String itemType );
...
在我的 POJO 类(class)中:
@XmlAccessorType(XmlAccessType.FIELD)
public class Item implements Serializable
{
private static final long serialVersionUID = 1L;
@XmlElement( required = true )
private int id;
@XmlElement( required = true )
private String name;
/**
* Default constructor.
*/
public Item() { }
/**
* @return the id
*
*/
public int getId()
{
return id;
}
/* setter for id */
/**
* @return the name
*/
public String getName()
{
return name;
}
/* setter for name */
}
关于jboss - JAXB-WS - 使用 @WebMethod 强制设置字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12642335/