views:

3916

answers:

4

Hi,

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

Cheers!

Ausgar

+4  A: 

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.

Marc

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

marc_s
Hi Marc!Thank you for clarifying that! I'll go back and do my homework on this!
Ausgar
Marc, do you mean "import the schema into wsdl:types" rather than "include the XSD into wsdl:Schema"?
Cheeso
marc_s
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
marc_s
A: 

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
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
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
+1  A: 

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
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
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
How do you know from just your XSD what kind of SOAP binding you'll have? style=document or style=RPC ???
marc_s
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
Long-winded manual editing process that forgets that .xsd doesn't define WSDL methods or type of SOAP binding and other parameters.
JeeBee
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
A: 

try this www.theprogrammerfactory.com

Milfar