王朝网络
分享
 
 
 

Web Service Software Factory 入门

王朝other·作者佚名  2007-06-13
宽屏版  字体: |||超大  

这次主要是通过一个示例基本介绍Web Service Software Factory各个层次的开发

一、建立模板

文件—新建—项目,选择Web Service Software Factory (ASMX)并建立ASMX Service 模板如下图

建立之后我们就能看到由模板帮我们建立的解决方案,分别是业务组件层、数据访问层、服务层以及测试和客户端,这些层次的相关的作用了功能已经在上次中有提到。

二、添加数据库连接

这个很重要,任何的发起都是以它为先决条件的

我们在Service层中右键选择Service Factroy-DataAccess—Add DataBase Connection,在设置向导中建立数据库的连接

这个步骤其实就在web.Config中建立连接字符串

三、添加业务实体类

在CustomerService.BusinessEntities项目中右键选择Service Factroy-DataAccess—Create businessEntities from DataBase,有人可能会想到,难道集成了ORM,其实不然,这个我在后续中会介绍,数据库表直接的数据关系,那它怎么处理呢,其实大家看了就知道了,他也可以将视图生成实体类,从这里我们可以考虑我们可以把数据表直接的关系写在视图中,这样就可以实现关系了

这样他就自动帮我们生成了实体类Customer类

public partial class Customer

{

public Customer()

{

}

public Customer(System.Int32 customerId, System.String firstName, System.String lastName)

{

this.customerIdField = customerId;

this.firstNameField = firstName;

this.lastNameField = lastName;

}

private System.Int32 customerIdField;

public System.Int32 customerId

{

get
{ return this.customerIdField; }

set
{ this.customerIdField = value; }

}

private System.String firstNameField;

public System.String firstName

{

get
{ return this.firstNameField; }

set
{ this.firstNameField = value; }

}

private System.String lastNameField;

public System.String lastName

{

get
{ return this.lastNameField; }

set
{ this.lastNameField = value; }

}

}

四、建立自己的业务逻辑层

因为使用的是这个框架所以我们就把业务逻辑放在CustomerService.BusinessEntities 层中,我们新建一个FinfCustomerAction类

class FindCustomerAction

{

public CustomerList Execute(Customer criteria)

{

CustomerList list = new CustomerList();

list.Add(new Customer(20, "Kim", "Abercrombie"));

list.Add(new Customer(21, "Andy", "Jacobs"));

list.Add(new Customer(22, "Agostino", "Martino"));

list.Add(new Customer(23, "Qiang", "Wang"));

return list;

}

}

五、定义数据类型

就能生成

[System.SerializableAttribute()]

[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://CustomerService.DataTypes/2006/10", IsNullable = false)]

public class Customer

{

private int iD;

private string firstName;

private string lastName;

public int ID

{

get

{

return this.iD;

}

set

{

this.iD = value;

}

}

public string FirstName

{

get

{

return this.firstName;

}

set

{

this.firstName = value;

}

}

public string LastName

{

get

{

return this.lastName;

}

set

{

this.lastName = value;

}

}

}

这个是什么用,我会在下章节中描述

六、定义消息类型

七、建立消息协议

八、建立服务协议解释器

九、在执行服务上添加适配器

using CustomerService.ServiceContracts;

using CustomerService.BusinessLogic;

namespace CustomerService.ServiceImplementation

{

class CustomerManagerAdapter : ICustomerManager

{

ICustomerManager Members#region ICustomerManager Members

/**//// <summary>

/// Implement the FindCustomer operation

/// </summary>

/// <param name="request">Request message contract</param>

/// <returns>Response message contract</returns>

public SearchResponse FindCustomer(SearchRequest request)

{

// translate the data type to a business entity

Translators.TranslateBetweenCustomerAndCustomer translator =

new Translators.TranslateBetweenCustomerAndCustomer();

CustomerService.BusinessEntities.Customer criteria = translator.TranslateCustomerToCustomer(request.Criteria);

// invoke the business action

FindCustomerAction action = new FindCustomerAction();

CustomerService.BusinessEntities.CustomerList customers = action.Execute(criteria);

// translate customer list into a data type

Translators.TranslateBetweenCustomerListAndCustomerList listTranslator =

new Translators.TranslateBetweenCustomerListAndCustomerList();

CustomerService.DataTypes.CustomerList list =

listTranslator.TranslateCustomerListToCustomerList(customers);

// create a response and return it

SearchResponse response = new SearchResponse();

response.Customers = list;

return response;

}

/**//// <summary>

/// Implement the GetCustomer operation

/// </summary>

/// <param name="request">Customer ID</param>

/// <returns>Customer data type</returns>

public CustomerService.DataTypes.Customer GetCustomer(int request)

{

// invoke the business action

GetCustomerAction action = new GetCustomerAction();

CustomerService.BusinessEntities.Customer customer = action.Execute(request);

// translate the business entity into a data type

Translators.TranslateBetweenCustomerAndCustomer translator =

new Translators.TranslateBetweenCustomerAndCustomer();

CustomerService.DataTypes.Customer response = translator.TranslateCustomerToCustomer(customer);

return response;

}

#endregion

}

}

十、发布服务

十一、发布客户端

using (localhost.CustomerManager proxy = new localhost.CustomerManager())

{

localhost.SearchRequest request = new localhost.SearchRequest();

request.Criteria = new localhost.Customer();

request.Criteria.LastName = SearchText.Text;

localhost.SearchResponse response = proxy.FindCustomer(request);

ResultsGrid grid = new ResultsGrid(response.Customers);

grid.ShowDialog(this);

}

十二、总结:

这是关于Web Service Software Factory的一次入门的实例,现在只牵涉到怎样去实现,里面牵涉的内容很多,下次就详细的描述各个层次之间设计的原理。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
>>返回首页<<
推荐阅读
 
 
频道精选
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有