using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.ServiceModel; using System.Web; using System.Web.Script.Serialization; using System.Web.UI; using System.Web.UI.WebControls; namespace HL7SoupWebsite { public partial class IntegrationHostTrial : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { YouDescriptionDropDown.Items.Insert(0, new ListItem("Please Select a Description", "Please Select a Description")); PrimaryReasonDropDown.Items.Insert(0, new ListItem("Please Select a Reason", "Please Select a Reason")); } } protected void Button1_Click(object sender, EventArgs e) { //if (!Page.IsValid) //{ // // LabelRecaptcha.Visible = true ; // return; //} LabelRecaptcha.Visible = false; YouDescriptionRequiredLabel.Visible = false; PrimaryReasonRequiredLabel.Visible = false; if (YouDescriptionDropDown.SelectedIndex == 0) { YouDescriptionRequiredLabel.Visible = true; } if (PrimaryReasonDropDown.SelectedIndex == 0) { PrimaryReasonRequiredLabel.Visible = true; } if (YouDescriptionDropDown.SelectedIndex == 0 || PrimaryReasonDropDown.SelectedIndex == 0) { return; } if (!ValidateRecaptcha()) { LabelRecaptcha.Visible = true; return; } try { string phone = PhoneTextBox.Text; string country = "UnknownTrial"; string city = "UnknownTrial"; CreateLicense(FirstNameTextBox.Text, LastNameTextBox.Text, EmailTextBox.Text, phone, CompanyTextBox.Text, country, city, YouDescriptionDropDown.SelectedValue, PrimaryReasonDropDown.SelectedValue, 1); EmailAddressSentToLabel.Text = EmailTextBox.Text; Panel1.Visible = false; Panel2.Visible = true; } catch (Exception ex) { errorLabel.Text = "An error occured logging inquiry: " + ex.ToString(); } } public static void CreateLicense(string FirstName, string LastName, string Email, string phone, string Company,string country, string city, string UserDescription, string Reason, int instructions) { //Get license emailing out BasicHttpBinding binding = new BasicHttpBinding(); //********************************************************************* //Comment out the mode below that you don't want... //Release mode: Calls hosted license server via ssl binding.Security.Mode = BasicHttpSecurityMode.Transport; Uri baseAddress = new Uri("https://HL7Soup.com/SoupLicenseService/LicenseService.svc"); //Debug mode: Calls local license server via http //Uri baseAddress = new Uri("http://localhost:63930/LicenseService.svc"); //********************************************************************* EndpointAddress endpointAddress = new EndpointAddress(baseAddress); LicenseService.LicenseServiceClient licenseService = new LicenseService.LicenseServiceClient(binding, endpointAddress); licenseService.GetTrialWorkflowLicense3(FirstName, LastName, Email, phone, Company, country, city, Guid.Empty, "52615b24-d668-4774-94bf-58105515b674", UserDescription, Reason, instructions); } public bool ValidateRecaptcha() { string Response = Request["g-recaptcha-response"];//Getting Response String Append to Post Method bool Valid = false; //Request to Google Server HttpWebRequest req = (HttpWebRequest)WebRequest.Create (" https://www.google.com/recaptcha/api/siteverify?secret=6LfR4_kSAAAAAMgsWSIsEEtgS_cXDCAeueojvP7B&response=" + Response); try { //Google recaptcha Response using (WebResponse wResponse = req.GetResponse()) { using (StreamReader readStream = new StreamReader(wResponse.GetResponseStream())) { string jsonResponse = readStream.ReadToEnd(); JavaScriptSerializer js = new JavaScriptSerializer(); MyObject data = js.Deserialize(jsonResponse);// Deserialize Json Valid = Convert.ToBoolean(data.success); } } return Valid; } catch (WebException ex) { throw ex; } } public class MyObject { public string success { get; set; } } protected string GetIPAddress() { System.Web.HttpContext context = System.Web.HttpContext.Current; string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (!string.IsNullOrEmpty(ipAddress)) { string[] addresses = ipAddress.Split(','); if (addresses.Length != 0) { return addresses[0]; } } return context.Request.ServerVariables["REMOTE_ADDR"]; } } }