Cecil
19+ years progress programming and still learning.
Hi all.
We where having a problem where our members where entering their email address which they thought to be correct but we had no way to check. Web Services to the rescue.
I've created a simple Web Services Client which will consume a free service to verify an email address.
This code does need internet access for it to work. Also because it's free it comes with NO support and I would like to think that the email addresses are not used for spam.
We where having a problem where our members where entering their email address which they thought to be correct but we had no way to check. Web Services to the rescue.
I've created a simple Web Services Client which will consume a free service to verify an email address.
This code does need internet access for it to work. Also because it's free it comes with NO support and I would like to think that the email addresses are not used for spam.
Code:
/** EMAIL VALIDATION **/
DEFINE VARIABLE hWebService AS HANDLE NO-UNDO.
DEFINE VARIABLE hValidateEmailSoap AS HANDLE NO-UNDO LABEL 'Email Valid'.
DEFINE VARIABLE chEmailAddress AS CHARACTER NO-UNDO LABEL 'Email Address' FORMAT "x(45)".
CREATE SERVER hWebService.
hWebService:CONNECT("-WSDL 'http://www.webservicex.net/ValidateEmail.asmx?WSDL'").
RUN ValidateEmailSoap SET hValidateEmailSoap ON hWebService.
DEFINE VARIABLE lgValidEmail AS LOGICAL NO-UNDO.
FUNCTION IsValidEmail RETURNS LOGICAL
(INPUT Email AS CHARACTER)
IN hValidateEmailSoap.
MAIN-BLOCK:
DO ON ERROR UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK
ON QUIT UNDO main-BLOCK, LEAVE MAIN-BLOCK
ON STOP UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK:
IF VALID-HANDLE(hWebService) AND
VALID-HANDLE(hValidateEmailSoap) AND
hWebService:CONNECTED() THEN
DO:
UPDATE chEmailAddress.
ASSIGN
lgValidEmail = IsValidEmail(INPUT chEmailAddress ).
DISPLAY chEmailAddress lgValidEmail.
END.
END.
DELETE PROCEDURE hValidateEmailSoap.
IF hWebService:CONNECTED() THEN
hWebService:DISCONNECT().
DELETE OBJECT hWebService.