I am using a third party Web Service whose definition and implementation are beyond my control. This web service will change in the future.
The Web Service should be used to generate an XML file which contains some of the same data (represented by the same XSD types) as the Web Service plus some extra information generated by the program.
My approach:
The XSD types I am going to use in my own XSD file, but are defined in the WSDL, are subject to change. Whenever they change, I would like to automatically process the XSD and WSDL databinding again. (If the change is significant enough, this might trigger some development effort.(But usually not.))
My problem:
In step 1 I need an XSD referring to the same types as used by the Web Service.
The WSDL is referring to another WSDL, which is referring to another WSDL etc. Eventually there is an WSDL with the needed inline XSD types. As far as I know there is no way to directly reference the inline XSD types of a WSDL from an XSD.
The approach I would think most viable, is to include an extra step in the automatic processing (before the databinding) that extracts the inline XSD from the WSDL into other XSD file(s). These other XSD file(s) can then be referred to by my own XSD file.
Things I'd like to avoid:
PS: I found some similar questions, but they all had responses like: WTH would you want to do that? That is the reason for my rather large background story.
I don't know any libraries that would do this for you, but it is definitly possible to implement with a bit of effort (~200 lines). A rough meta-program to generate all inline and included XSDs:
method processWSDL(Document wsdl) {
for each ("/wsdl:definitions/wsdl:types/xsd:schema" in wsdl) {
call processXSD("inline_[i].xsd",".")
}
for each ("/wsdl:definitions/wsdl:import" in wsdl) {
Document x = read and parse ("@location")
if (x is WSDL) call processWSDL(x)
else if (x is XSD) call processXSD("@location", x)
}
}
method processXSD(String filename, Document xsd) {
write "xsd" to a new file "filename" // if 'filename' is a URL, take only the part after the last '/'
for each ("/xsd:schema/xsd:import" or "/xsd:schema/xsd:include" in xsd) {
if ("@schemaLocation" is local reference) { // no 'http://' prefix
Document x = read and parse ("@schemaLocation")
call processXSD("@schemaLocation", x)
}
}
}
It is not a full solution, e.g. does not handle namespace prefixes defined outside of the inline schema, but hopefully gives a good starting point.
Just to keep this post relevant, things have changed since an answer was accepted. It is now possible in Java to generate what you want starting from WSDL; JAX-WS provides the wsimport tool that does exactly what's requested: take the WSDL, create a client proxy along with a bunch of JAXB-annotated classes for un/marshalling of requests.
I would say though, to @MoizTankiwala 's point, that the need to export XSD content from WSDL (or to include all external XSD content inside a WSDL's types section) is alive and well.
The former is something that makes sense when someone has a large body of XSDs, and there's a general concern regarding effective managing, analysing and evolving of that model in XSD.
The latter is also sought after since some (mainly) dynamic languages still lack full blown support from tooling when it comes to WSDL to client side proxy generation.
My other answer on SO talks about a similar need, that should help at least with Moiz's request...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With