First knowledge of Web Services

Source: Internet
Author: User

What is Web Services
  
On the surface, Web Service is an application that exposes an API that can be called through the Web. That is to say, you can use programming methods to call this application through the Web.
  
A more accurate explanation of Web Services: Web Services is a new platform for building interoperable distributed applications. The Web service platform is a set of standards that define how applications implement interoperability on the web. You can use any language you like to write Web Services on any platform you like, as long as we can query and access these services through web service standards.
  
No matter what tool or language your Web Service uses, the overall structure is consistent as long as you use the SOAP protocol to call it over HTTP. Generally, you use your preferred language (such as VB 6 or VB. to build your web service, and then use the soap toolkit or. net built-in support to expose it to Web customers. Therefore, customers in any language and platform can read its WSDL document to call this web service. The customer generates a SOAP request message based on the WSDL description. Web services are placed after Web servers (such as IIS). The SOAP requests generated by the customer are embedded in an http post request and sent to the web server. The Web server then forwards these requests to the Web service request processor. The request processor parses the received SOAP request, calls the web service, and then generates the corresponding soap response. After the Web server receives a soap response, it will send it back to the client through HTTP response.
  
Basic Concepts
  
Soap
  
XML and XSD
  
WSDL (Web Services Description Language)
  
Wsml (Web Services meta LANGUAGE)
  
When to use Web Services
  
Web Service is a new platform for creating interoperable distributed applications. The main goal of Web Service is cross-platform interoperability. To achieve this goal, Web services are fully based on XML, XSD, and other standards independent of platforms and software vendors.
  
Web service is very useful when applications communicate across platforms and networks. Web Service is suitable for application integration, B2B integration, code and data reuse, and communication between clients and servers through the Web.
  
Of course, Web services are not omnipotent. You cannot abuse web services everywhere. In some cases, Web Service Reduces the application performance without any benefits. For example, a homogeneous application running on a machine or a LAN should not communicate with Web Services.
  
How to call Web Services
  
Client: Get the service description file WSDL of the server, parse the content of the file, understand the service information of the server, and call method. Generate the appropriate SOAP request message (specify the method to call and the parameters already called) as needed and send it to the server. Wait for the soap response message returned by the server and parse it to get the return value.
  
Server: generate a service description file for the client to obtain. Receives the SOAP request message from the client and parses the method call and parameter format. According to the description of WSDL and wsml, call the corresponding COM object to complete the specified function, and put the returned value into the soap Response Message and return it to the user.
  
High-level Interface
  
A WebService can be generated and used without knowing any information about soap and XML. Soap Toolkit 2.0 provides two COM objects-soapclient and soapserver.
  
On the client, you only need to generate a soapclient instance and use WSDL as the parameter to call the mssoapinit method. The soapclient object automatically parses the WSDL file and generates the method and parameter information of all web services internally. Then, you can call all the methods in the idispatch interface just like calling the methods in it. In VB or script language, you can even directly add a. Method (parameter…) after the name of the soapclient object ...) .
  
Lower Layer Interface
  
To use lower-layer interfaces, you must understand soap and XML. You can control the processing of soap, especially for special processing.
  
On the client, you must first create an httpconnector object for HTTP connection. Set some header information of connector, such as endpoinurl and soapaction. If you need to use a proxy server for network connection, set the relevant information here. Create a soapserializer object to generate a SOAP message. According to the definition in WSDL, all parameters are serialized in order to obtain a complete SOAP request message. This SOAP message is sent to the server as payload through httpconnector. Finally, a soapreader object is generated to read the SOAP message returned by the server and obtain the return value.

Experience the elegance of. NET 2.0-asynchronous WebService call
In. net2.0 (specifically VS 2005), an example of asynchronous WebService asynchronous call method is provided:
Void dosomethingtest ()
{
Localhost. Service = new windowsapp. localhost. Service ();
Service. helloworldcompleted + = new windowsapp. localhost. helloworldcompletedeventhandler (service_helloworldcompleted );
// Do Asyn calling here
Service. helloworldasync ();
}

Void service_helloworldcompleted (Object sender, windowsapp. localhost. helloworldcompletedeventargs E)
{
If (E. Error = NULL)
{
MessageBox. Show (E. Result );
}
Else
{
MessageBox. Show (E. Error. Message );
}
}

Server code

[WebService (namespace = "http://tempuri.org/")]
[Webservicebinding (conformsto = wsiprofiles. basicprofile1_1)]
Public class service: system. Web. Services. WebService
{Public Service (){
}

[Webmethod] Public String helloworld (){
Return "Hello World ";
}
}

It's easy. Without the annoying asynccallback and iasyncresult, The called code becomes concise and elegant. the result returns a strongly typed return value ("Hello World" in the preceding example "). However, if you are interested, you can check the referance. CS file generated by VS 2005, which is much more complicated than the referance. CS file generated by vs 2003. The system. componentmodel. asynccompletedeventargs and system. Threading. sendorpostcallback (delegate) are not found in. Net 1.x. It is estimated that more than the WebService client is used.

This article is reproduced from 1024 K: http://www.1024k.cn/net/2007/200701/15405.html

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.