清风乱谈 之 基于WCF的电子商务解决方案(一)

首先,先用这个图片来说明我上次提到的多个组件服务器与WEB服务器之间的关系

 

这么做至少有3个明显的好处:

1.         将站点的压力平均化,提高网站的浏览速度,降低服务器压力。

2.         保证各个应用组件之间逻辑的绝对分离,实现了我们说的低耦合。

3.         应用服务器的接口可以多次复用,企业可以通过重新组合应用服务器接口建立统一的电子商务体系。

 

 

该程序在VS2008下的结构如下:

 

其中Orders对应着 订单管理组件服务系统”,Products对应着“产品目录管理组件服务系统”,Marketing对应着“市场营销及促销组件服务系统”,多个组件可以以IIS为宿主分别架设在多台服务器上。

 

 

这里是IIS宿主站点的配置:

 

 

以下为WEB服务器对组件服务器接口的调用方法:

public void UpdateQuantity(Guid productID, int quantity)

        {

            //此处为对产品目录管理组件服务系统中提供的Product GetProductByID(Guid productID);接口的调用

            Product product = ServiceLoader.LoadService<IProduct>().GetProduct(productID);

            if (product.Inventory < quantity)

            {

                throw new BusinessException("Lack of inventory.");

            }

            OrderDetail detail = this.Order.Details.Where(item => item.ProductID == productID).ToArray<OrderDetail>()[0];

            detail.Quantity = quantity;

            this.View.BindingOrderInfo(this.Order);

        }

 

 

 

这段为接口调用在WEB.CONFIG文件里面的相关配置代码

<client>

              <endpoint address="http://localhost/PetShop/Products/productservice.svc" behaviorConfiguration="petShopBehavior" binding="ws2007HttpBinding"  contract="Artech.PetShop.Products.Service.Interface.IProductService" name="productservice"/>

              <endpoint address="http://localhost/PetShop/Infrastructures/MembershipService.svc" behaviorConfiguration="petShopBehavior" binding="ws2007HttpBinding"  contract="Artech.PetShop.Infrastructures.Service.Interface.IMembershipService" name="membershipservice"/>

              <endpoint address="http://localhost/PetShop/Orders/OrderService.svc" behaviorConfiguration="petShopBehavior" binding="ws2007HttpBinding"  contract="Artech.PetShop.Orders.Service.Interface.IOrderService" name="orderservice"/>

         </client>

 

 

本次文章重点在把我昨天提出的理论找出一些实际的例子进行演示说明,这个码字和说话毕竟是有点区别的,希望大家可以理解~

 

 

以上代码参考了Artech大神提供的PETSHOP网店例子,如果冒犯,还望Artech大大不要打我,呵呵~

 

posted on 2010-05-09 16:50  吕鑫  阅读(1867)  评论(10编辑  收藏  举报

导航