Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

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.

Is there a way to make my WebMethod parameters required, short of manually editing the xsd and setting minOccurs to 1?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
160 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.

You also have to upgrade your JDK by putting the JAX-WS 2.2 webservices-api.jar in the endorsed/ directory.

I posted the same question on the Java forums.

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.

When @XmlElement(required=true) is set on the parameter SoapUI no longer indicates that the parameter as optional.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...