45

I need to generate a WSDL file given an XSD file. How do I do this? Can I do this in VS2005? What is the simplest way to do this?

informatik01
  • 16,038
  • 10
  • 74
  • 104
Ausgar
  • 693
  • 1
  • 8
  • 12

6 Answers6

56

You cannot - a XSD describes the DATA aspects e.g. of a webservice - the WSDL describes the FUNCTIONS of the web services (method calls). You cannot typically figure out the method calls from your data alone.

These are really two separate, distinctive parts of the equation. For simplicity's sake you would often import your XSD definitions into the WSDL in the <wsdl:types> tag.

(thanks to Cheeso for pointing out my inaccurate usage of terms)

Muhd
  • 24,305
  • 22
  • 61
  • 78
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Hi Marc! Thank you for clarifying that! I'll go back and do my homework on this! – Ausgar May 28 '09 at 10:15
  • Marc, do you mean "import the schema into wsdl:types" rather than "include the XSD into wsdl:Schema"? – Cheeso May 28 '09 at 10:36
  • 2
    You can do both - you can either include a XSD in a WSDL, or you can copy&paste the contents of the XSD into the WSDL - both works. – marc_s May 28 '09 at 11:42
  • Well, no. wsdl:schema doesn't exist. The element is wsdl:types. And the preferred mechanism is xsd:import, not cut-and-paste, nor "include". If by "include" you mean "import", I suggest you use the accurate term. – Cheeso May 28 '09 at 14:31
  • Yes, I'm aware of that, Cheeso - but there are some braindead dev environments that cannot deal with xsd:import and statements like that - in that case, good ole cut&paste might end up being your only options. It's an option - not a great one, but it's there if you really need it. – marc_s May 28 '09 at 15:05
  • I'm completely missing http://wscfblue.codeplex.com/ from any of the answers, you can generate wsdl from given xsd, you just have to choose which element from the xsd will be input of your soap method. – jhexp Jun 29 '11 at 10:31
  • @jhexp: good point - at the time I answered this question, WSCF Blue wasn't available yet (I believe) – marc_s Jun 29 '11 at 11:13
34

I'd like to differ with marc_s on this, who wrote:

a XSD describes the DATA aspects e.g. of a webservice - the WSDL describes the FUNCTIONS of the web services (method calls). You cannot typically figure out the method calls from your data alone.

WSDL does not describe functions. WSDL defines a network interface, which itself is comprised of endpoints that get messages and then sometimes reply with messages. WSDL describes the endpoints, and the request and reply messages. It is very much message oriented.

We often think of WSDL as a set of functions, but this is because the web services tools typically generate client-side proxies that expose the WSDL operations as methods or function calls. But the WSDL does not require this. This is a side effect of the tools.

EDIT: Also, in the general case, XSD does not define data aspects of a web service. XSD defines the elements that may be present in a compliant XML document. Such a document may be exchanged as a message over a web service endpoint, but it need not be.


Getting back to the question I would answer the original question a little differently. I woudl say YES, it is possible to generate a WSDL file given a xsd file, in the same way it is possible to generate an omelette using eggs.

EDIT: My original response has been unclear. Let me try again. I do not suggest that XSD is equivalent to WSDL, nor that an XSD is sufficient to produce a WSDL. I do say that it is possible to generate a WSDL, given an XSD file, if by that phrase you mean "to generate a WSDL using an XSD file". Doing so, you will augment the information in the XSD file to generate the WSDL. You will need to define additional things - message parts, operations, port types - none of these are present in the XSD. But it is possible to "generate a WSDL, given an XSD", with some creative effort.

If the phrase "generate a WSDL given an XSD" is taken to imply "mechanically transform an XSD into a WSDL", then the answer is NO, you cannot do that. This much should be clear given my description of the WSDL above.

