当前位置: 首页 >> 程序设计 >> 用VB调用Webservice
 

用VB调用Webservice

作者:baishijun      来源:     发表时间:2006-06-19     浏览次数:      字号:    

关键字: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

责任编辑 webmaster

 
 
 
 
 
评论更多>>
 
 
 
发表
 
姓名: QQ:
性别: MSN:
E-mail: 主页:
评分: 1 2 3 4 5
评论内容:
验证码:
  
  • 请遵守《互联网电子公告服务管理规定》及中华人民共和国其他各项有关法律法规。
  • 严禁发表危害国家安全、损害国家利益、破坏民族团结、破坏国家宗教政策、破坏社会稳定、侮辱、诽谤、教唆、淫秽等内容的评论 。
  • 用户需对自己在使用本站服务过程中的行为承担法律责任(直接或间接导致的)。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表网友个人观点,与本网站立场无关。
  •