First, create a Web Service Project
Main Code As follows:
Add the method in service. VB in appcode:
'Helloworld' is automatically generated by the system.
'I added two methods
'Addservice implements a simple addition operation of two numbers,
'Myds generates a simple dataset.
'Prepare for subsequent calls.
'Note: If you want to use methods and data on the Web service elsewhere,
'You must add "<webmethod ()> _" before the method definition _"
Imports system. Web
Imports system. Web. Services
Imports system. Web. Services. Protocols
Imports system. Data
<WebService (namespace: = "http://tempuri.org/")> _
<Webservicebinding (conformsto: = wsiprofiles. basicprofile1_1)> _
<Global. Microsoft. VisualBasic. compilerservices. designergenerated ()> _
Public class service
Inherits system. Web. Services. WebService
<Webmethod ()> _
Public Function helloworld () as string
Return "Hello World"
End Function
<Webmethod ()> _
Public Function addservice (byval A as integer, byval B as integer) as string
Return A + B
End Function
<Webmethod ()> _
Public Function myds () as Dataset
Dim ds as new dataset
Dim dT as new datatable ("test ")
Dim col1 as datacolumn = DT. Columns. Add ("fname", system. type. GetType ("system. String "))
Dim col2 as datacolumn = DT. Columns. Add ("fsex", system. type. GetType ("system. String "))
Dim Dr as datarow
For I as integer = 0 to 5
Dr = DT. newrow
Dr (0) = "Wang" & I
Dr (1) = "man"
DT. Rows. Add (DR)
Next
DS. Tables. Add (DT)
Return DS
End Function
End Class
Generate the http: // localhost/website1/service. asmx service address locally
Next we are creating a simple website project.
Because we are doing a web service test, we need to add a reference to it,
Add the service address http: // localhost/website1/service. asmx to it and name the reference localhost.
Add a datagridview control to the page.
The background code is as follows:
Imports localhost. Service
Partial class _ default
Inherits system. Web. UI. Page
Dim A as localhost. Service
Protected sub page_load (byval sender as object, byval e as system. eventargs) handles me. Load
A = new localhost. Service 'instance.
Me. dgv. datasource = A. myds. Tables (0) 'calls the dataset in the service.
Me. dgv. databind ()
End sub
End Class
Run the website to view the data obtained from the service.
Next, we create a Windows project to implement service usage.
The method is like a website operation. You can follow the steps above to use the service. I just went a little bit, huh, huh!
This is the simplest application. It is complicated for us to learn together!