webservice:
webservice是一種程式介面,提供資料。可以用java,c#等語言開發。同時調用也可以用多種語言。
即C#可以調用java 寫的介面,java也可以調用C#寫的介面,總之就是為了分工,安全,方便。
現在使用C#語言調用一個現成的寫好的webservice。
步驟:
首先,以本地 webservice為例
項目右鍵 添加web引用,瀏覽本地,找到如同http://localhost/EnglishChinese.asmx?wsdl (若是遠程介面,只需要更改此URL即可)
找到後 可以查看裡面的方法,說明webservice沒有問題
然後 記得webservice的 引用名稱 自己可以更改的
最後 就是調用裡面的方法就可以了。
如果是調用別人的介面,人家會將裡面的方法做個說明的,直接調用即可,如下WebReference是引用名,ModuleService是方法。
using System;using System.Linq;using System.Collections.Generic;using System.Text;namespace test001{ class Class1 { //函數:調用介面,返回xml資料 public String returnData(int ss) { String data = null; String errmsg = null; try { using (WebReference.ModuleService service = new test001.WebReference.ModuleService()) { service.QuestMessage("DBTS", "", ss, "", "", out data, out errmsg); return data; } } catch { return null; } finally { if(data!=null) data = null; if (errmsg != null) errmsg = null; } } //函數:上傳資料 public int uploadData(String data,String id) { int flag = 0; String errmsg = null; using (WebReference.ModuleService service = new test001.WebReference.ModuleService()) { flag= service.PostMessage("SYGL", "", 0, data, id, out errmsg); return flag; } } }}