How to compare two wsdl files

I builds a file Service.dll from a Web service for use. Now, i want to auto update file Service.dllfor time Web service changed. Current, my approach is save WSDL that is used to describe web services into Service.dll resource then compare WSDL in this resource with WSDL i got direct from Web service, if they is different i will update file Service.dll. This is my code C#:

public ServiceInspector(Uri serviceLocation) { if (serviceLocation.Query == string.Empty) { UriBuilder uriB = new UriBuilder(serviceLocation); uriB.Query = "WSDL"; serviceLocation = uriB.Uri; } _serviceLocation = serviceLocation; WebRequest wsdlWebRequest = WebRequest.Create(serviceLocation); Stream wsdlRequestStream = wsdlWebRequest.GetResponse().GetResponseStream(); //Get the ServiceDescription from the WSDL file ServiceDescription sd = ServiceDescription.Read(wsdlRequestStream); string wsdlPath = @"C:\Users\John\Downloads\Compressed\Core\TestApp\Ref\Service.wsdl"; sd.Write(wsdlPath); string sdName = sd.Services[0].Name; ServiceDescriptionImporter sdImport = new ServiceDescriptionImporter(); sdImport.AddServiceDescription(sd, String.Empty, String.Empty); sdImport.ProtocolName = "Soap"; sdImport.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties; CodeNamespace codeNameSpace = new CodeNamespace(); CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); codeCompileUnit.Namespaces.Add(codeNameSpace); ServiceDescriptionImportWarnings warnings = sdImport.Import(codeNameSpace, codeCompileUnit); if (warnings == 0) { StringWriter stringWriter = new StringWriter(System.Globalization.CultureInfo.CurrentCulture); Microsoft.CSharp.CSharpCodeProvider prov = new Microsoft.CSharp.CSharpCodeProvider(); prov.GenerateCodeFromNamespace(codeNameSpace, stringWriter, new CodeGeneratorOptions()); //Compile the assembly string[] assemblyReferences = new string[2] { "System.Web.Services.dll", "System.Xml.dll" }; CompilerParameters param = new CompilerParameters(assemblyReferences); param.GenerateExecutable = false; param.GenerateInMemory = false; param.TreatWarningsAsErrors = false; param.WarningLevel = 4; //Embedd wsdl into Resources param.EmbeddedResources.Add(wsdlPath); param.OutputAssembly = @"C:\Users\John\Downloads\Compressed\Core\TestApp\Ref\Service.dll"; CompilerResults results = new CompilerResults(new TempFileCollection()); results = prov.CompileAssemblyFromDom(param, codeCompileUnit); Assembly assembly = results.CompiledAssembly; } }

And method check wsdl changed:

private static bool IsServiceChanged(Uri uri) { Assembly assembly = Assembly.LoadFile(@"C:\Users\John\Downloads\Compressed\Core\TestApp\Ref\Service.dll"); Stream stream = assembly.GetManifestResourceStream("Service.wsdl"); if (string.IsNullOrEmpty(uri.Query)) { UriBuilder uriBuilder = new UriBuilder(uri); uriBuilder.Query = "WSDL"; uri = uriBuilder.Uri; } System.Net.WebRequest wsdlWebRequest = System.Net.WebRequest.Create(uri); using (Stream wsdlRequestStream = wsdlWebRequest.GetResponse().GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) using (StreamReader reader2 = new StreamReader(wsdlRequestStream)) { string result = reader.ReadToEnd(); string result2 = reader2.ReadToEnd(); if (string.Compare(result, result2, StringComparison.Ordinal) != 0) { return true; } } return false; }

Current,My method IsServiceChanged(Uri uri) always return True, because file wsdl written into file has change the sort order namespace . E.g:

<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"....

this is wsdl taken directly from Web service, then written into file, it will become:

<wsdl:definitions xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:s="http://www.w3.org/2001/XMLSchema" Please give me a best solution for update this my Service.dll? Thanks for help me !

A colleague of mine posed an interesting question last week. He had a test setup with three different machines on which his application under test was installed and deployed. He wanted to make sure in his test that the web service interface offered by these deployments was exactly the same by comparing the WSDLs associated with each installation. However, the tool he used (Parasoft SOAtest) only supports regression testing of single WSDL instances, i.e., it can validate whether a certain WSDL has been changed over time, but it cannot compare two or more different WSDL instances.

Luckily, SOAtest supports extension of its functionality using scripting, and I found a nice Java API that would do exactly what he asked. In this post, I’ll show you how this is done in Java. In SOAtest, I did it with a Jython script that imported and used the appropriate Java classes, but apart from syntax the solution is the same.

The Java API I used can be found here. The piece of code that executes the comparison is very straightforward:

private static void compareWSDL(){ // configure the log4j logger BasicConfigurator.configure(); // create a new wsdl parser WSDLParser parser = new WSDLParser(); // parse both wsdl documents Definitions wsdl1 = parser.parse("Z:\\Documents\\Bas\\wsdlcompare\\ParaBank.wsdl"); Definitions wsdl2 = parser.parse("Z:\\Documents\\Bas\\wsdlcompare\\ParaBank2.wsdl"); // compare the wsdl documents WsdlDiffGenerator diffGen = new WsdlDiffGenerator(wsdl1, wsdl2); List<Difference> lst = diffGen.compare(); // write the differences to the console for (Difference diff : lst) { System.out.println(diff.dump()); } }

For this example, I used two locally stored copies of a WSDL document where I changed the definition of a single element (I removed the minOccurs=”0″ attribute). The API uses Log4J as the logging engine, so we need to initialize that in our code and add a log4j.properties file to our project:

How to compare two wsdl files
When we run our code, we can see that the WSDL documents are compared successfully, and that the difference I injected by hand is detected nicely by the WSDL compare tool:

How to compare two wsdl files


A nice and clean answer to yet another automated testing question, just as it should be.

An example Eclipse project using the pattern described above can be downloaded here.

"

Get online WSDL reports and usage statistics for free.

Note! Your uploaded documents will not be visible on the internet.

New! - Analyze your Swagger specifications with Swagger Analyzer

    • Examines the structure of your WSDL
    • Analyzes embedded and imported XML schema
    • Checks for inconsistencies
    • Views WSDL for humans
    • Creates a WSDL Validation report

    The screenshot shows an excerpt of an Analyze WSDL report.

    How to compare two wsdl files

    • Compare different versions of your WSDL
    • Discover which elements were added, removed or changed
    • Understand how changes affect the contract of your WSDL

    The screenshot shows an excerpt of a WSDL Diff report.

    How to compare two wsdl files

Skip to first unread message

How to compare two wsdl files

unread,

Jan 16, 2013, 10:14:17 PM1/16/13

Sign in to reply to author

You do not have permission to delete messages in this group

Sign in to report message as abuse

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to

Dear SOA Model community,

we've got the following request and I found it a good idea to share the question here. The answer could be interesting for everyone, who intends something similar.

'I have used your online WSDL comparison tool at service-repository.com , but would like to know if you’ve got an offline or desktop version. We would like to check our unreleased schemas against the one’s on our webserver to ensure we are not introducing any breaking changes.'Of course you can use the SOA Model Java API and write your own program to compare wsdl and schema documents. But there is another much easier way to do this.

Since version 1.2.1 SOA Model provides tools to compare wsdl and schema documents from the command line without writing any code. As a result you get an HTML report with all the differences between the two documents (See the screen shot).

All you have to do after download is to set the SOA_MODEL_HOME system variable to the directory where you extract the program and run wsdldiff (or schemadiff) with two wsdl documents as parameters:

 

How to compare two wsdl files

The output will be generated in the current directory by default and look like the following. You can change this by giving a different output folder as a third parameter.
How to compare two wsdl files

These tools will be further developed and improved. In the next release there will be a detailed documentation for how to use the diff tolls and also a wsdl analyzer tool. 

So keep in touch and don't hesitate to give us a feed back or share your questions here.

Regards,

Kaveh

How to compare two wsdl files

unread,

Jun 25, 2014, 1:42:53 PM6/25/14

Sign in to reply to author

You do not have permission to delete messages in this group

Sign in to report message as abuse

Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message

to

Does it work on Mac? Any tips for a beginner on getting it to work on mac from Terminal?