C# vs2010 調用webservice

來源:互聯網
上載者:User

標籤:c# vs2010 webservice函數調用

如何調用已經發布的webservice,主要分為2個步驟(vs2010環境 C#)

  1. 發布webservice,使其處於服務狀態。

  2. 建立一個asp.net程式(java等也可以),對webservice的方法進行調用。


  1. 發布webservice,可以參見

    http://mingsuper.blog.51cto.com/8269088/1439419

  2. 建立asp.net

    1)建立空的asp.net程式

    650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/3E/A1/wKioL1PHgbrSmIo7AAYOD8NqKHM453.jpg" title="2014-07-17_155147.jpg" alt="wKioL1PHgbrSmIo7AAYOD8NqKHM453.jpg" />2)建立測試用的頁面,這裡不過多敘述

    650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/3E/A1/wKiom1PHgOXQFdJ_AAHhrrYw3dM623.jpg" title="2014-07-17_155313.jpg" alt="wKiom1PHgOXQFdJ_AAHhrrYw3dM623.jpg" />3)增加對webservice的web 引用,在工程上點擊右鍵。

    650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/3E/A1/wKiom1PHgYThuWtoAAdlpIH2KJk414.jpg" title="2014-07-17_155431.jpg" alt="wKiom1PHgYThuWtoAAdlpIH2KJk414.jpg" />4)在彈出的對話方塊中輸入webservice的發布路徑,點擊go按鈕。找到後,在下面的對話方塊中為這個引用起命名空間名。(這個名字在後續的操作中會被用到)

    650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/3E/A2/wKiom1PHgf-yq1PoAAH-X5DvUXI858.jpg" title="2014-07-17_155553.jpg" alt="wKiom1PHgf-yq1PoAAH-X5DvUXI858.jpg" />

    5)引入後是這樣的

    650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/3E/A2/wKiom1PHgoixzDDDAAEPU1R_Wtw902.jpg" title="2014-07-17_160032.jpg" alt="wKiom1PHgoixzDDDAAEPU1R_Wtw902.jpg" />

    6)LoginService.wsdl是發布的webservice的描述檔案

    650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/3E/A5/wKiom1PHhCqyEaUyAAIyDKh1Vx0115.jpg" title="2014-07-17_160731.jpg" alt="wKiom1PHhCqyEaUyAAIyDKh1Vx0115.jpg" />7)在asp.net進行調用過程中,直接通過命名空間名找到對應的webservice類,這裡是

    LoginServiceSoapClient(我發布的類名是LoginService 其自己加上了soapclient)。其中LoginServiceRef.UserInfo這個變數很有意思,它本身在asp.net工程中並沒有被定義過,是在webservice的工程中被定義的,但在asp工程裡也可以使用,而且屬性方法都是存在的。

protected void LoginBtn_Click(object sender, EventArgs e)    {        string loginResult;        LoginServiceRef.LoginServiceSoapClient service = new LoginServiceRef.LoginServiceSoapClient();        LoginServiceRef.UserInfo userinfo = new LoginServiceRef.UserInfo();        //UserInfo userInfo = new UserInfo();        userinfo.UserName = UserName.Text;        userinfo.Password = Password.Text;        loginResult = service.CheckLoginUserInfo(userinfo);        LoginResult.Text = loginResult;    }


調用結果

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/3E/A5/wKiom1PHhhqDdKfqAAC7Ho2oQG0861.jpg" style="float:none;" title="2014-07-17_161513.jpg" alt="wKiom1PHhhqDdKfqAAC7Ho2oQG0861.jpg" />

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/3E/A5/wKioL1PHhzOBePxyAAC8hJmMXCw873.jpg" style="float:none;" title="2014-07-17_161527.jpg" alt="wKioL1PHhzOBePxyAAC8hJmMXCw873.jpg" />

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/3E/A5/wKiom1PHhhqwMUS4AAC773CCrso463.jpg" style="float:none;" title="2014-07-17_161541.jpg" alt="wKiom1PHhhqwMUS4AAC773CCrso463.jpg" />


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.