Click here to Skip to main content
Click here to Skip to main content

WSDL and Schema Parser

By , 25 Nov 2005
 

Introduction

If you want to aggregate a web service with your application service, or if you are trying to implement someone else's WSDL, then you need to pay attention while viewing them. That means you are encountering the web service interoperability problem. That was the problem I had too, and I thought that having a GUI for viewing a WSDL like tree structure could be really cool.

In my previous article on UDDI Explorer, I presented an approach for searching the web service and parsing the web service description information (WSDL). It focused on UDDI and parsing the abstraction (interface) level of WSDL. I sometimes encounter questions that fall into the same idea of parsing WSDL that also takes into account the implementation of the information level.

In addition to refactoring, this library was developed to patch up the known bugs of the previous article. It aims to achieve better result by improving some features like:

  • Bottom-up parsing of WSDL document.
  • Collection based parsing of XML schema.
  • Generating XML document from XML schema.

Background

If you are not familiar with WSDL, SOAP, XML schema, then before going further please check out these resources:

Parsing the WSDL

As you can see, the WSDL can be represented as a tree structure. The parsing task includes two major modules: WSDL parser and the XML schema parser. The WSDL parsing task goes from the implementation level up to the abstraction level. The parser proceeds as follows:

  • For clarity, we first get all the <service> elements. For each <service> element, we jump to the <Binding> element that matches the service, and get the set of operations that the <binding> element includes, and then jump to the <PortType> definition which the <binding> element points to.
  • Finally, we find the operations set of the <PortType> element. Parsing such operations is based on the binding information (style, use attributes) and the input/output message declaration associated with them. This process also takes into account parsing of the associated XML schema.

The XML schema parser module includes a process that translates the XML schema structure into a tree that looks like the XML instance of each SOAP message. It is featured in detail below:

  • Reference type definition

    Reference definition is a mechanism to make schema simple through the sharing of common segments/types. In the process of transforming this structure into a tree, I chose to duplicate the shared segment under the node that refers to it.

  • Preventing infinite recursive definition

    This happens when a leaf element refers to one of its ancestors. (I.e. A class has a member as an instance of it.) This structure definition will also break the tree structure and it has to be solved differently from the way of solving reference types, otherwise it will fall into an infinite recursive loop. In this case, it just shows the node (which refers to its ancestors) with a predefined depth.

  • Handling multiple schema elements

    This occurs when an element has an unbounded value for the maxOccur attribute. It will be treated by duplicating the same element.

  • Handling the inherit definition

    A complexType which is defined based on other types will be built as the derived structure. That means the derived node contains the base node elements.

  • Handling the namespace

    If an element form is qualified, the XML element should be displayed in the qualified name.

It turns out that there is no easy way to do parsing of the XML schema due to its structure which is extremely rich and complex. Due to the declaration difference between the operation styles of Document/RPC, the input/output tree might be different. We can extend the result of XML schema parser to solve the problem of generating XML document from XML schemas.

Using the library

The view displays the service name, protocol, port, the collection of operations that are exposed by the port and their parameters. Depending on the complexity of WSDL and the server status, the TreeView may take a few seconds to render. Move your cursor over any operation element to view the input/output parameters associated with it.

This library contains two major parser modules as mentioned above. The extra module helps you to create XML from a tree node; in this case it generates XML data from the XML schema tree. You can use them in both 1.1 or 2.0 Framework.

I've tested it on some quite big web services with size larger than 10000 lines and with a complex schema definition, by just entering the web service address and clicking the Parse button. Now, let's take a look at how the tree looks like!

Conclusion

Web services are still growing up and going to play an important role in distributed computation. However, there are many misconceptions that exist in this technology. At the basic level, this tool can partially help you in creating the business process. I will stop for now and expect to have more time to enrich the explanation.

