title: How to compare two Web Service Descriptions (wsdl)?
body: <p>I builds a file <code>Service.dll</code> from a Web service for use. Now, i want to auto update file <code>Service.dll</code> for time Web service changed. Current, my approach is save WSDL that is used to describe web services into <code>Service.dll</code> 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#:</p>
  
  <pre><code> 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;
          }
      }
  </code></pre>
  
  <p>And method check wsdl changed:</p>
  
  <pre><code> 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;
      }
  </code></pre>
  
  <p>Current,My method <code>IsServiceChanged(Uri uri)</code> always return <code>True</code>, because file wsdl written into file has change the sort order namespace . E.g:</p>
  
  <pre><code>&lt;wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"....
  </code></pre>
  
  <p>this is wsdl taken directly from Web service, then written into file, it will become:</p>
  
  <pre><code>&lt;wsdl:definitions xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:s="http://www.w3.org/2001/XMLSchema" 
  </code></pre>
  
  <p>Please give me a best solution for update this my Service.dll? Thanks for help me !</p>