Introduction to the WebService of Android development

Source: Internet
Author: User
Tags documentation soap object model web services xmlns wsdl firewall

Often have netizens ask: "How to call WebService on Android platform"? Through communication I found that even some friends were asking how to use the Webserivce, not to mention the "Martian" terms such as soap and WSDL related to webservice. So, I just want to introduce the next webservice before I explain how the Android platform calls Webserivce, and see how mysterious it is.

I remember that the title of my master's thesis included the word "Web service", when I spent a lot of time researching the application of Web service in system integration and enterprise application integration. At work, several of the projects contacted have been used for Web service And now spend some time outside of work to learn Android and Web Service. It seems that Web service is really ubiquitous, where there is programming language, can always find its figure (hint: If you have not contacted WebService before, here need to know WebService is not the patent of Android, 10几 years ago has appeared).

According to the definition of the Consortium, Web Services (Web service) is a software system that supports the interoperability of different machines between networks. It is a self-contained, self-describing, and modular application that can be described, published, and invoked on a network and can be viewed as a network-based, distributed modular component.

WEB services are built on the basis of common protocols, such as HTTP, SOAP, UDDI, WSDL, and so on, which have no inclination to choose the operating system, programming language, and object model, and therefore have a strong vitality.

The advantage of WEB services is that it provides interoperability between different application platforms, enabling component-based development and Web integration to be the best. It is based on the HTTP protocol, call request and response messages can go through the firewall, do not need to change the firewall settings, so as to avoid the use of special ports to communicate without crossing the firewall problem.

Simple understanding: Usually what we call WebService is that a remote server exposes a service, or understands that it exposes a function or method, and we can programmatically invoke the service to get the information we need. For example: www.webxml.com.cn the mobile phone number attribution to the Public inquiries service, we only need to call the service when a mobile phone number (number), you can immediately obtain the information of the ownership of the paragraph.

A more popular understanding: By using WebService, we can invoke methods on the remote server just as we call local methods. We don't need to care whether the remote method is written in Java or PHP or C #, and we don't need to care whether the remote approach is based on a UNIX platform or a Windows platform, which means that webservice is independent of platform and language.

When it comes to Webserivce, you have to know what soap and WSDL are, and how do they relate to webserice? As mentioned above, Web Services is built on the basis of common protocols such as HTTP, SOAP, and WSDL.

SOAP (Simple Object Access Protocol) is a lightweight, simple, xml-based protocol designed to Protocol simple protocols for exchanging formatting and solidifying information in a distributed environment. In other words, to communicate, data access transmission, you must rely on a certain protocol, and SOAP is webservice communication is dependent on a protocol. The SOAP protocols that are currently used are two versions: SOAP 1.1 and SOAP 1.2.

The WSDL (Web Services Description Language, Web Service Description Language) is an XML language used to describe Web services, which describes the functions, interfaces, parameters, return values of Web services, and facilitates user binding and invocation of services. It defines the actions and messages for a given Web service invocation and answer in a language-independent way.

WSDL is something that we can actually see, an XML document that describes every aspect of a webserivce. For example, the above mentioned www.webxml.com.cn website provides the mobile phone number attribution Query Webserivce, how do we use this webserivce? Which version of the SOAP protocol is it based on? What parameters do I need to pass in to call it? What value will it return? Is it a string or an XML document? This series of questions can be found in WSDL. The WSDL address for this service is: http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl, access it on the browser, and you will see the XML document as follows:

<?xml version= "1.0" encoding= "Utf-8"?> <wsdl:definitions xmlns:soap= "Http://schemas.xmlsoap.org/wsdl/soap" /"xmlns:tm=" http://microsoft.com/wsdl/mime/textMatching/"xmlns:soapenc=" http://schemas.xmlsoap.org/soap/ encoding/"Xmlns:mime=" http://schemas.xmlsoap.org/wsdl/mime/"xmlns:tns=" http://WebXml.com.cn/"xmlns:s=" http: Www.w3.org/2001/XMLSchema "xmlns:soap12=" http://schemas.xmlsoap.org/wsdl/soap12/"xmlns:http=" http:// schemas.xmlsoap.org/wsdl/http/"targetnamespace=" http://WebXml.com.cn/"xmlns:wsdl=" http://schemas.xmlsoap.org/ wsdl/"> <wsdl:documentation xmlns:wsdl=" http://schemas.xmlsoap.org/wsdl/"> <a href=" http://www . webxml.com.cn/"mce_href=" http://www.webxml.com.cn/"target=" _blank ">WebXml.com.cn</a> <strong> country Internal mobile phone number attribution to query Web Services </STRONG&GT, to provide the latest domestic mobile phone number of the attribution of data, monthly update. <br/> Use this site WEB services, please indicate or link this site: <a href= "http://www.webxml.com.cn/" mce_href= "http://www.webxml.com.cn/" target= "_blank" >http://www.webxml.com.cn/</a> Thank you for your support! <br/> </wsdl:documentation> <wsdl:types> <s:schema elementformdefault= "Qualif  
                IED "targetnamespace=" http://WebXml.com.cn/"> <s:element name=" Getmobilecodeinfo "> <s:complexType> <s:sequence> <s:element minoccurs= "0" max occurs= "1" name= "Mobilecode" type= "s:string"/> <s:element minoccurs= "0" maxoccurs= "1" nam  
            E= "UserID" type= "s:string"/> </s:sequence> </s:complexType> </s:element> <s:element name= "Getmobilecodeinforesponse" > <s:comple xtype> <s:sequence> <s:element minoccurs= "0" maxoccurs= "1" nam  
                    E= "Getmobilecodeinforesult" type= "s:string"/></s:sequence> </s:complexType> </s:element> ... </s:schema> </wsdl:types> ... </wsdl:definitions>

When we see the WSDL, what information can we get from it?

1 as can be seen from line No. 08, the SOAP protocol version on which the Webserivce is based is SOAP1.2;

2 as can be seen from line 10th, the Webserivce namespace (NameSpace) is http://WebXml.com.cn/;

3 from the 20th line can be seen, we query mobile phone number of the attribution of the method to call the name: Getmobilecodeinfo;

4 from the 第23-24 line, we can see that when we call the Getmobilecodeinfo method, we need to pass in two parameters: Mobilecode and UserID;

5 as you can see from line 31st, when the Getmobilecodeinfo method is invoked, a result string named Getmobilecodeinforesult is returned.

Here, we have a preliminary understanding of Webserivce, as well as soap and WSDL. With this knowledge in place, you can start WebService related development work. The next article will explain how to programmatically invoke this Webserivce on the Android platform and get the results back.

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.