// // 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 //====================================================================================================== // This is the client for the OrderProcessorService. //====================================================================================================== //====================================================================================================== // Code originally contributed by Microsoft Corporation. // This contribution to the Stonehenge project is limited strictly // to the source code that is submitted in this submission. // Any technology, including underlying platform technology, // that is referenced or required by the submitted source code // is not a part of the contribution. // For example and not by way of limitation, // any systems/Windows libraries (WPF, WCF, ASP.NET etc.) // required to run the submitted source code is not a part of the contribution //====================================================================================================== using System; using System.Diagnostics; using System.Data; using System.Collections.Generic; using System.Text; using System.ServiceModel; using System.Threading; using System.ServiceModel.Channels; using System.Runtime.Serialization; using System.Globalization; using System.Reflection; using System.Configuration; using Trade.BusinessServiceDataContract; using Trade.OrderProcessorContract; using Trade.BusinessServiceConfigurationSettings; using Trade.Client; using Trade.Utility; namespace Trade.OrderProcessorAsyncClient { /// /// This is the WCF client class for the remote Order Processor Services. This class implements channel initialization and /// load balancing/failover logic across cached channel instances specific to the Configuration Management/Node services /// implemented in StockTrader via the LoadBalancingClient.Client class, now re-used across all clients /// implementing the configuration service. /// public class TradeOrderServiceAsyncClient : IOrderProcessor { public Client.Client opsclient; /// /// This will initialize the correct client/endpoint based on the OrderMode setting the user has set /// in the database BSTOPS table /// /// The order mode, determines what type of binding/remote interface is used for communication. public TradeOrderServiceAsyncClient(string clientConfig, string url) { try { opsclient = new Client.Client(ConfigurationManager.AppSettings.Get(clientConfig), url, Settings.OPS_USERID, Settings.OPS_PASSWORD); } catch { StockTraderUtility.Logger.WriteErrorMessage("TradeOrderServiceAsyncClient Initialization Error: BAD CONFIG"); } } /// /// This returns the base channel type, cast to the specific contract type. /// public IOrderProcessor Channel { get { return opsclient.Channel; } set { opsclient.Channel = value; } } /// /// The online check method. /// public void isOnline() { try { this.Channel.isOnline(); return; } catch { this.Channel = null; throw; } } /// /// Submits an order to a non-transacted queue. /// /// public void SubmitOrder(OrderDataModel order) { try { this.Channel.SubmitOrder(order); return; } catch { this.Channel = null; throw; } } /// /// This method sends an order off to the order processor service, in an async fashion depending on OrderMode setting. /// /// Order to submit. public void processOrderASync(Trade.BusinessServiceDataContract.OrderDataModel order) { try { SubmitOrder(order); } catch (Exception e) { string innerException = null; if (e.InnerException != null) innerException = e.InnerException.ToString(); StockTraderUtility.Logger.WriteErrorMessage(e.ToString() + "\nInner Exception: " + innerException); this.Channel = null; throw; } } /// /// A Static method that clears the cache of the Client Service /// public static void Initialize() { Client.Client.ClearCache(); } } }