private void submitReq() { #region Initialization double initial = (double)rngInitial.Value2; double exercise = (double)rngInitial.Value2; double up = (double)rngUp.Value2; double down = (double)rngDown.Value2; double interest = (double)rngInterest.Value2; int periods = Convert.ToInt32(rngPeriods.Value2); int runs = Convert.ToInt32(rngRuns.Value2); double interestStart = (double)rngInterestStart.Value2; double interestEnd = (double)rngInterestEnd.Value2; double interestStep = (double)rngStep.Value2; #endregion #region fire request SessionStartInfo info = new SessionStartInfo(Config.headNode, "AsianOptionsService"); info.Secure = false; info.BrokerSettings.SessionIdleTimeout = 12 * 60 * 60; // 12 hours DurableSession.SetInterfaceMode(false, IntPtr.Zero); //set interface mode to non console using (DurableSession session = DurableSession.CreateSession(info)) { this.Range["C20", missing].Value2 = "Session Created. SessionId"; this.Range["D20", missing].Value2 = session.Id; Thread.Sleep(1000); this.Range["C21", missing].Value2 = " Sending Req..."; NetTcpBinding binding; binding = new NetTcpBinding(SecurityMode.None); using (BrokerClient <IService1> client = new BrokerClient <IService1>(session, binding)) { int count = 0; int reqCount = 0; for (double interestIdx = interestStart; interestIdx < interestEnd; interestIdx += interestStep, count++) { this.Range["C21", missing].Value2 = string.Format("Sending Req Batch {0}", count); bool batch_succeed = false; int batch_retrycount = 0; while (!batch_succeed && batch_retrycount < 3) { for (int j = 0; j < cols.Length; j++) { string col = cols[j]; for (int i = 2; i <= 11; i++) { PriceAsianOptionsRequest priceRequest = new PriceAsianOptionsRequest(initial, exercise, up, down, interestIdx, periods, runs); cellContext ctx = new cellContext(); ctx.range = string.Format("{0}{1}", col, i); ctx.iteration = count; bool i_succeed = false; int i_retrycount = 0; while (!i_succeed && i_retrycount < 3) { try { client.SendRequest <PriceAsianOptionsRequest>(priceRequest, ctx); i_succeed = true; this.Range["D21", missing].Value2 = string.Format("{0} Req sent.", ++reqCount); } catch (Exception) { // Populate the cell with an error message this.Range[ctx.range, missing].Value2 = "#SendErr#"; i_retrycount++; } } if (!i_succeed) { this.Range["C22", missing].Value2 = "Session failed."; this.Range["D20", missing].Clear(); session.Close(); return; } } } try { client.Flush(); this.Range["C22", missing].Value2 = string.Format("Req Batch {0} Flushed.", count); batch_succeed = true; } catch (Exception) { // Populate the cell with an error message this.Range["C22", missing].Value2 = "ClientFlush failed."; batch_retrycount++; } if (!batch_succeed) { this.Range["C22", missing].Value2 = "Session failed."; this.Range["D20", missing].Clear(); session.Close(); return; } } } client.EndRequests(); this.Range["C21", missing].Value2 = "Closing."; } } this.Range["C21", missing].Value2 = "Request sent."; this.Range["C22", missing].Value2 = "Request flushed."; #endregion }