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

Tagged as

Go to top

Validating SOAP Message against WSDL

, 8 Jun 2011
Rate this:
Please Sign up or sign in to vote.
A program that checks whether SOAP message conforms to WSDL

Introduction

While developing our web service client, I received a message from the server that did not deserialize properly. It was rather large, and just by looking at it, I could not figure out what was wrong. It was obvious it is not conforming to the schema the client expects, but where?

I Googled it, and found that many people ask that same question: how do I check a SOAP message against WSDL? Surprisingly, there was no simple answer. I ended up checking the message in Eclipse IDE (we do some Java development too, so I had one installed). However, it required manually altering the message to add appropriate schema locations.

At this point, I decided to write a simple validator that would do this job automatically. Thanks to .NET built-in XML validation functionality, it is not very hard to do: all you need is to parse arguments and supply proper input to a validating XML reader.

Using the Code

Since downloading executables is forbidden in many companies, and compiling an executable is a hassle, I created the validator as a self-compiling .BAT file. Beginning of the file has some command line instructions for compilation, the rest is C# 2.0 source code. All you need is the .BAT file and .NET framework 2.0 or higher.

Since CodeProject does not allow uploading .BAT files, I renamed it to .TXT. Rename it back to .BAT after download. A precompiled executable is also available.

Using the code is straightforward:

SoapValidator message.xml contract.wsdl schema1.xsd schema2.xsd... 

All arguments except for the message file name are optional. If you supply "-" for file name, this means "read standard input".

The validator can check any XML document, not just SOAP messages. To make SOAP validation easier, the schema for the SOAP format itself (envelope, body, header) is built into the validator.

In additional to XSD schema files, the validator recognizes WSDL files with <schema> tags. If any schemas are imported, they must have valid schemalocation accessible to the validator.

Points of Interest

Self-compiling batch files or scripts are not a regular thing in .NET, while they are very common in UNIX. I find them useful, because they are not executable code per se (easier to get through firewalls and mail filters), and you don't need an IDE to compile them. I really wish Windows had the #! notation from UNIX, but alas.

History

  • 16th April, 2011: Initial post
  • 7th June, 2011: Replaced "exit" with "exit /B 0" on line 10 of SoapValidator.bat. This prevents it from closing the command prompt window.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0

Share

About the Author

Ivan Krivyakov
Technical Lead Thomson Reuters
United States United States
Ivan is a hands-on software architect/technical lead working for Thomson Reuters in the New York City area. At present I am mostly building complex multi-threaded WPF application for the financial sector, but I am also interested in cloud computing, web development, mobile development, etc.
 
Please visit my web site: www.ikriv.com.

Comments and Discussions

 
QuestionNot telling me where the error is PinmemberMember 85397564-Jan-12 8:03 
AnswerRe: Not telling me where the error is PinmemberIvan Krivyakov4-Jan-12 8:19 
GeneralRe: Not telling me where the error is PinmemberMember 85397564-Jan-12 8:47 
GeneralMy vote of 4 PinmemberJV99999-Jun-11 1:20 
GeneralSounds promising! PinmemberJV99998-Jun-11 10:16 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 8 Jun 2011
Article Copyright 2011 by Ivan Krivyakov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid