It's been a long time! I have been learning Web Service recently. By the way, let's write a simple experience.

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.