1.service文件代码:
Imports System.Web.Services
<System.Web.Services.WebService(Namespace :Namespace := "http://tempuri.org/VSService/Service1")> _
Public Class Service1Class Service1
Inherits System.Web.Services.WebService
#Region " Web Services Designer Generated Code "
Public Sub New()Sub New()
MyBase.New()
'This call is required by the Web Services Designer.
InitializeComponent()
'Add your own initialization code after the InitializeComponent() call
End Sub
'Required by the Web Services Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Web Services Designer
'It can be modified using the Web Services Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
Protected Overloads Overrides Sub Dispose()Sub Dispose(ByVal disposing As Boolean)
'CODEGEN: This procedure is required by the Web Services Designer
'Do not modify it using the code editor.
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
#End Region
' WEB SERVICE EXAMPLE
' The HelloWorld() example service returns the string Hello World.
' To build, uncomment the following lines then save and build the project.
' To test this web service, ensure that the .asmx file is the start page
' and press F5.
'
'<WebMethod()> _
'Public Function HelloWorld() As String
' Return "Hello World"
'End Function
<WebMethod()> Public Function add()Function add(ByVal a As Integer, ByVal b As Integer) As String
add = CStr(a + b)
End Function
End Class 2. asp.net调用,添加Web References。
Dim s As String
Dim t As New mingservice.Service1
ResultAdd.Text = t.add(CInt(Param1.Text), CInt(Param2.Text))
3. VB6调用,安装SoapToolkit20.exe。添加References:C:\Program Files\Common Files\MSSoap\Binaries\MSSOAP1.dll.
Dim sc As New MSSOAPLib.SoapClient
sc.mssoapinit "http://192.168.0.8/VSService/Service1.asmx?WSDL"
Text3.Text = sc.Add(CInt(Text1.Text), CInt(Text2.Text))
4.ASP调用,安装SoapToolkit20.exe。添加References:C:\Program Files\Common Files\MSSoap\Binaries\MSSOAP1.dll.
<%
Dim t1,t2,t3,SSO
t1 = Request.Form("text1")
t2 = Request.Form("text2")
SET SSO = Server.CreateObject("MSSOAP.SoapClient")
SSO.ClientProperty("ServerHTTPRequest") = True
Call SSO.mssoapinit("http://192.168.0.8/VSService/Service1.asmx?WSDL")
t3=SSO.add(CInt(t1),CInt(t2))
%>
<form action="http.asp" METHOD="POST">
<div align="center" >
<input type="text" name="text1" value="0">
<input type="text" name="text2" value="0">
<input type="text" name="text3" value="<%=t3%>">
</div>
<br>
<div align="center" ><input type="submit" name="Submit" value="Ìá½»"></div>
</form>
5. ASP HTTP请求:
<%
Dim t1,t2,t3
t1 = Request.Form("text1")
t2 = Request.Form("text2")
url = "http://192.168.0.8/VSService/Service1.asmx/add"
SoapRequest="a="&t1&"&b="&t2&""
Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open "POST",url,false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.setRequestHeader "HOST","192.168.0.8"
xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)
xmlhttp.Send(SoapRequest)
If xmlhttp.Status = 200 Then
Set xmlDOC = server.CreateObject("MSXML.DOMDocument")
xmlDOC.load(xmlhttp.responseXML)
t3=xmlDOC.childNodes(1).Text
Set xmlDOC = nothing
Else
Response.Write xmlhttp.Status&" "
Response.Write xmlhttp.StatusText
End if
Set xmlhttp = Nothing
%>
<form action="http.asp" METHOD="POST">
<div align="center" >
<input type="text" name="text1" value="0">
<input type="text" name="text2" value="0">
<input type="text" name="text3" value="<%=t3%>">
</div>
<br>
<div align="center" ><input type="submit" name="Submit" value="提交"></div>
</form>