* VFP LOCAL loCryptoService AS "XML Web Service" * LOCAL loCryptoService AS "MSSOAP.SoapClient30" * Do not remove or alter following line. It is used to support IntelliSense for your XML Web service. *__VFPWSDef__: loCryptoService = http://localhost/Crypto/Service1.asmx?wsdl , CryptoService , CryptoServiceSoap LOCAL loException, lcErrorMsg, loWSHandler, lckey TRY loWSHandler = NEWOBJECT("WSHandler",IIF(VERSION(2)=0, "", HOME() + "FFC\") + "_ws3client.vcx") loCryptoService = loWSHandler.SetupClient("http://localhost/Crypto/Service1.asmx?wsdl", "CryptoService", "CryptoServiceSoap") * Call your XML Web service here. ex: leResult = loCryptoService.SomeMethod() lckey = loCryptoService.GenerateKey() CATCH TO loException lcErrorMsg = "Error: " + TRANSFORM(loException.Errorno) + " - " + loException.Message DO CASE CASE VARTYPE(loCryptoService)#"O" * Handle SOAP error connecting to web service CASE NOT EMPTY(loCryptoService.FaultCode) * Handle SOAP error calling method lcErrorMsg = lcErrorMsg + CHR(13) + loCryptoService.Detail OTHERWISE * Handle other error ENDCASE * Use for debugging purposes MESSAGEBOX(lcErrorMsg) FINALLY loCryptoService = NULL loWSHandler = NULL ENDTRY // C# using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; using System.Security; using System.Security.Cryptography; using System.Text; using System.Web; using System.Web.Services; namespace Crypto { /// <summary> /// Return an encrypted string. /// </summary> public class CryptoService : System.Web.Services.WebService { public CryptoService() { //CODEGEN: This call is required by the ASP.NET Web Services Designer InitializeComponent(); } #region Component Designer generated code //Required by the Web Services Designer private IContainer components = null; /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if(disposing && components != null) { components.Dispose(); } base.Dispose(disposing); } #endregion [WebMethod] public string Encrypt(string tsString, string tsKey) { string lsresult = ""; byte[] byt; DESCryptoServiceProvider DES = new DESCryptoServiceProvider(); DES.Key = ASCIIEncoding.ASCII.GetBytes(tsKey); DES.IV = ASCIIEncoding.ASCII.GetBytes(tsKey); ICryptoTransform desencrypt = DES.CreateEncryptor(DES.Key, DES.IV); byt = Encoding.UTF8.GetBytes(tsString); MemoryStream memstream = new MemoryStream(); CryptoStream cryptstream = new CryptoStream(memstream, desencrypt, CryptoStreamMode.Write); cryptstream.Write(byt, 0, byt.Length); cryptstream.FlushFinalBlock(); cryptstream.Close(); lsresult = Convert.ToBase64String(memstream.ToArray()); return lsresult; } // Function to Generate a 64 bits Key. [WebMethod] public string GenerateKey() { // Create an instance of Symetric Algorithm. Key and IV is generated automatically. DESCryptoServiceProvider desCrypto = (DESCryptoServiceProvider)DESCryptoServiceProvider.Create(); // Use the Automatically generated key for Encryption. return ASCIIEncoding.ASCII.GetString(desCrypto.Key); } [WebMethod] public string UnEncrypt(string tsString, string tsKey) { string lsresult = ""; byte[] byt; DESCryptoServiceProvider DES = new DESCryptoServiceProvider(); DES.Key = ASCIIEncoding.ASCII.GetBytes(tsKey); DES.IV = ASCIIEncoding.ASCII.GetBytes(tsKey); ICryptoTransform desencrypt = DES.CreateDecryptor(DES.Key, DES.IV); try { byt = Convert.FromBase64String(tsString); MemoryStream memstream = new MemoryStream(); CryptoStream cryptstream = new CryptoStream(memstream, desencrypt, CryptoStreamMode.Write); cryptstream.Write(byt, 0, byt.Length); cryptstream.FlushFinalBlock(); cryptstream.Close(); lsresult = Encoding.UTF8.GetString(memstream.ToArray()); } catch (Exception e) { lsresult = e.Message; } return lsresult; } } }