技术开发 频道

利用WebService技术实现远程数据库存取


【IT168技术文档】

  随着微软Visual Studo.Net Beta版的发布,由于Visual Studio.Net对XML以及Web服务的强大支持,利用Visual Studio.Net开发Web服务应用将会越来越多而且是非常的方便。本文以一个B2B电子商务网站为例,介绍利用web服务在不同站点间共享同一数据库的具体方法和步骤。本文中,客户端是指使用web服务的一方,服务器端是指提供web服务的另一方。

  问题的提出

  该网站是一家(简称A)从事网上销售手机SIM卡的业务的电子商务网站。前不久,该网站与另一家网站(简称B)合作,共同开展网上销售联通手机SIM卡业务。由于都是使用的A网站的号码资源,存取的都是A网站的数据库,于是笔者利用webservice技术为另一家网站开发了网上售卡系统。

  各主要功能的模块和关键代码

  1. 数据库采用SQL SERVER2000,使用存储过程实现号码浏览的分页显示。代码如下:
create procedure fenye ( @pagenow int, @pagesize int, @cityid int, @code char(3), @recordcount int output ) as set nocount on declare @allid int,@beginid int,@endid int,@pagebegin char(11),@pageend char(11) select @allid=count(*) from jinan where cityid=@cityid and (code like @code+'%') select @recordcount=@allid declare cur_fastread cursor scroll for SELECT code FROM jinan where cityid=@cityid and (code like @code+'%') order by code open cur_fastread select @beginid=(@pagenow-1)*@pagesize+1 select @endid=@beginid+@pagesize-1 fetch absolute @beginid from cur_fastread into @pagebegin if @endid>@allid fetch last from cur_fastread into @pageend else fetch absolute @endid from cur_fastread into @pageend set nocount off select code,cost,status from jinan join xuanhaofei on jinan.category=xuanhaofei.category and jinan.cityid=xuanhaofei.cityid where code between @pagebegin and @pageend order by code close cur_fastread deallocate cur_fastread GO
0
相关文章