Click here to Skip to main content
15,867,568 members
Articles / Programming Languages / C#

Validating SOAP Message against WSDL

Rate me:
Please Sign up or sign in to vote.
4.63/5 (7 votes)
8 Jun 2011Apache2 min read 69.9K   2.5K   12   6
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


Written By
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

 
QuestionERROR: Namespace not declared Pin
Member 1178638823-Jun-15 5:19
Member 1178638823-Jun-15 5:19 
QuestionNot telling me where the error is Pin
Member 85397564-Jan-12 8:03
Member 85397564-Jan-12 8:03 
AnswerRe: Not telling me where the error is Pin
Ivan Krivyakov4-Jan-12 8:19
Ivan Krivyakov4-Jan-12 8:19 
GeneralRe: Not telling me where the error is Pin
Member 85397564-Jan-12 8:47
Member 85397564-Jan-12 8:47 
Here's what I get when trying to figure out why I'm getting problems when validating the response.

C:> soapvalidator soapresponse.xml Authentication.wsdl
Error: SchemaReadException
Authentication.wsdl: XmlSchemaException: The type attribute cannot be present with either simpleType or complexType.
GeneralMy vote of 4 Pin
JV99999-Jun-11 1:20
professionalJV99999-Jun-11 1:20 
GeneralSounds promising! Pin
JV99998-Jun-11 10:16
professionalJV99998-Jun-11 10:16 

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

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