开发者

JAX-WS: how to inform client of valid parameter values?

I'm creating a simple web service with only one method. The client sends a list of Strings that are the names of facilities (toilets, printers, buried treasure, whatever) they want to locate. The service sends back the locations of whatever facilities were requested.

Obviously the server can only understand cert开发者_如何学运维ain Strings. If a client asked for "cake", the server has no information on this. I've already coded the service to send an exception if it is given any invalid Strings, but is there any way to specify in the WSDL file the list of valid values, so that clients can know in advance what to send?

I'm using the NetBeans Web Service creation tools to implement the service, so if somebody could specify how this can be done using those tools, that would be a bonus. Thanks to anybody who can assist.


Use enums instead of strings, and the wsdl will represent the enum with the possible values in XML Schema. if you are writing your own WSDL, you'll have to learn about enums in XML schema. If you are Java-first, just use a Java enum.


You'll need to specify these desired restrictions in the WSDL or in an imported XSD, for each of the types corresponding to the input messages.

Additionally, you'll need to switch on schema validation. Assuming that you are using Metro as the JAXWS implementation, you'll need to use the SchemaValidation annotation.

More details could be found in this related question at StackOverflow.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