看了一篇<<一步一步开始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”。