Withheld
Withheld

Reputation: 4703

How to pull detailed schema info from a WSDL based web service?

Assuming I am developing a client for a known, WSDL-based, web service (of which source code is not available to me):

Is there a way I can validate various fields (e.g. string lengths not exceeding limit) based on the inline schema in that WSDL, at runtime?

If so, how do I interact with that web service to get its inline XSD information?

Upvotes: 2

Views: 1220

Answers (1)

Petru Gardea
Petru Gardea

Reputation: 21658

If you want to make this really dynamic, than you have to assume that the URI to the WSDL is accessible to you, along with all other external references the WSDL might use, to other WSDL files and/or XSD files.

First step, you will have to download files to a temp folder, or create I/O streams to those URIs for in memory loading, to load a schema (a javax.xml.validation.Schema). I am not aware of a Java API which would make this task easy (get a schema out of WSDL reference, such as one available to developers on the .NET platform) - hopefully if there is one, someone might chime in. Otherwise, it shouldn't be that difficult to write one.

I have to warn you that many people may consider this (loading external URIs, particularly one pointing to the Internet) as a security issue in a production environment, so be careful here with your design. Since you're saying "a known, WSDL-based, web service", I would probably aquire the XSDs at design time, and bundle them as resources in my Jar files which would go with the client code.

The next thing is how do you create your XML... Let's say you're using something such as JAXB, then a post such as this one will give an idea how to tackle your problem, and what exactly do you need to validate. If you're not using JAXB, then explore what your API is doing, and how it would actually allow you to interject your validation...

I hope that this at least gives you an idea around the kind of details you need to have in this kind of question, to get a more specific answer.

Upvotes: 2

Related Questions