2012-05-18 41 views
0

大家好下面是我想使用的一個WebService類(我寫它)。問題是我不太清楚如何去使用它。我有一個WinForm,通過DataAccessObject的另一個實例連接到數據庫。如何去使用Web服務

用戶必須能夠點擊一個按鈕,該按鈕將打開表單的網站版本並從那裏修改數據庫。

問題是我不知道如何使用這項服務,這樣做

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Services; 
using System.Xml.Linq; 
using System.Configuration; 

/// <summary> 
/// Summary description for DataManager 
/// </summary> 
[WebService(Namespace = "/201103578Site//Default.aspx")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment   the following line. 
//[System.Web.Script.Services.ScriptService] 

public class DataManager : System.Web.Services.WebService 
{ 
    XElement[] xmlCompany = null; 
    XElement[] xmlCandidate = null; 
    XElement[] xmlQualification = null; 

    public DataManager() 
    { 
     //Uncomment the following line if using designed components 
     //InitializeComponent(); 
     DataAccessObject.DataAccessObject daoDataBase = new  DataAccessObject.DataAccessObject(ConfigurationManager.ConnectionStrings[1].ToString()); 
     daoDataBase.openConnection(); 

     xmlCompany = daoDataBase.sqlSelectCompany(new SQL.SqlImplementation(), "Select  * From Company"); 
     xmlCandidate = daoDataBase.sqlSelectCandidate(new SQL.SqlImplementation(),  "Select * From Candidate"); 
     xmlQualification = daoDataBase.sqlSelectQualification(new  SQL.SqlImplementation(), "Select * From Qualification"); 
     daoDataBase.closeConnection(); 
    } 

    [WebMethod] 
    public XElement[] getXmlCompany() 
    { 
     return xmlCompany; 
    } 

    [WebMethod] 
    public XElement[] getXmlCandidate() 
    { 
     return xmlCandidate; 
    } 

    [WebMethod] 
    public XElement[] getXmlQualification() 
    { 
     return xmlQualification; 
    } 

} 

我想打電話給getXmlCompany和任何從Company.aspx.cs其他方法,比如一個文件任何其他方法 - 如果可能的話

親切的問候

馬庫斯

+2

您需要在調試器中啓動Web服務項目,然後轉到耗用它的項目並選擇添加Web引用。 –

回答

1

當您調試Web服務,如果一切是正確的,你會看到你的網頁方法列表。現在,在瀏覽器中複製網址,轉到需要使用它的項目,添加Web引用並通過網址。它將查找並顯示您的webserivice。

此外,你可以考慮在IIS中託管你的web服務,所以你不必每次都運行調試。