用VB調用Webservice(一)

關鍵字:VB,WebService,C#,
調試環境:vb6+sp5 , Vs.net 2005 , SOAP Toolkit 3.0
 
在VB中調用Webservice先要安裝Soap Toolkit,可以到微軟的網站上下載,下載地址爲:http://www.microsoft.com/downloads/details.aspx?familyid=BA611554-5943-444C-B53C-C0A450B7013C&displaylang=en
 
1 首先用Vs.net建立WebService工程,添加以下調試代碼

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }
    [WebMethod]
    public int Add(int x,int y)
    {
        return x + y;
    }
 
 
2 新建VB工程,添加對soap toolkit的引用(Microsoft Soap Type Library 3.0)

3 在VB中添加以下代碼:

Private Sub Command1_Click()
    Dim soapClient As New SoapClient30
    Dim text As String


    '注:此爲本地的WebService地址,實際應用中會有不同

    soapClient.MSSoapInit "http://localhost:2239/DemoWebService/Service.asmx?WSDL"


    text = soapClient.HelloWorld '此處直接寫服務端方法名
    MsgBox text
   
    Dim total As Integer
   
    total = soapClient.Add(2, 3)
   
    MsgBox total
End Sub

 

發佈了28 篇原創文章 · 獲贊 6 · 訪問量 25萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章