Web Service 初学

看了一篇<<一步一步开始Web Service>>想把用VB.NET创建Web/服务的步骤记录下来.

1、用VS.NET创建一个“ASP.NET Web 服务”项目(我用的是VB.NET),然后在.asmx中的Service1类中实现一个“Add”函数如下:

    <WebMethod()> _
    Public Function Add(ByVal i As Integer, ByVal j As Integer) As Integer
        Add = i + j
    End Function

注意:要加“<WebMethod()> _”

2、按“F5”可以调试我们写的Add函数

3、生成“.wsdl”文件。

使用Visual Studio.NET工具中的 “Visual Studio.NET命令行提示”然后执行“disco http://localhost/WebService1/Service1.asmx?WSDL

4、生成“.vb”文件。

使用Visual Studio.NET工具中的 “Visual Studio.NET命令行提示”然后执行“wsdl /out:myWebService1.vb http://localhost/WebService1/Service1.asmx

5、编译

使用Visual Studio.NET工具中的 “Visual Studio.NET命令行提示”然后执行“csc /out:myWebService1.dll /t:library /r:System.XML.dll /r:System.Web.Services.dll myWebService1.vb”

6、用VS.NET创建一个“ASP.NET Web 应用程序”项目(我用的是VB.NET),在“解决方案资源管理器”中右键“添加Web引用”-“本地计算机上的 Web 服务”-“Service1”-“添加引用”

7、在WebForm1.aspx中添加一个TextBox、一个Button,双击Button添加代码如下:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim aaa As New localhost1.Service1
        TextBox1.Text = CStr(aaa.Add(1024, 1024))
    End Sub

8、按“F5”运行,单击“Button”后,TextBox1中显示“2048”。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值