Basic introduction and call example of WebService

This article is edited by Markdown syntax editor.

1. WebService’s basic introduction

Traditionally, we call the functions provided by the computer daemon as “services” (Service). For example, let an anti-virus software run in the background, it will automatically monitor the system, then this automatic monitoring is a “service”. In layman’s terms, a “service” is a certain function that a computer can provide.

According to different sources, “services” can be divided into two types: one is “local services” (services provided by the same machine, no Network), the other is “Network Service” (using the service provided by another computer, it must be done through the network).

The essence of “Web Service” is to call resources of other websites through the Internet.

The above content comes from Ruan Yifeng’s blog: “What is a Web service? 》, the link is as follows: http://www.ruanyifeng.com/blog/2009/08/what_is_web_service.html.

Therefore, by learning and using WebService, we can make full use of the various services provided on the Internet (such as querying the mobile phone number attribution, querying the time and weather forecast of each city, querying stock market information, and querying flights Information, etc.), rather than just limited to the limited services provided by the local computer. After all, the resources of the network are unlimited. By directly calling the services provided by other websites, we can maximize our work efficiency, without re-creating wheels, and focusing on our own business realization.

2. Build a WebService client through JavaScript

The following is a service based on JavaScript that sends an Ajax GET request to the WebService Request and return a simple example of the received data.

The code of testWebService.html is as follows:

<html><head< /span>> <title>WebService Client test pagetitle> <meta http-equiv="Content-Type" content< /span>="text/html;charset=utf-8" />head><body><script src= "./jquery-2.1.3.min.js">script><script src="./testWebServiceClient.js ">script> <script> document.write("

Send WebService Get and Post:

"
);
script><div> <input id="sendWebServiceGet" onclick="sendWebServiceGet();" type= "button" value="SendGet" > br>div> body>html>

The implementation of testWebServiceClient.js is as follows:
Among them, URL: http://ws.webxml.com.cn//WebServices/WeatherWS.asmx/getRegionCountry is a service provided on the Internet to obtain the name of a foreign country and its corresponding ID.
The service has no input parameters, and the return data is: a one-dimensional string array.

function sendWebServiceGet() { var getRegionCountryURL =  'http://ws.webxml.com.cn//WebServices/WeatherWS.asmx/getRegionCountry'; $.ajax({ url: getRegionCountryURL, type: 'Get ', dataType: 'JSONP', contentType: "text/xml; charset=utf-8"< /span>, success: function(data){< /span> console.log(data); }, error: function( msg){ console.log(msg);} })}

Write the picture description here

Write the picture description here

Although according to the above JS file, you can send a GET request to the WebService server, and in the jQuery callback function, you can also get the data returned from the server. However, in the background of the browser, an error message was thrown:
Uncaught SyntaxError: Unexpected token <“.

According to the answer given in this link, you can know the reason for this problem:
https://stackoverflow.com/questions/19934187/unexpected-token-reading-xml-file
” The response you are getting is an XML document, not a JavaScript program following the JSONP pattern. You get the error because the browser is trying to execute the XML as JavaScript (which it isn’t). Either change the response to be JSONP, or use some other method to make a cross-domain request.”
(The response you get is an XML document, not a JSONP style JavaScript program. You get this error because the browser is trying to execute the XML as JavaScript, in fact it is not. Modify the response to JSONP, or use other methods to generate a cross-domain request.)

3. Based on SoapUI simulation WebService client

The following demonstrates an available WebService service found on the Internet:
The service provided by this WebService is “query train schedule”, and the specific services provided include: station query ; Inquiry of train times; Inquiry of all train times at the station, etc.
http://www.webxml.com.cn/WebServices/TrainTimeWebService.asmx
(1) getDetailInfoByTrainCode
(2) getStationAndTimeByStationName
(3) getStationAndTimeByTrainCode
(4) getStationName
(5) getStationNameDataSet
(6) getVersionTime

4. Available WebService address list:

  1. What is Web service?
    http://www.ruanyifeng.com/blog/2009/08/what_is_web_service.html
  2. How to use soapUI to simulate a WebService client to send a request
    https://jingyan.baidu.com /article/cbcede0712849a02f40b4d88.html

