How can I use the W3C validator API in a .NET application?

I found that there is an API for the W3C markup validator .

I previously asked: Is there a .NET library for the W3C validation validation API?

Assaf answer :

This API is based on SOAP. If you want to use it in a .net application, you can just add a web link and code against it. It seems simple enough, as it is basically a single method API ...

So, I tried "Add Service Link" at http://validator.w3.org/check .

First a dialog box opens:

Please wait for the service information to load ...

Then:

An error occurred ... when trying to find services on ' http://validator.w3.org/check '

Visual Studio Add Service Reference Dialog Box http://img17.imageshack.us/img17/719/addservicereference.gif

Error Details:

The HTML document does not contain web page service discovery information. Metadata contains a link, cannot be resolved: ' http://validator.w3.org/check '. content type text / html; encoding = UTF-8 of the response message does not match the content type of the binding (application / soap + xml; charset = utf-8). If you use a custom encoder, make sure that the IsContentTypeSupported method is executing properly. The first 1024 bytes of the response:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <title> Validation Results - W3C Markup Validator</title> <link rel="icon" href="data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%10%00%00%00%10%08%02%00%00%00%90%91h6%00%00%00%19IDAT(%91c%BCd%AB%C2%40%0A%60%22I%F5%A8%86Q%0DCJ%03%00%DE%B5%01S%07%88%8FG%00%00%00%00IEND%AEB%60%82" type="image/png" /> <link rev="made" href="mailto: www-validator@w3.org " /> <link rev="start" href="./" title="Home Page" /> <style type="text/css" media="all">@import "./style/base.css"; @import "./style/results.css";</style> <meta name="keywords" content="HTML, HyperText Markup Language, Validation, W3C Markup Validation Service" /> <meta name="description" content="W3C easy-to-use H 

If the service is defined in the current solution, try building the solution and adding the link service again.

How can I use the W3C validation validation API in my .NET application?

+1
source share
5 answers

W3C is not a standard SOAP service! It can give a formatted SOAP response, but call it a crazy REST URL based service http://validator.w3.org/check?uri=YourURLToProof&charset=utf-8&output=soap12

+3
source

In order for the web link to work, I think that the owner of this service needs to publish a WSDL file for .Net to read and create local objects. Then you call these local objects in your project, and they are populated with data from the other end of the service using SOAP.

I was looking for a WSDL file that describes a W3C WAP file for verification on my site, but so far no luck. Which is odd if the W3C manages the WSDL protocol. You really expected them to use it!

If anyone knows:

  • A way to work with a web link without WSDL or ...
  • Where is the WSDL file of the W3C Validator ...

Then please let me know ...

Otherwise, the W3C installed a link to the C # library on their website ( http://validator.w3.org/docs/api.html#libs ), which is simple enough to download and build. But it uses LINQ to create the SOAP-based object returned by the W3C, which seems a bit heavy for my purposes ... This is a useful starting point, if nothing else.

+2
source

I ran into the same problem and wrote the .NET W3C Validation API Wrapper .

+2
source

SOAP web service must have WSDL. I saw some references on the W3C SOAP API site, but the location of the API or WSDL to it is not obvious.

Pulling out and browsing with Bing, I found the following: http://www.w3.org/Search/Mail/Public/search?type-index=www-validator&index-type=t&keywords=wsdl&search=Search

Good luck. It seems that they did it a little back, and the web service was an afterthought from people who did not quite understand the concept of WSDL.

+1
source

In fact, you can download and install the validator on your website from https://github.com/validator/validator

Some useful notes about the page

I called a quick C # validation method: https://validator.w3.org/nu/?doc=http://www.example.com&out=json

So:

 using Newtonsoft.Json; using System.Net; using System.Net.Http; private void ValidateFromW3Org(string url) { HttpClientHandler clientHandler = new HttpClientHandler(); HttpClient client = new HttpClient(clientHandler); client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0"); string validator = string.Format( "http://validator.w3.org/nu/?doc={0}&out=json", url); string response = client.GetStringAsync(url).Result; PageValidationResult pageResults = JsonConvert.DeserializeObject< PageValidationResult>(response); IList<ValidationResult> results = pageResults.Messages; foreach(ValidationResult result in results) { Console.WriteLine("{0}:{1} line: {2} - {3}", result.Type, result.SubType, result.LastLine, result.Message); } } public class ValidationResult { public string Type { get; set; } public string SubType { get; set; } public int LastLine { get; set; } public int FirstColumn { get; set; } public int LastColumn { get; set; } public string Message { get; set; } public string Extract { get; set; } public int HiliteStart { get; set; } public int HiliteLength { get; set; } } public class PageValidationResult { public string Url { get; set; } public IList<ValidationResult> Messages { get; set; } } 

Please note that this is just a sample. You would not want to reuse HttpClient in a method this way. It also uses third-party Newtonsoft.Json to parse the json result.

0
source

Source: https://habr.com/ru/post/955289/


All Articles