Call WebService in VC

Source: Internet
Author: User
Tags header soap reference visual studio

One, what is WebService?

WebService is actually a web-based application that provides a certain calling interface to external programs. An external (remote) program that can be invoked via the Web.

Second, the characteristics of WebService:

1. Because WebService is published via a Web server, it can go through the firewall more smoothly than DCOM. This is also one of the advantages of WebService, it can be said that WebService, for the development of distributed applications, provides a good platform.

2. The invocation of WebService is done through the SOAP protocol. Simple Object Access Protocol (SOAP) provides a standard remote procedure call (RPC) method to invoke a Web service. Soap is also xml-based and XSD, and XML is the data encoding of soap, so calls to WebService can also be cross-platform. 、

Third, how to call WebService?

Visual Studio.NET provides a call to WebService. In Vc.net, it takes only a few simple steps to call WebService. Just find the WebService address and introduce the address into the VC project. At this point, the compiler compiles one time, automatically generating and WebService related header files (also called Web Proxy files) WebService. h. In your program, you can invoke the remote WebService by including WebService. h and then generating the related objects.

To demonstrate how to invoke WebService, we use a published WebService on the web, called Translateservice, whose function is to translate to one another in multiple languages. The address of this WebService is as follows: Http://www.WebServicex.net/TranslateService.asmx

Iv. Program Examples

1. Console-based managed programs sample

Now, let's start by introducing the console-based managed program in Vc.net, which calls the WebService example:

Start Visual Studio.NET 2003 to create a new Visual C + + project with type selection based on. NET managed console application. Then, introduce WebService to the project, right-click on the project name of the solution, and select Add Web Reference. The following figure (Figure 1):

Figure 1 Adding a WebService reference to the project

Fill in the WebService address and click the "Go" button. The details of the WebService will be shown below. Web reference name, you can use the default name, you can set up one, here, our name is TService. Then click "Add Reference" (Figure 2), the compiler automatically generates TService.h and WebService. H. TService.h is already included in WebService. H. In the engineering code, we directly include the header file WebService. h.

Figure 2 Adding WebService

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.