//
// 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
//======================================================================================================
// TradeServiceFacadeWcf: The WCF/.NET 3.5 Web Service facade to TradeService.cs.
//======================================================================================================
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Description;
using System.Configuration;
using System.Diagnostics;
using System.Xml;
//using ConfigService.ServiceConfigurationUtility;
using Trade.BusinessServiceConfigurationSettings;
using Trade.BusinessServiceDataContract;
using Trade.BusinessServiceContract;
using Trade.OrderProcessorAsyncClient;
using Trade.Utility;
namespace Trade.BusinessServiceImplementation
{
///
/// This is the service facade implementation for WCF-based Trade Business Services. It defines the business service layer operations
/// that are implemented in the TradeService.cs implementation class.
///
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)]
public class TradeServiceWcf : ITradeServices
{
static int loginCount;
public void emptyMethodAction()
{
return;
}
public String getProfileIdFromStsIdentifier(string uniqueIdentifier, string issuingSts)
{
loginCount++;
if (Settings.DISPLAY_WEBSERVICE_LOGINS && (loginCount % Settings.LOGIN_ITERATIONSTO_DISPLAY == 0))
StockTraderUtility.Logger.WriteDebugMessage("Login request # " + loginCount.ToString() + " received. Login is for user id: " + uniqueIdentifier + "\n");
TradeService service = new TradeService();
return service.getProfileIdFromStsIdentifier(uniqueIdentifier, issuingSts);
}
public AccountDataModel login(string userid, string password)
{
loginCount++;
if (Settings.DISPLAY_WEBSERVICE_LOGINS && (loginCount % Settings.LOGIN_ITERATIONSTO_DISPLAY == 0))
StockTraderUtility.Logger.WriteDebugMessage("Login request # " + loginCount.ToString() + " received. Login is for user id: " + userid + "\n");
TradeService service = new TradeService();
return service.login(InputText(userid, StockTraderUtility.USERID_MAX_LENGTH), InputText(password, StockTraderUtility.PASSWORD_MAX_LENGTH));
}
public List getOrders(string userID)
{
TradeService service = new TradeService();
return service.getOrders(InputText(userID, StockTraderUtility.USERID_MAX_LENGTH));
}
public AccountDataModel getAccountData(string userID)
{
TradeService service = new TradeService();
return service.getAccountData(InputText(userID, StockTraderUtility.USERID_MAX_LENGTH));
}
public AccountProfileDataModel getAccountProfileData(string userID)
{
TradeService service = new TradeService();
return service.getAccountProfileData(InputText(userID, StockTraderUtility.USERID_MAX_LENGTH));
}
public AccountProfileDataModel updateAccountProfile(AccountProfileDataModel profileData)
{
TradeService service = new TradeService();
return service.updateAccountProfile(profileData);
}
public void logout(string userID)
{
TradeService service = new TradeService();
service.logout(InputText(userID, StockTraderUtility.USERID_MAX_LENGTH));
return;
}
//note orderProcessing mode param is not used by StockTrader or IBM Trade 6.1; instead
//both apps pick this up from the application configuration.
public OrderDataModel buy(string userID, string symbol, double quantity, int orderProcessingMode)
{
if (quantity <= 0)
throw new Exception(StockTraderUtility.EXCEPTION_MESSAGE_BAD_ORDER_PARMS);
TradeService service = new TradeService();
return service.buy(InputText(userID, StockTraderUtility.USERID_MAX_LENGTH), InputText(symbol, StockTraderUtility.QUOTESYMBOL_MAX_LENGTH), quantity, orderProcessingMode);
}
//note orderProcessing mode param is not used by StockTrader or IBM Trade 6.1; instead
//both apps pick this up from the application configuration.
public OrderDataModel sell(string userID, int holdingID, int orderProcessingMode)
{
TradeService service = new TradeService();
return service.sell(InputText(userID, StockTraderUtility.USERID_MAX_LENGTH), holdingID, orderProcessingMode);
}
public List getHoldings(string userID)
{
TradeService service = new TradeService();
return service.getHoldings(InputText(userID, StockTraderUtility.USERID_MAX_LENGTH));
}
public AccountDataModel register(string userID, string password, string fullname, string address, string email, string creditcard, decimal openBalance)
{
TradeService service = new TradeService();
return service.register(InputText(userID, StockTraderUtility.USERID_MAX_LENGTH), InputText(password, StockTraderUtility.PASSWORD_MAX_LENGTH), InputText(fullname, StockTraderUtility.FULLNAME_MAX_LENGTH), InputText(address, StockTraderUtility.ADDRESS_MAX_LENGTH), InputText(email, StockTraderUtility.EMAIL_MAX_LENGTH), InputText(creditcard, StockTraderUtility.CREDITCARD_MAX_LENGTH), openBalance);
}
public List getClosedOrders(string userID)
{
TradeService service = new TradeService();
return service.getClosedOrders(InputText(userID, StockTraderUtility.USERID_MAX_LENGTH));
}
public MarketSummaryDataModelWS getMarketSummary()
{
TradeService service = new TradeService();
return service.getMarketSummary();
}
public QuoteDataModel getQuote(string symbol)
{
string _symbol = InputText(symbol, StockTraderUtility.QUOTESYMBOL_MAX_LENGTH);
if (_symbol.Length == 0)
return null;
TradeService service = new TradeService();
return service.getQuote(InputText(symbol, StockTraderUtility.QUOTESYMBOL_MAX_LENGTH));
}
public HoldingDataModel getHolding(string userID, int holdingID)
{
TradeService service = new TradeService();
return service.getHolding(InputText(userID, StockTraderUtility.USERID_MAX_LENGTH), holdingID);
}
public List getTopOrders(string userID)
{
TradeService service = new TradeService();
return service.getTopOrders(InputText(userID, StockTraderUtility.USERID_MAX_LENGTH));
}
public OrderDataModel sellEnhanced(string userID, int holdingID, double quantity)
{
if (quantity <= 0)
throw new Exception(StockTraderUtility.EXCEPTION_MESSAGE_BAD_ORDER_PARMS);
TradeService service = new TradeService();
return service.sellEnhanced(InputText(userID, StockTraderUtility.USERID_MAX_LENGTH), holdingID, quantity);
}
//Used for online check in WCF proxy logic for clients to this service; employed in
//StockTrader load-balanced scenarios to ensure application-level failover of
//service-to-service remote calls to clusters running this service.
public void isOnline()
{
return;
}
private string InputText(string inputString, int maxLength)
{
// check incoming parameters for null or blank string
if ((inputString != null) && (inputString != String.Empty))
{
inputString = inputString.Trim();
//chop the string incase the client-side max length
//fields are bypassed to prevent buffer over-runs
if (inputString.Length > maxLength)
inputString = inputString.Substring(0, maxLength);
}
return inputString;
}
public static void Initialize()
{
TradeOrderServiceAsyncClient.Initialize();
}
}
}