My special thanks to Marc Clifton and Lluis Sanchez for their works on XSD and WSDL generation that helped me in saving my time for implementing such things.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Thanh Dao
Software Developer
Vietnam Vietnam
Member
I'm still alive...but temporarily moved to work on mobile & web stuffs(j2me/brew/php/flash...something not M$). things have just been very busy, and probably will continue...so don't have chance to maintain & respond. Hope will have time to try to write again, because many ideas with WPF &silver light are waiting. wish me luck Smile | :)
 
FYI:
- MESHSimPack project(c# library for measuring similarity among concepts of the MESH ontology):
http://sourceforge.net/projects/meshsimpack.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionsoap xml [modified]memberschalla1237 May '13 - 5:57 
Hi I entered my wsdl
"https://service100.emedny.org:9047/MHService?wsdl"
and all I see is the nodes... none of xml shows up.. Is this xpected behavior

modified 7 May '13 - 12:05.

SuggestionTo improve performancememberSatyacbit24 Apr '12 - 22:49 
While creating the tree, render only the top level elements. On expand of any element, render its children. This increases the performance in case of large and complex Schemas.
--Satya

QuestionCan't find the TreeNode.Tag object in C#.Netmemberdisney67512 Apr '12 - 16:56 
I realize that there is no TreeNode.Tag in System.Web.UI.WebControls.
Is there any alternative way?
Thanks a lot.
GeneralMy vote of 5membermanoj kumar choubey15 Feb '12 - 23:34 
Nice ...
QuestionSilverlightmemberuugii5556 Dec '11 - 17:05 
Could you improve this works on the Silverlight.
j

QuestionCan I parse local files?membertechstress18 Feb '11 - 5:38 
when i try to parse a local file path it shows a blank entry
GeneralWSDL parser to extract types and their facets from a WSDL documentmembersruthi116 Jul '08 - 14:10 
Hi,
 
I would like to parse WSDL to extract types section from it.(i.e. what are the types in this WSDL document and their facets)
 
Can I use this WSDL and Schema Parser for this?
 
If not, are there any other open source programs which does this?
 
Thanks,
Ritika
GeneralDerivative/Extension worksmemberSantosh Benjamin15 Mar '08 - 10:50 
Hi,
Would you be ok with people using this as a base for non commercial extensions? ~(ie) take the WSDL parser as a base and then use it in other tools?
 
Please let me know cos i am interested in using this as a building block for some other tools.
 
rgds
benjy
GeneralRe: Derivative/Extension worksmemberThanh Dao6 Jun '08 - 4:12 
Sorry for this lately response. as this project released under the CP License so it's ok to do so. It's quite excited to see your work.
 
Thanh Dao

GeneralRe: Derivative/Extension worksmemberrohith shenoy19 Apr '12 - 8:02 
I love your work...! Thanks Thanh. Its really helping me in my academics, as building blocks for my projects.
Generalparse SOAP HeadermemberAtanu GB19 Aug '07 - 20:32 
This is great tool, but how do I generate XML for a method, which has soap header.
GeneralDemo & code no longer in syncmemberbrigw141 May '07 - 12:45 
Great tool! However, the Demo and the code provided do not seem to be matching. In particular, it looks like the Demo displays the details within WSDL elements while the code provided only works its way down to the element level. Anyone have ideas on what is causing this problem in the currently available code?
AnswerRe: Demo & code no longer in syncmemberipsharer27 Feb '09 - 5:41 
Use VS2003 to compile the code and it will work fine.
GeneralRe: Demo & code no longer in syncmemberRobert Tji17 Mar '09 - 5:42 
If you use VS2008 (and perhaps VS2005), you need to change one line of code in the Add_ComplexElements() method. When type.ContentTypeParticle is equal to EmptyParticle, the first condition succeeds when it should be failing. Unfortunately, EmptyParticle is not accesible so you cannot use that enum. However you can check for ContentModel being null instead.
 
void Add_ComplexElements (TreeNode complexNode, string ns, XmlSchemaComplexType stype)
{
    //if (stype.ContentTypeParticle != null)
    if (stype.ContentModel != null)
    {
        Parse_ParticleComplexContent (complexNode, ns, stype.ContentTypeParticle);
    }
    ...

GeneralRe: Demo & code no longer in syncmemberDJ_SG8 May '11 - 23:48 
Thx, Robert.
Although I don't quite understand what u said. But the one line of code change really makes it work.
GeneralWSDL parsingmemberrorobisso4 Apr '07 - 1:21 
Hello,
 
I was wondering whether there is an easy way to parse a WSDL file programmatically in order to get the different web methods along with their input and output parameters; i.e. given a WSDL file, we only want a way to find the different methods so that we can invoke one of them.
 
Thank you so much,
Rawia Smile | :)
QuestionHow I can send credentials for authentication?memberDock196 Sep '06 - 7:31 
Hi Thanh!
I am studying your tool and I have a question: is possible to form the shipment of credentials for authentication? (Just I need basic authentication over http/s)
 
XmlTextReader reader=new XmlTextReader (cboURL.Text);
ServiceDescription service = ServiceDescription.Read(reader);
//in this line i get "The remote server returned an error: (401) Unauthorized."
 
I cannot put credentials in ServiceDescription class . is some other form?
 
Thank you very much for your answer and excuse my bad english Smile | :)
 
