[018] WebService introduction for Android Development

Source: Internet
Author: User

 

From: http://blog.csdn.net/lyq8479/article/details/6420398

Some netizens often ask: "How to call WebService on the Android platform "? After communication, I found that some friends even asked how to use webserivce, not to mention the "Mars" terms such as soap and WSDL related to WebService. So, I just wantBefore explaining how to call webserivce on the Android platform, let's first introduce WebServiceTo see how mysterious it is.
I remember that my master thesis included the word "Web Service". At that time, I spent a lot of time studying the application of Web Service in system integration and enterprise application integration. At work, the Web Service is used for all the projects involved. Now, I have to spend some time learning Android, and I am also a web service. It seems that Web services are everywhere and can always be found in programming languages (Note: if you have never touched WebService before, You Need To Know That WebService is not a patent of Android, ).

According to W3C definition, Web Services is a software system used to support interoperability between different machines in the network. It is a self-contained, self-described, and modular application, it can be described, published, and called in the network, and can be viewed as a network-based, distributed modular component.
Web services are built on general protocols, such as HTTP, soap, UDDI, and WSDL. These protocols have no preference in the selection of operating systems, programming languages, and object models, therefore, it has a strong vitality.
The advantage of web services is that it provides interoperability between different application platforms, which makes the combination of component-based development and web best. It is based on the HTTP protocol. Call requests and response messages can both pass through the firewall without changing the firewall settings. This avoids the problem that the firewall cannot be crossed when special ports are used for communication.

Simple understanding:Generally, WebService is a remote server that discloses a service, or is understood as a function or method, we can call the service through programming to obtain the information we need. For example, www.webxml.com.cn has published a mobile phone number for the local location query service. You only need to input a mobile phone number segment (number) when calling this service to obtain the region information of this segment immediately.
A more general understanding:By using WebService, we can call methods on the remote server just like calling local methods. We don't need to worry about whether the remote method is written in Java or in PHP or C #. We don't need to worry about whether the remote method is based on Unix or windows, that is to say, WebService has nothing to do with the platform and language.

When it comes to webserivce, you must know soap and WSDL. What is the relationship between them and webserice? As mentioned above, Web services are built on common protocols such as HTTP, soap, and WSDL.
Simple Object Access Protocol (SOAP) is a lightweight, simple, XML-based protocol, it is designed to exchange simple protocols for formatting and solidification of information in a distributed environment. That is to say, for communication and data access and transmission, it must rely on a certain protocol, and soap is a protocol that is relied on in WebService communication. Currently, the commonly used SOAP protocol has two versions: Soap 1.1 and soap 1.2.
Web Services Description Language (WSDL) is an XML language used to describe Web services. It describes the functions, interfaces, parameters, and returned values of Web Services, this allows you to easily bind and call services. It defines operations and messages related to a given web service call and response in a language-independent manner.
WSDL is what we can see. It is an XML document used to describe all aspects of a webserivce. For example, I mentioned that the www.webxml.com.cn website provides a webserivce for querying mobile phone numbers in the same region. How can we use this webserivce? Which version of the SOAP protocol is it based on? What parameters need to be passed in to call it? What value does it return? Is it a string or an XML document? All these questions can be answered in WSDL. The WSDL address of the above service is: http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx? Access IT in the browser. You will see the following XML document:

