How does ASP. NET call web service?

Source: Internet
Author: User

Calling a Web Service in. NET is actually as simple as creating a web service. (CompleteCodeLocation: Optical Disc \ code \ ch07 \
Webappclient)

The implementation steps are as follows.

(1) first, create an ASP. NET web application.Program.

(2) Add a web service reference.

Right-click the project and choose "add web reference" from the shortcut menu, as shown in 7-6. The "add web reference" dialog box, as shown in 7-7 is displayed.


 
Figure 7-6 select the "add web reference" command

 
(Click to view the larger image) Figure 7-7
"Add web reference" dialog box

Adding a reference is divided into the following three cases.

If it is a Web service in this solution, select the first one. The program automatically redirects to the service address in the solution.

If it is a Web service on the computer, the system will automatically find the Web service on the local machine for you to choose from.

In either case, the final goal is to input the corresponding address in the URL for loading. Therefore, we can enter the address of the web service in the URL, both local and public networks are the same.
Then, click "go" to list the Web service test page and method description, and verify whether the project can use the web service, as shown in 7-8.


 
(Click to view the larger image) Figure 7-8 preview web reference

In this case, enter a name in the "Web reference name" text box and use this name in the code to access the selected web service programmatically, click Add reference.

(3) In this case, a directory named web references is added to the project, as shown in 7-9. The automatically generated proxy class is placed here.


 
Figure 7-9 Web reference

(4) Click the "show all files" button in Solution Explorer of the Project. Then you can see the proxy class named reference. CS.

(5) using this proxy class in code is basically the same as using a local common class.

 
  
  
  1. Productservice. ltpservice service =NewProductservice. ltpservice ();
  2. StringPrice = service. getproductprice ("001");

So far, ASP. NET has finished calling Web service, and only two lines of code have been written.

Related Article

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.