如何使 WebMethod 参数成为必需 [英] How can I make a WebMethod parameter required
问题描述
我们使用从 Java 开始"的方法来创建使用 Metro 1.5 堆栈的 JAX-WS 2.0 Web 服务.当我们将像 SoapUI 这样的标准工具指向我们的一个 Web 服务时,它表明 WebMethods 的参数是可选的.生成的 xsd 显示 minOccurs=0.
We use the "start from Java" approach to creating JAX-WS 2.0 web services using the Metro 1.5 stack. When we point a standard tool like SoapUI at one of our web services it indicates that parameters to WebMethods are optional. The generated xsd shows minOccurs=0.
我需要一种在从 Java 开始"方法中使 WebMethod 参数成为必需的方法(在 xsd 中可能是 minOccurs=1).我认为有一个 Java 注释,但我找不到.XmlElement 注解有 required 属性,但 XmlElement 不能应用于 WebMethod 参数.
I need a way to make WebMethod parameters required (maybe minOccurs=1 in the xsd) in the "start from Java" approach. I would think there is a Java annotation for this, but I haven't been able to find one. The XmlElement annotation has required attribute, but XmlElement cannot be applied to WebMethod parameters.
除了手动编辑 xsd 并将 minOccurs 设置为 1 之外,有没有办法使我的 WebMethod 参数成为必需的?
Is there a way to make my WebMethod parameters required, short of manually editing the xsd and setting minOccurs to 1?
推荐答案
我已经验证 Metro 2.0 确实允许您在参数上设置 @XmlElement(required=true)
.生成的 xsd 没有 minOccurs=0
.它将 minOccurs
排除在生成的 xsd 之外,因此它假定默认值为 1.
I've verified that Metro 2.0 does allow you to set @XmlElement(required=true)
on a parameter. The generated xsd does not have minOccurs=0
. It leaves minOccurs
out of the generated xsd so it assumes the default value of 1.
您还必须通过将 JAX-WS 2.2 webservices-api.jar
放在 endorsed/
目录中来升级您的 JDK.
You also have to upgrade your JDK by putting the JAX-WS 2.2 webservices-api.jar
in the endorsed/
directory.
我发布了同样的问题 在 Java 论坛上.
I posted the same question on the Java forums.
感谢 jitu 的回答并指出 minOccurs 默认为 1,因此将其排除在 .xsd 之外具有预期的效果.
Thanks to jitu for both the answer and pointing out that minOccurs defaults to 1 so leaving it out of the .xsd has the desired effect.
当在参数上设置@XmlElement(required=true) 时,SoapUI 不再表示该参数为可选.
When @XmlElement(required=true) is set on the parameter SoapUI no longer indicates that the parameter as optional.
这篇关于如何使 WebMethod 参数成为必需的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!