When generating a WSDL using an XSD file, you will typically do something like this (note the creative steps in this procedure):

  1. import the XML schema into the WSDL (wsdl:types element)
  2. add to the set of types or elements with additional ones, or wrappers (let's say arrays, or structures containing the basic types) as desired. The result of #1 and #2 comprise all the types the WSDL will use.
  3. define a set of in and out messages (and maybe faults) in terms of those previously defined types.
  4. Define a port-type, which is the collection of pairings of in.out messages. You might think of port-type as a WSDL analog to a Java interface.
  5. Specify a binding, which implements the port-type and defines how messages will be serialized.
  6. Specify a service, which implements the binding.

Most of the WSDL is more or less boilerplate. It can look daunting, but that is mostly because of those scary and plentiful angle brackets, I've found.

Some have suggested that this is a long-winded manual process. Maybe. But this is how you can build interoperable services. You can also use tools for defining WSDL. Dynamically generating WSDL from code will lead to interop pitfalls.

Cheeso
  • 189,189
  • 101
  • 473
  • 713
  • How are you going to determine the SOAP actions and such?? Just from the data? That's at best a bit speculative, no? – marc_s May 28 '09 at 11:43
  • How do you know just from your XSD which of the wsdl:operation will have which SOAP faults and such?? You might be able to GUESS at best..... – marc_s May 28 '09 at 11:45
  • How do you know from just your XSD what kind of SOAP binding you'll have? style=document or style=RPC ??? – marc_s May 28 '09 at 11:45
  • how do you even know the service endpoint of your whatever-service if you only have a XSD describing the data being passed around??? – marc_s May 28 '09 at 11:46
  • Long-winded manual editing process that forgets that .xsd doesn't define WSDL methods or type of SOAP binding and other parameters. – JeeBee May 28 '09 at 12:44
  • My apologies for the confusion. Let me point out that I do not suggest that XSD is equivalent to WSDL, nor is XSD sufficient to produce a WSDL. But that you can produce a WSDL using an XSD, just as an omelette from an egg. An egg is not an omelette. An XSD is not a WSDL. In each case there is something more that must be added. – Cheeso May 28 '09 at 14:20
10

I know this question is old, but it deserves an answer. I personally prefer to create a WSDL by hand and test for compliance using SoapUI. But sometimes (specially for complex WSDLs), you have three ways to generate one out of an XSD:

  1. Generating a WSDL from a schema using Eclipse (probably the most user-friendly)
  2. Generating a WSDL via CXF (my favorite)
  3. Generating a WSDL via conventions using Spring WS (my least favorite)

I prefer the CXF approach since I'm a CLI guy. If it has a CLI, you can automate (that's my motto). And I like the Spring WS approach the least since it uses a lot of framework specific conventions.

There are more people who know CXF (I believe) than Spring WS. So anything that can throw a learning curve for a new engineer (without any clear advantage or ROI) is something I frown upon.

It should also go w/o saying that any generated WSDL should be tested for validity and compliance (and tweaked till it complies), and that your application publishes a static wsdl (as opposed to returning an auto-generated one.)

It's been my experience that you start with a WS-I compliant wsdl and then your application auto-generates (and returns to consumers) a non-compliant one.

In other words, beware of auto magic.

luis.espinal
  • 10,331
  • 6
  • 39
  • 55
7

This tool xsd2wsdl part of the Apache CXF project which will generate a minimalist WSDL.

Vishnu
  • 1,011
  • 14
  • 31
0

we can generate wsdl file from xsd but you have to use oracle enterprise pack of eclipse(OEPE). simply create xsd and then right click->new->wsdl...

0

Personally (and given what I know, i.e., Java and axis), I'd generate a Java data model from the .xsd files (Axis 2 can do this), and then add an interface to describe my web service that uses that model, and then generate a WSDL from that interface.

Because .NET has all these features as well, it must be possible to do all this in that ecosystem as well.

JeeBee
  • 17,476
  • 5
  • 50
  • 60
  • Gee that sounds circular. Why not generate a WSDL by xsd:import'ing the XSD into the wsdl:types element, then generate the Java or .NET interface from THAT? It's called "the WSDL-First approach" and it gives good interoperability. – Cheeso May 28 '09 at 10:35
  • 1
    Because you want to define the methods for the web service, and the .xsd doesn't specify those, so you would have to hand-edit the methods into any .wsdl that you generated in your way - idiotic IMO. – JeeBee May 28 '09 at 12:43