// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to You under the Apache License, Version 2.0 // (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // .NET StockTrader Sample WCF Application for Benchmarking, Performance Analysis and Design Considerations for Service-Oriented Applications using System; using System.Web.Security; using System.Web.UI; using Trade.BusinessServiceClient; using Trade.StockTraderWebApplicationModelClasses; using Trade.StockTraderWebApplicationSettings; using Trade.Utility; namespace Trade.Web { /// /// Registers a new user, performs login/authentication via Business Services. /// public partial class Register : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { submitData(); } } private void submitData() { Page.Validate(); if (Page.IsValid) { RegisterMessage.ForeColor = System.Drawing.Color.Red; string fullName = Input.InputText(this.FullName.Text, StockTraderUtility.FULLNAME_MAX_LENGTH); string address = Input.InputText(this.Address.Text, StockTraderUtility.ADDRESS_MAX_LENGTH); string emailAddress = Input.InputText(this.Email.Text, StockTraderUtility.EMAIL_MAX_LENGTH); string creditCard = Input.InputText(this.CreditCard.Text, StockTraderUtility.CREDITCARD_MAX_LENGTH); string userID = Input.InputText(this.UserID.Text, StockTraderUtility.USERID_MAX_LENGTH); string password = Input.InputText(this.Password.Text, StockTraderUtility.PASSWORD_MAX_LENGTH); decimal openBalance = Decimal.Parse(Input.InputText(this.OpenBalance.Text, StockTraderUtility.OPENBALANCE_MAX_LENGTH)); AccountDataUI customer = null; try { BSLClient businessServicesClient = new BSLClient(); customer = businessServicesClient.register(userID, password, fullName, address, emailAddress, creditCard, openBalance); } catch (Exception e) { //Depending on web.config user setting just catch the duplicate key exception and display a //user-friendly message, or throw a 500 back to browser to make it easy to catch //this error from benchmark scripts. You can mark DisplayDuplicateKeyExceptions true/false //in Web.Config for this setting. if ((e.Message.Contains(StockTraderUtility.EXCEPTION_DOTNET_DUPLICATE_PRIMARY_KEY) || e.Message.ToLower().Contains(StockTraderUtility.EXCEPTION_WEBSPHERE_DUPLICATE_PRIMARY_KEY.ToLower())) && !Settings.DISPLAY_DUPLICATE_KEY_EXCEPTIONS) { RegisterMessage.Text = StockTraderUtility.EXCEPTION_MESSAGE_DUPLICATE_PRIMARY_KEY; return; } else throw; } FormsAuthentication.SetAuthCookie(customer.profileID, false); Response.Redirect(Settings.PAGE_HOME, true); } } } }