
Ajax for Business Logic
Sunday, February 19, 2006
I created a JavaScript Wrapper for my C# Business Logic classes. You specify which dll to "wrap" and the wrapper spits out javascript.
The result is that you can write near-C# language in JavaScript! I have all the public classes, constructors, public constants, public methods and public properties available client side in javascript.
The methods and constructors are just "empty" functions that check if the correct number of parameters are specified and then perform a synchronous web service call. The web service then invokes the constructor or method and returns the resulting value.
This means that you don't need to write hundreds of web services and web service methods when you need to interact with the business entities and business logic.
In respect to security the wrapper only wraps public classes and namespaces. And furthermore it checks that a [Wrap] attribute is present.
For even more security WSE provides a mechanism to digitally sign SOAP messages.
Examples:
Creating an instance of Business.Logic.ContractSale
using the constructor that takes an id as parameter, invoking Validate()
and Accept(DateTime oDateAccepted)
on the instance.
var oContractSale = new Business.Logic.ContractSale(iCSal_Id); if (oContractSale.Validate()) { oContractSale.Accept(new Date()); } else { alert("Sales contract is not valid!"); }
Creating a new instance of Business.Logic.InvoiceSale
setting properties and invoking method Save()
on the instance.
var oInvoiceSale = new Business.Logic.InvoiceSale(); oInvoiceSale.DateInvoice = new Date(); oInvoiceSale.Amount = 150; oInvoiceSale.Currency = Business.Logic.Currency.USD; oInvoiceSale.Save();