In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to use the Soap protocol to call webservice to achieve mobile phone attribution query in android. I hope you will get something after reading this article. Let's discuss it together.
One: Web service (webservice) is a software system that can support machine-to-machine interoperability on local area network and Internet. It has an interface described in WSDL, and other systems can interact with it in the way described by the interface using SOAP messages. SOAP protocol is the basis of Web service survival.
The goal of Web services is to achieve that in such a distributed environment, any number of applications or application components within and between organizations can interact seamlessly in a platform-independent and language-independent manner.
Web service is a software system identified by unified resource identification (URI). Its common interface and binding are defined and described by XML. Software systems can communicate XML-based messages through the Internet protocol so that they can interact with them in the way defined by Web Service.
Web services enable us to make remote calls to RPC (Remote Procedure Call) to an object on the Internet or network. Web services use neutral platform standards (HTTP and XML) to completely hide the details of performing tasks from customers, who only need to know the data types used by the URL or method calls of the service to provide services for different platforms.
SOAP, WSDL, and UDDI are the core of the webservice technology system:
(1) WSDL is the description language of Web service, which is similar to IDL of CORBA to describe the interactive message format, port type and binding of transport protocol of Web service.
(2) the Web service uses UDDI as the directory mechanism, and the service publisher can register the service information with UDDI, which makes it convenient for the service consumer to find the service.
(3) SOAP provides a standard packaging structure for transferring XML documents over a variety of standard Internet technologies, including SMTP, HTTP, and FTP. It also defines the coding and binding standard for sending non-XML RPC calls using XML, and SOAP provides a simple structure for RPC: document exchange. After adopting the standard transmission mechanism, heterogeneous clients and servers can interoperate at once.
SOAP (Simple Object Access Protocol) is a simple object access protocol, which is a lightweight distributed computing protocol that allows the exchange of structured information in a decentralized and distributed environment. The SOAP specification defines a framework for delivering messages in distributed systems and conventions that support remote procedure calls and responses. The SOAP message is based on SOAP
Envelope is the root element and contains two child elements: SOAP Header and SOAP Body. SOAP Body is mandatory and is a necessary element of SOAP messages. It contains the main content of SOAP messages and is handled by the node that finally receives the SOAP messages. SOAP Body is the application payload and can contain application data, RPC methods and parameters, and SOAP errors.
Three: the following is a case of mobile phone attribution query based on soap protocol and server interaction in android development.
one. Running effect:
When this user does not exist:
two。 Layout file code:
3. Create a mobile phone attribution query tool class PhoneUtil.java
Public class PhoneUtil {public static Object searchPlace (String wsdlurl,String method,String phonenumber) {/ / specify the namespace of the webservice and the method name of the call String namespace= "http://WebXml.com.cn/"; SoapObject soap=new SoapObject (namespace,method) / / add attributes. As long as the order of setting parameters is the same, the parameter name of the calling method is not necessarily the same as the parameter name of the method in the server's WebService class: soap.addProperty ("mobileCode", phonenumber); soap.addProperty ("userID", null); / / set the version number of the SOAP protocol through the constructor of the SoapSerializationEnvelope class. SoapSerializationEnvelope soapEnvelope=new SoapSerializationEnvelope (SoapEnvelope.VER11); / / set the outgoing Soap soapEnvelope.bodyOut=soap; soapEnvelope.dotNet=true; soapEnvelope.setOutputSoapObject (soap); / / create http transport object HttpTransportSE transportSE=new HttpTransportSE (wsdlurl); / / soap operation url String SOAP_ACTION=namespace+method Try {/ / request to call WebService method transportSE.call (SOAP_ACTION, soapEnvelope); / / use getResponse to get the result of parsing xml returned by WebService method Object result=soapEnvelope.getResponse () If (resulting null) return result;} catch (IOException e) {e.printStackTrace ();} catch (XmlPullParserException e) {e.printStackTrace ();} return null;}}
4.MainActivity class
Public class MainActivity extends Activity {private EditText phonenum; private Button search; private EditText result; @ Override public void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); / / set no title bar / / setTheme (Window.FEATURE_NO_TITLE); setContentView (R.layout.activity_main); / / find component phonenum= (EditText) this.findViewById (R.id.phone) Search= (Button) this.findViewById (R.id.search); result= (EditText) this.findViewById (R.id.result); search.setOnClickListener (new OnClickListener () {public void onClick (View v) {String phone=phonenum.getText () .toString () / / web server phone attribution url String wsdlUrl= "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx"; / / call the method getMobileCodeInfo provided by web to get the attribution Object answer=PhoneUtil.searchPlace (wsdlUrl," getMobileCodeInfo ", phone) / / query results are displayed in the result text field result.setText (answer.toString ());}});} @ Override public boolean onCreateOptionsMenu (Menu menu) {getMenuInflater () .inflate (R.menu.activity_main, menu); return true }} after reading this article, I believe you have a certain understanding of "how to use Soap protocol to call webservice to query mobile phone attribution in android". If you want to know more about it, welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.