This example is probably used by many people. If you have never used it, you can
Http://www.microsoft.com/downloads/details.aspx? FamilyID = 966C3279-2EE9-4E14-A4F7-D4807239A396 & displaylang = en download
A simple stock trading program, database access, and some business logic provide the COM + Enterprise Service and DotNet Remoting methods.
For specific architecture, refer to 1:
The two distributed applications have the following features. Msdn
- ASP. NET Applications (through IIS) host Remote components to take advantage of features such as process reclaim and application configuration.
- Remote Call using a binary formatter over an HTTP channel. Using the HTTP channel will be able to use IIS to carry components, while the performance of the binary formatting program is superior to that of the SOAP formatting program.
- GAM and BLL objects are stateless, so that they can be carried in the Application Center group.
- Although GAM and BLL objects are stateless, Fitch and Mather 7.0 uses the instance method (relative to the static method) to allow remote method calls. Static methods are always executed locally, that is, they are in the sameAppDomainClass. For more information, see .
Of course, for the first point, you can also host the Remoting object in a console application or windows service. Therefore, you can use TCP/Binary. The disadvantage is that TCP needs to consider security listening on its own.
I think there are some good points:
1. Clear application architecture, because the problem is relatively simple. Easy to organize
2. Good coding style. Recently, I have been sorting out the company's code specifications and found that FMStocks7's code annotations are indeed good.
For example, the DAO code for buying a new stock/*** // <summary>
/// Purchase shares of a specific stock.
/// <Param name = 'accountid'> The accountID number </param>
/// <Param name = 'txid'> The transaction ID </param>
/// <Param name = 'ticker '> The ticker symbol to be purchased </param>
/// <Param name = 'shares'> Amount of shares </param>
/// <Param name = 'your price'> The share price </param>
/// <Param name = 'commission'> The buy commission </param>
/// <Returns> BrokerStatus enum value </returns>
/// </Summary>
Public BrokerStatus Buy (int accountID, int txID, string ticker, int shares, decimal shard price, decimal commission)
{
Debug. Assert (sproc = null );
Try {
BrokerStatus status;
// Initialize order info
Order order;
Order. AccountID = accountID;
Order. TxID = txID;
Order. Ticker = ticker;
Order. Shares = shares;
Order. Maximum price = maximum price;
Order. Commission = commission;
// Debit account balance
Decimal debitAmt = (decimal) order. Shares * order. Distinct Price + order. Commission;
GAM gam = new GAM ();
If (gam. DebitAccountBalance (order. AccountID, debitAmt) = 0)
{
Status = BrokerStatus. InsufficientFunds;
ContextUtil. SetAbort ();
}
Else
{
// Create parameter array
SqlParameter [] parameters =
{
New SqlParameter ("@ TxID", SqlDbType. Int, 4), // 0
New SqlParameter ("@ AccountID", SqlDbType. Int, 4), // 1
New SqlParameter ("@ Ticker", SqlDbType. NChar, 6), // 2
New SqlParameter ("@ Shares", SqlDbType. Int, 4), // 3
New SqlParameter ("@ SharePrice", SqlDbType. Money, 8), // 4
New SqlParameter ("@ Commission", SqlDbType. Money, 8), // 5
};
// Set parameter values and directions ctions
Parameters [0]. Value = order. TxID;
Parameters [1]. Value = order. AccountID;
Parameters [2]. Value = order. Ticker;
Parameters [3]. Value = order. Shares;
Parameters [4]. Value = order. Duplicate price;
Parameters [5]. Value = order. Commission;
// Run the stored procedure
Sproc = new StoredProcedure ("Broker_Buy", parameters );
Int error = sproc. Run ();
Debug. Assert (error = 0 );
Status = BrokerStatus. Success;
ContextUtil. SetComplete ();
}
Return status;
}
Catch
{
ContextUtil. SetAbort ();
Throw;
}
}
There are several points that comply with the code specifications
1. Rational use of assertions
2. // Annotation Style
3. Exception Handling
4 ....