July 16, 2008, 10:34 a.m.
posted by angryuser
Using Business LogicTo help not only with versioning, but also with designing a loosely coupled system, try as much as possible to write code that is independent of the actual wire format. Listing 15.4 shows an example that creates a PurchaseOrderHandler class which uses a PurchaseOrder object. However, the service takes a NewPurchaseOrder class that is designed to match the wire format. Changing the Wire Format
public class Service1 : WebService
{
[WebMethod]
public POReceipt SubmitPO(NewPurchaseOrder po)
{
PurchaseOrder purchaseOrder = new PurchaseOrder();
purchaseOrder.Details = po.SomethingInteresting;
POReceipt receipt = new POReceipt();
receipt.ticket = PurchaseOrderHandler.HandleOrder(
purchaseOrder );
return receipt;
}
}
[XmlRoot(
"PurchaseOrder",
Namespace="http://keithba.com/2002/05/PurchaseOrder")]
public class NewPurchaseOrder
{
public String SomethingInteresting;
}
public class PurchaseOrder
{
public String Details;
}
public class POReceipt
{
[XmlAttribute]
public int ticket;
}
public class PurchaseOrderHandler
{
public static int HandleOrder( PurchaseOrder po )
{
//insert real business logic here
}
}
This allows you to deal with changes to wire format that may occur without having to change your core business logic. Instead, the ASP.NET Web Service is a thin shell over the core business logic. |
- Comment