View plaincopy
Clipboardprint?
  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <WSDL: Definitions xmlns: Soap = "http://schemas.xmlsoap.org/wsdl/soap"
  3. Xmlns: TM = "http://microsoft.com/wsdl/mime/textMatching"
  4. Xmlns: soapenc = "http://schemas.xmlsoap.org/soap/encoding"
  5. Xmlns: mime = "http://schemas.xmlsoap.org/wsdl/mime"
  6. Xmlns: TNS = "The http://WebXml.com.cn /"
  7. Xmlns: S = "http://www.w3.org/2001/XMLSchema"
  8. Xmlns: soap12 = "http://schemas.xmlsoap.org/wsdl/soap12"
  9. Xmlns: HTTP = "http://schemas.xmlsoap.org/wsdl/http"
  10. Targetnamespace = "http://WebXml.com.cn /"
  11. Xmlns: WSDL = "http://schemas.xmlsoap.org/wsdl/">
  12. <WSDL: Documentation xmlns: WSDL = "http://schemas.xmlsoap.org/wsdl/">
  13. <A href = "http://www.webxml.com.cn/" mce_href = "http://www.webxml.com.cn/" target = "_ blank"> webxml.com.cn </a>
  14. <Strong> domestic mobile phone number retrieval Web Service </strong>: provides the latest domestic mobile phone number segment retrieval data, which is updated every month. <Br/>
  15. Use this site web service please note 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/
  16. </A> thank you for your support! <Br/>
  17. </WSDL: Documentation>
  18. <WSDL: types>
  19. <S: schema elementformdefault = "qualified" targetnamespace = "http://WebXml.com.cn/">
  20. <S: element name = "getmobilecodeinfo">
  21. <S: complextype>
  22. <S: sequence>
  23. <S: Element minoccurs = "0" maxoccurs = "1" name = "mobilecode" type = "s: string"/>
  24. <S: Element minoccurs = "0" maxoccurs = "1" name = "userid" type = "s: string"/>
  25. </S: sequence>
  26. </S: complextype>
  27. </S: Element>
  28. <S: element name = "getmobilecodeinforesponse">
  29. <S: complextype>
  30. <S: sequence>
  31. <S: Element minoccurs = "0" maxoccurs = "1" name = "getmobilecodeinforesult" type = "s: string"/>
  32. </S: sequence>
  33. </S: complextype>
  34. </S: Element>
  35. ......
  36. </S: schema>
  37. </WSDL: types>
  38. ......
  39. </WSDL: Definitions>

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <WSDL: Definitions xmlns: Soap = "http://schemas.xmlsoap.org/wsdl/soap/" <br/> xmlns: TM = "http://microsoft.com/wsdl/mime/textMatching/" <br/> xmlns: soapenc = "http://schemas.xmlsoap.org/soap/encoding/" <br/> xmlns: mime = "http://schemas.xmlsoap.org/wsdl/mime/" <br/> xmlns: TNS = "http://WebXml.com.cn/" <br/> xmlns: S = "http://www.w3.org/2001/XMLSchema" <br/> xmlns: soap12 = "http://schemas.xmlsoap.org/wsdl/soap12" <Br/> xmlns: HTTP = "http://schemas.xmlsoap.org/wsdl/http/" <br/> targetnamespace = "http://WebXml.com.cn/" <br/> xmlns: WSDL = "http://schemas.xmlsoap.org/wsdl/"> <br/> <WSDL: documentation xmlns: WSDL = "http://schemas.xmlsoap.org/wsdl/"> <br/> <a href = "http://www.webxml.com.cn/" mce_href = "http://www.webxml.com.cn/" target = "_ blank"> webxml.com.cn </a> <br/> <strong> domestic mobile phone number retrieval Web Service </strong>, provides the latest domestic mobile phone number segment region data, which is updated every month. <Br/> to use the Web service on this site, please indicate or link to this site: <a href = "http://www.webxml.com.cn/" mce_href = "http://www.webxml.com.cn/" target = "_ blank"> http://www.webxml.com.cn/<br/> </a> thank you for your support! <Br/> </WSDL: Documentation> <br/> <WSDL: types> <br/> <s: schema elementformdefault = "qualified" targetnamespace = "http://WebXml.com.cn/"> <br/> <s: element name = "getmobilecodeinfo"> <br/> <s: complextype> <br/> <s: sequence> <br/> <s: Element minoccurs = "0" maxoccurs = "1" name = "mobilecode" type = "s: string "/> <br/> <s: Element minoccurs =" 0 "maxoccurs =" 1 "name =" userid "type =" s: string "/> <br/> </S: sequence> <br/> </S: complextype> <br/> </s: element> <br/> <s: element name = "getmobilecodeinforesponse"> <br/> <s: complextype> <br/> <s: sequence> <br/> <s: Element minoccurs = "0" maxoccurs = "1" name = "getmobilecodeinforesult" type = "s: string "/> <br/> </S: sequence> <br/> </S: complextype> <br/> </s: element> <br/> ...... <br/> </S: schema> <br/> </WSDL: types> <br/> ...... <br/> </WSDL: Definitions>
What information can we get from the WSDL?
1) Line 1 shows that the SOAP Protocol version of The webserivce is soap1.2;
2) from row 10th we can see that the namespace of the webserivce is http://WebXml.com.cn /;
3) from row 20th, we can see that the method to be called when querying the mobile phone number attribution location is getmobilecodeinfo;
4) line 23-24 shows that two parameters are required when we call the getmobilecodeinfo method: mobilecode and userid;
5) lines 31st show that after the getmobilecodeinfo method is called, a result string named getmobilecodeinforesult is returned.
Here, we have a preliminary understanding of webserivce and soap and WSDL. With this knowledge, you can start WebService-related development. The next article explains how to program and call the webserivce above on the Android platform and obtain the returned results.

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.