Gabriel
AnswerRe: How I can send credentials for authentication?memberDock196 Sep '06 - 9:17 
Do This:
 
replace
XmlTextReader reader=new XmlTextReader (cboURL.Text);
ServiceDescription service = ServiceDescription.Read(reader);
 
for this:
System.Net.WebRequest request = System.Net.WebRequest.Create(cboURL.Text);
request.Credentials = new System.Net.NetworkCredential("XXX", "XXX");
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
ServiceDescription service = ServiceDescription.Read(response.GetResponseStream());

 
Bye

AnswerRe: How I can send credentials for authentication?memberdan p27 Feb '08 - 11:25 
not sure if this is what you're looking for, but try putting the authentication inline to the url
 
ex: http://amazon.com/something.wsdl ==> http://user:pass@amazon.com/something.wsdl
GeneralGenerated Xml to Soap Requestmember[V]GreyWolf5 Sep '06 - 13:44 
I'm just wondering would it be possible to take the generated xml fill in some data and use serialization on it to create a soap request?
QuestionsimpleTypes?memberLinski24 May '06 - 23:08 
Hi,
 
Great tool!
 
I'm heaving some problems parsing simpleTypes though. The subelements of simpleTypes are not shown....
 
Greetz,
Linda
AnswerRe: simpleTypes? [modified]memberThanh Dao25 May '06 - 4:00 
Do you mean something like "facet" ? you can get a better version of the schemaParser in folllowing article code. sorry for this inconvenience Sleepy | :zzz:
 
http://www.codeproject.com/useritems/XPathEditor.asp[^]
 
Thanh Dao
 

General.net 2.0memberNetguy21 May '06 - 6:48 
Hi Thanh,
 
Great job!
I tried converting the project to .net 2.0 all works fine except that the input & output paramters are not being populated.
 
Do you have any ideas on this?
 
Thanks
 
<%= Netguy %>
GeneralRe: .net 2.0memberThanh Dao25 May '06 - 4:16 
Please find the following code for Net 2.0 of the WSDLParser class
http://www.codeproject.com/cs/webservices/uddiexplorer.asp[^]
 
Thanh Dao
 

GeneralRe: .net 2.0memberomeng22 Jun '06 - 22:41 
hi Thanh! u have a great tool
 
i have a question though, why am I having a The remote server returned an error: (401) Unauthorized error on this line
ServiceDescription service=
ServiceDescription.Read(reader);
 
do i need to pass credentials? if so how can i pass credentials? or is it a folder permission problem?
 
Thanks!!
Romar

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 25 Nov 2005
Article Copyright 2005 by Thanh Dao
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid