1.开发人员创建一个名为 XBikes-BLL-WSServiceInterface 的新 ASP.NET Web 服务项目。
2.他们删除默认的 Service1.asmx 文件并将其替换为名为 BLLWSServiceInterface.asmx 的新 Web 服务。开发人员用如下的 [WebService] 属性来批注该 Web 服务类。
[WebService(Namespace="http://XBikes.com/BLLWSServiceInterace/")] public class BLLWSServiceInterface : System.Web.Services.WebService { // Members... } 3.该团队将 Web 服务方法添加到 Web 服务类,由现有的业务服务外观公开的每种方法都具有正确的方法签名。但是,开发人员将数据类型更改为“字符串”,而不是每种方法将数据集作为参数接受或返回。
[WebService(Namespace="http://XBikes.com/BLLWSServiceInterace/")] public class BLLWSServiceInterface : System.Web.Services.WebService { [WebMethod] public string AuthenticateCustomer(string email, string passWord) {} [WebMethod] public string GetCategories() {} [WebMethod] public string GetPRodUCtsByCategory(int CategoryID) {} [WebMethod] public string GetSearchResults(string keyword) {} [WebMethod] public void PlaceOrder(string order) {} [WebMethod] public string GetCustomerOrders(int customerID) {} } 4.该团队将代码添加到每种 Web 服务方法以调用业务服务外观方法。以下代码示例显示了如何对 Web 服务服务接口中的 GetCategories 方法执行操作。开发人员调用自业务服务外观返回的 CategoriesData 对象的 Getxml 方法,从而将数据转换成 XML 格式化字符串,WS 服务接口将该字符串返回其调用方。
[WebMethod] public string GetCategories() { try { // Create a business service facade (BSF) object BusinessServiceFacade bsf = new BusinessServiceFacade(); // Call the GetCategories method on the BSF object CategoriesData cd = bsf.GetCategories(); // Convert the CategoriesData dataset into XML, and return it return cd.GetXml(); } catch (XBikesInteropException intEXP) { //.. Error handling code } } 5.根据 WS-I Basic Profile 1.0,Web 服务应该支持 SOAP 协议,但不支持 HTTPGet 或者 HTTPPost 协议。为了从 Web 服务中移除协议支持,XBikes 开发人员将以下代码添加到 Web 服务的 Web.config 文件的 部分。
为了测试 Web 服务,开发人员在 Visual?Studio .NET 2003 中建立并运行 Web 服务项目。运行 ASP.NET Web 服务项目时,在浏览器中会自动出现一张测试页。这张测试页包含答应调用每种 Web 服务方法的超级链接。假如必要,该测试页还有供您输入值的文本框。在调用完一个 Web 服务方法后,另一个浏览器窗口会打开显示来自 Web 服务方法的 XML 响应。