1.環境準備
1.1準備兩個SQL Server,分別部署在局域網內的服務器A,服務器B上;
1.2服務器A,創建接口表SYNC_SPKFK作爲數據源;
說明:id自增量;
is_up爲同步標識,值爲N時,表示未同步;
值爲Y時,表示已同步到服務器B,並且數據同步正確;
值爲E時,表示數據同步時產生錯誤;
uptime爲同步時間,由同步工具進行回寫;
1.3服務器B,創建接口表SYNC_SPKFK作爲接收表;
uptime爲插入時默認值;
2.製作WebService
接口代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.Services;
namespace MyWebService
{
/// <summary>
/// WebService1 的摘要說明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允許使用 ASP.NET AJAX 從腳本中調用此 Web 服務,請取消註釋以下行。
// [System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod(Description = "商品資料單個提交")]
public bool OneSyncSPZL(int id,string yzid,string hzid,string spid,string spbh,string spmch,string shpgg,string shengccj,int jlgg,string dw) {
try
{
bool ret = false;
ret = SaveSyncSPZL.SaveData(id,yzid,hzid,spid,spbh,spmch,shpgg,shengccj,jlgg,dw);
return ret;
}
catch (Exception ex)
{
return false;
throw (ex);
}
}
[WebMethod(Description = "商品資料批量提交")]
public bool AddSPLIST(DataSet ds)
{
try
{
bool ret = false;
ret = AddSaveSPList.SaveData(ds);
return ret;
}
catch (Exception ex)
{
return false;
}
}
}
}
把WebService發佈,並部署到服務器B的IIS上
訪問測試
WebService源碼請到此處下載;
3.製作數據提交工具
界面如下:
功能說明:
1.查詢得到服務器A中,IS_UP爲N的TOP 100條數據;
2.點單個上傳,測試OneSyncSPZL接口,上傳成功後,回寫IS_UP爲Y,並回寫UPTIME,並刷新數據,上傳錯誤,回寫IS_UP爲E,並回寫UPTIME;
3.點批量上傳,測試 AddSPLIST接口,上傳成功後,回寫IS_UP爲Y,並回寫UPTIME,並刷新數據,上傳錯誤,回寫IS_UP爲E,並回寫UPTIME;此時以DataSet中作爲變量上傳,一次100條數據;
數據提交工具源碼請到此處下載;
4.結果
服務器A SYNC_SPKFK數據
單個上傳
服務器A SYNC_SPKFK 回寫情況
服務器B SYNC_SPKFK插入情況
批量上傳
刷新數據
服務器A插入情況
服務器B插入情況