This article is edited by Markdown syntax editor.

1. WebService’s basic introduction

Traditionally, we call the functions provided by the computer daemon as “services” (Service). For example, let an anti-virus software run in the background, it will automatically monitor the system, then this automatic monitoring is a “service”. In layman’s terms, a “service” is a certain function that a computer can provide.

According to different sources, “services” can be divided into two types: one is “local services” (services provided by the same machine, no Network), the other is “Network Service” (using the service provided by another computer, it must be done through the network).

The essence of “Web Service” is to call resources of other websites through the Internet.

The above content comes from Ruan Yifeng’s blog: “What is a Web service? 》, the link is as follows: http://www.ruanyifeng.com/blog/2009/08/what_is_web_service.html.

Therefore, by learning and using WebService, we can make full use of the various services provided on the Internet (such as querying the mobile phone number attribution, querying the time and weather forecast of each city, querying stock market information, and querying flights Information, etc.), rather than just limited to the limited services provided by the local computer. After all, the resources of the network are unlimited. By directly calling the services provided by other websites, we can maximize our work efficiency, without re-creating wheels, and focusing on our own business realization.

2. Build a WebService client through JavaScript

The following is a service based on JavaScript that sends an Ajax GET request to the WebService Request and return a simple example of the received data.

The code of testWebService.html is as follows:

<html><head< /span>> <title>WebService Client test pagetitle> <meta http-equiv="Content-Type" content< /span>="text/html;charset=utf-8" />head><body><script src= "./jquery-2.1.3.min.js">script><script src="./testWebServiceClient.js ">script> <script> document.write("

Send WebService Get and Post:

"
);
script><div> <input id="sendWebServiceGet" onclick="sendWebServiceGet();" type="button" value="SendGet"> br>div> body> html>

The implementation of testWebServiceClient.js is as follows:
, URL: http://ws.webxml.com.cn//WebServices/WeatherWS.asmx/getRegionCountry, is a service provided on the Internet to obtain the name of a foreign country and its corresponding ID.
The service has no input parameters, and the return data is: a one-dimensional string array.

function sendWebServiceGet() { var getRegionCountryURL =  'http://ws.webxml.com.cn//WebServices/WeatherWS.asmx/getRegionCountry'; $.ajax({ url: getRegionCountryURL, type: 'Get ', dataType: 'JSONP', contentType: "text/xml; charset=utf-8"< /span>, success: function(data){< /span> console.log(data); }, error: function( msg){ console.log(msg);} })}

Write the picture description here

Write picture description here

Although according to the above JS file, you can send a GET request to the WebService server, and in the jQuery callback function, you can also get the data returned from the server. However, in the background of the browser, an error message was thrown:
Uncaught SyntaxError: Unexpected token <“.

According to the answer given in this link, you can know the reason for this problem:
https://stackoverflow.com/questions/19934187/unexpected-token-reading-xml-file
” The response you are getting is an XML document, not a JavaScript program following the JSONP pattern. You get the error because the browser is trying to execute the XML as JavaScript (which it isn’t). Either change the response to be JSONP, or use some other method to make a cross-domain request.”
(The response you get is an XML document, not a JSONP style JavaScript program. You get this error because the browser is trying to execute the XML as JavaScript, in fact it is not. Modify the response to JSONP, or use another method to generate a cross-domain request.)

3. Based on SoapUI simulation WebService client

The following demonstrates an available WebService service found on the Internet:
The service provided by this WebService is “query train schedule”, and the specific services provided include: station query ; Inquiry of train times; Inquiry of all train times at the station, etc.
http://www.webxml.com.cn/WebServices/TrainTimeWebService.asmx
(1) getDetailInfoByTrainCode
(2) getStationAndTimeByStationName
(3) getStationAndTimeByTrainCode
(4) getStationName
(5) getStationNameDataSet
(6) getVersionTime

4. Available WebService address list:

  1. What is Web service?
    http://www.ruanyifeng.com/blog/2009/08/what_is_web_service.html
  2. How to use soapUI to simulate a WebService client to send a request
    https://jingyan.baidu.com /article/cbcede0712849a02f40b4d88.html

Leave a Comment

Your email address will not be published.