Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Help with using XML SpellChecker Service

by Anonymous Monk
on Nov 19, 2007 at 01:43 UTC ( [id://651558]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Perl Monks,

I have a project where I am supposed to access a web service using XML/SOAP to check for the spelling of some texts. The web service is located at http://ws.cdyne.com/SpellChecker/check.asmx. I looked around this site and the XML protocol format that it accepts is:
http://ws.cdyne.com/spellchecker/check.asmx?op=CheckTextBody
SOAP 1.2 The following is a sample SOAP 1.2 request and response. The placehold +ers shown need to be replaced with actual values. POST /spellchecker/check.asmx HTTP/1.1 Host: ws.cdyne.com Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://ww +w.w3.org/2003/05/soap-envelope"> <soap12:Body> <CheckTextBody xmlns="http://ws.cdyne.com/"> <BodyText>string</BodyText> <LicenseKey>string</LicenseKey> </CheckTextBody> </soap12:Body> </soap12:Envelope> HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://ww +w.w3.org/2003/05/soap-envelope"> <soap12:Body> <CheckTextBodyResponse xmlns="http://ws.cdyne.com/"> <DocumentSummary> <MisspelledWord> <Suggestions>string</Suggestions> <Suggestions>string</Suggestions> <word>string</word> <SuggestionCount>int</SuggestionCount> </MisspelledWord> <MisspelledWord> <Suggestions>string</Suggestions> <Suggestions>string</Suggestions> <word>string</word> <SuggestionCount>int</SuggestionCount> </MisspelledWord> <ver>string</ver> <body>string</body> <MisspelledWordCount>int</MisspelledWordCount> </DocumentSummary> </CheckTextBodyResponse> </soap12:Body> </soap12:Envelope>
I have created a simple HTML interface for the user to enter the text for spell check but am not sure how to proceed on connecting to this web site and sending the text over and retrieving the XML response back. What kind of module to I need to include in my Perl script? use xml::simple? Please help. Some simple script to help me started would be appreciated.

Thanks.
Here is my html interface to take the user input:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html> <head> <title>OS2 - Lab3 Project</title> </head> <body> <center><b><font size="+3">Online Spellchecker via SOAP and XML</b></c +enter> <br> <br> <p> <form method="post" action="cgi-bin/check.cgi"> <b>Enter text:</b><textarea cols="45" rows="5" name="text"></textarea> <br> <pre> <input type="submit" name="submit" value="Submit"></ +pre> <br> <b>Correction:</b><textarea cols="45" rows="5" name="response"></texta +rea> <p> <p> <br> </form> </body> </html>

Replies are listed 'Best First'.
Re: Help with using XML SpellChecker Service
by erroneousBollock (Curate) on Nov 19, 2007 at 06:22 UTC
    The web-service exposes a SOAP interface, including a WSDL description of the service at:

      http://ws.cdyne.com/SpellChecker/check.asmx?WSDL

    To talk to the service, use SOAP::WSDL.

    Something like the following should work (modify as appropriate with license key and real content to be checked):

    use strict; use warnings; use SOAP::WSDL; use Data::Dumper; # config vars my $tocheck = "you want a test?\nthars ees my boody text"; my $license = '12345yourlicensekey'; my $service = 'http://ws.cdyne.com/SpellChecker/check.asmx'; my $wsdl = "$service?WSDL"; # initialise the SOAP proxy object my $soap = SOAP::WSDL->new(); $soap->wsdl($wsdl); # $soap->on_action(sub { return $_[0].$_[1]; }); # uncomment if you ge +t a soapfault containing something like 'invalid SOAPAction'. $soap->proxy($service); $soap->wsdlinit(caching => 1) || die "couldn't connect to soap service!"; # call the CheckTextBody method exposed by the web-service my $som = $soap->CheckTextBody( BodyText => $tocheck, LicenseKey => $license); # examine the result returned by the web-service if ($som->fault) { print "REQUEST FAILED!\n\n"; print "Soap Fault ==> ".$som->faultstring."\n"; } else { print "REQUEST SUCCESSFUL!\n\n"; print Dumper($som->paramsall); }
    It just dumps the returned data-structure, so you'll need to have a look at what it contains to figure out what to do next.

    The WSDL formally describes what will be returned in the definition of the DocumentSummary complexType.

    -David

      Thank you David.
      The hardest part to this is getting the SOAP::WSDL installed properly. After that, everything works like a charm.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://651558]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-24 15:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found