版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、.NET WebService的創(chuàng)建、部署、運用 項目要求:(簡單點講) 1、客戶端通過web站點上傳XML,XML文件在web站點首先解析成DataSet,所以上傳給WebService只是DataSet,你也可以上傳XML文件到WebService服務(wù)器,這里以前者為例。 2、WebService接收客戶端傳來的DataSet,將DataSet插入到數(shù)據(jù)庫。 3、客戶端查詢,通過web引用,查詢結(jié)果返回客戶端。 -最先要解決的問題是你要閱讀和了解WebService相關(guān)的知識-第一步:創(chuàng)建你的webservice,打開VS2005-新建網(wǎng)站-Asp.Net Web服務(wù)-確定第二步:網(wǎng)站自動
2、給你生成了一個asmx文件-現(xiàn)在你就可以運行這個簡單的webservice,之后你就可以看到那個Hello World。第一步:創(chuàng)建你的WebSite,就是站點/當(dāng)然開發(fā)前,你可以先不新建站點,我就直接在webservice本地操作,我覺得這樣比較好。1:【上傳功能】第一步:在你的web站點拖入一個上傳控件FileUpload,這個控件的作用就是選擇本地的xml文件,在本地轉(zhuǎn)化為dataset,你要傳給webservice的是dataset。具體代碼如下:/=客戶端上傳Xml文件= protected void btnUpload_Click(object send
3、er, EventArgs e) /fullfileName獲得全路徑 string fullfileName = this.fileUpload.PostedFile.FileName; /獲得文件名 fileName = fullfileName.Substring(fullfileName.LastIndexOf() + 1); /文件類型 string fileType = fullfileName.Substring(fullfileName.LastIndexOf(.) + 1); if (this.fileUpload.PostedFile.FileName != null) i
4、f (fileType.ToLower() = xml) DataSet ds = new DataSet(); ds.ReadXml(fullfileName);/調(diào)用webService中的方法. myService.getXml(ds); /成功后提示,代碼省略 else /失敗后提示,代碼省略 else this.lblMessage.Text = 請選擇你要上傳的文件,謝謝!; 你在站點上上傳了一個dataset,所以webservice就要有一個方法來接收它,代碼如下:/=上傳XML文件= WebMethod public bool getXml(DataSet dataSet)
5、/public DataSet getXml(DataSet dataSet) /連接數(shù)據(jù)庫,這里面隨你怎么連接數(shù)據(jù)庫,只要能連上就可以了。DB db = new DB(); SqlConnection con = db.sqlCon(); con.Open(); DataSet c_dataSet = new DataSet(); /將用戶傳過來的dataSet賦值給c_dataSet. c_dataSet = dataSet; /這里調(diào)用了存儲過程./讀者只要將sp_MVP改為select * from MVP,其它的照例,不用存儲管理的話把藍色那行都刪掉. SqlDataAdapter
6、sda = new SqlDataAdapter(sp_MVP,con);sda.SelectCommand.CommandType = CommandType.StoredProcedure; SqlCommandBuilder mysqlcommand = new SqlCommandBuilder(sda); sda.Update(c_dataSet, MVP); SqlDataAdapter sda1 = new SqlDataAdapter(sp_OtherCompetencies, con);sda1.SelectCommand.CommandType = CommandType.
7、StoredProcedure; SqlCommandBuilder mysqlcommand1 = new SqlCommandBuilder(sda1); sda1.Update(c_dataSet, OtherCompetencies); SqlDataAdapter sda2 = new SqlDataAdapter(sp_OtherCompetency, con);sda2.SelectCommand.CommandType = CommandType.StoredProcedure; SqlCommandBuilder mysqlcommand2 = new SqlCommandB
8、uilder(sda2); sda2.Update(c_dataSet, OtherCompetency); SqlDataAdapter sda3 = new SqlDataAdapter(sp_Publications, con);sda3.SelectCommand.CommandType = CommandType.StoredProcedure; SqlCommandBuilder mysqlcommand3 = new SqlCommandBuilder(sda3); sda3.Update(c_dataSet, Publications); SqlDataAdapter sda4
9、 = new SqlDataAdapter(sp_Publication, con);sda4.SelectCommand.CommandType = CommandType.StoredProcedure; SqlCommandBuilder mysqlcommand4 = new SqlCommandBuilder(sda4); sda4.Update(c_dataSet, Publication); /處理所以的請求(更新). c_dataSet.AcceptChanges(); con.Close(); return true; 首先要在webservice服務(wù)器建立數(shù)據(jù)庫,有五張表M
10、VP,OtherCompetencies.這里webservice要連接數(shù)據(jù)庫了,這里是連接sql2005,o(_)o.哈哈,我相信這里連接數(shù)據(jù)庫會讓你很郁悶的,實在沒轍了來找我,_現(xiàn)在就可以試試效果了!當(dāng)然不可以一下就能成功,多調(diào)試!2:查詢功能查詢是在webservice里面實現(xiàn)的,代碼如下: /=用戶查詢= WebMethod /public DataSet searchData(string mvpguid,string fristname,string lastname) public DataSet searchData(string mvpguid) /連接數(shù)據(jù)庫 DB data
11、Base = new DB(); SqlConnection con = dataBase.sqlCon(); con.Open(); /用戶查詢得到的將是myDataSet. DataSet myDataSet = new DataSet(); try SqlDataAdapter myAdapter = new SqlDataAdapter(); if (mvpguid != ) /按照用戶輸入的mvpguid進行查詢. myAdapter.SelectCommand = new SqlCommand(select * from MVP where MVPGUID=+mvpguid+, c
12、on); SqlCommandBuilder myCB = new SqlCommandBuilder(myAdapter); myAdapter.Fill(myDataSet, MVP); /建立表間關(guān)系. SqlDataAdapter myAdapter1 = new SqlDataAdapter(select OtherCompetencies.OtherCompetencies_Id,OtherCompetencies.MVP_Id from MVP,OtherCompetencies where MVP.MVP_Id=OtherCompetencies.MVP_Id and MVP.
13、MVPGUID= + mvpguid + , con); SqlCommandBuilder myCB1 = new SqlCommandBuilder(myAdapter1); myAdapter1.Fill(myDataSet, OtherCompetencies); SqlDataAdapter myAdapter2 = new SqlDataAdapter(select OtherCompetency.OtherCompetencies_Id,OtherCompetency.OtherCompetency_Text from MVP,OtherCompetencies,OtherCom
14、petency where MVP.MVP_Id=OtherCompetencies.MVP_Id and OtherCompetencies.OtherCompetencies_Id=OtherCompetency.OtherCompetencies_Id and MVP.MVPGUID= + mvpguid + , con); SqlCommandBuilder myCB2 = new SqlCommandBuilder(myAdapter2); myAdapter2.Fill(myDataSet, OtherCompetency); SqlDataAdapter myAdapter3 =
15、 new SqlDataAdapter(select Publications.Publications_Id,Publications.MVP_Id from Publications,MVP where MVP.MVP_Id=Publications.MVP_Id and MVP.MVPGUID= + mvpguid + , con); SqlCommandBuilder myCB3 = new SqlCommandBuilder(myAdapter3); myAdapter3.Fill(myDataSet, Publications); SqlDataAdapter myAdapter4
16、 = new SqlDataAdapter(select Publication.Publications_Id,Publication.Id,Publication.Title,Publication.Publisher,Publication.DatePublished,Publication.Abstract,Publication.UrlLink from MVP,Publications,Publication where MVP.MVP_Id=Publications.MVP_Id and Publications.Publications_Id=Publication.Publi
17、cations_Id and MVP.MVPGUID= + mvpguid + , con); SqlCommandBuilder myCB4 = new SqlCommandBuilder(myAdapter4); myAdapter4.Fill(myDataSet, Publication); /Create DataRelation, and add it to the DataSet. DataRelation dr = new DataRelation(MVPToOtherCompetencies, myDataSet.TablesMVP.ColumnsMVP_Id, myDataS
18、et.TablesOtherCompetencies.ColumnsMVP_Id); DataRelation dr1 = new DataRelation(OtherCompetenciesToOtherCompetency, myDataSet.TablesOtherCompetencies.ColumnsOtherCompetencies_Id, myDataSet.TablesOtherCompetency.ColumnsOtherCompetencies_Id); DataRelation dr2 = new DataRelation(MVPToPublications, myDat
19、aSet.TablesMVP.ColumnsMVP_Id, myDataSet.TablesPublications.ColumnsMVP_Id); DataRelation dr3 = new DataRelation(PublicationsToPublication, myDataSet.TablesPublications.ColumnsPublications_Id, myDataSet.TablesPublication.ColumnsPublications_Id); /獲取或設(shè)置一個指示DataRelation對象是否嵌套的值. dr.Nested = true; dr1.Ne
20、sted = true; dr2.Nested = true; dr3.Nested = true; /創(chuàng)建關(guān)系到集合中 myDataSet.Relations.Add(dr); myDataSet.Relations.Add(dr1); myDataSet.Relations.Add(dr2); myDataSet.Relations.Add(dr3); catch (SqlException exception) return DataError(exception); return myDataSet; /=錯誤信息= public DataSet DataError(Exception
21、 ex) DataSet errDS = new DataSet(Errors); DataTable errTable = errDS.Tables.Add(Error); errTable.Columns.Add(Message); errTable.Rows.Add(new Object ex.Message ); return errDS; 代碼有點多,呵呵,然后你在客戶端只要引用它的接口就可以了,這樣會更好理解一點,代碼如下:/=客戶端查詢函數(shù)= protected void btnSearch_Click1(object sender, EventArgs e) string c_mvpGuid = ;try c_mvpGuid = this.txtByMV
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 中國嘧啶核苷行業(yè)市場前景預(yù)測及投資價值評估分析報告
- 2026年1月24日山東省選調(diào)生面試真題及答案解析(下午卷)
- 2026年生物基可降解塑料項目投資計劃書
- 牛羊販運人員培訓(xùn)課件教學(xué)
- 環(huán)境局公文寫作培訓(xùn)課件
- 小學(xué)科學(xué)教師的個人年度工作總結(jié)
- 社區(qū)就業(yè)與再就業(yè)年度工作總結(jié)
- 2025年國家公務(wù)員錄用考試公共基礎(chǔ)知識全真模擬題庫及答案
- 2025年全國高壓電工作業(yè)人員操作證考試題庫(含答案)
- 土方工程三級安全教育試題(附答案)
- 收購商場協(xié)議書范本
- 2025年榆林神木市信息產(chǎn)業(yè)發(fā)展集團招聘備考題庫(35人)及答案詳解(新)
- 2025年公務(wù)員時事政治熱點試題解析+答案
- 免疫聯(lián)合治療的生物樣本庫建設(shè)
- 項目管理溝通矩陣及問題跟進器
- 交通運輸企業(yè)人力資源管理中存在的問題及對策
- 蒂森電梯安全質(zhì)量培訓(xùn)
- 設(shè)備供貨進度計劃及保證措施
- 純化水取樣課件
- 2025年四川單招護理試題及答案
- 鋼梁現(xiàn)場安裝施工質(zhì)量通病、原因分析及應(yīng)對措施
評論
0/150
提交評論