用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 totalEnd Sub

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...