Advertisement
jasperlow

Untitled

Jun 30th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.03 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4. <title>SoapWS Calling</title>
  5. <!-- <script src="soapclient.js"></script> -->
  6. <script src="https://code.jquery.com/jquery-3.0.0.min.js" integrity="sha256-JmvOoLtYsmqlsWxa7mDSLMwa6dZ9rrIdtrrVYRnDRH0=" crossorigin="anonymous">
  7. </script>
  8. <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
  9.  
  10. </head>
  11.  
  12. <body onload="callMethod(5)">
  13.  
  14. <script type="text/javascript">
  15.  
  16. function callMethod (req) {
  17. if(req===1){
  18. callInvocation();
  19. }else if(req===2){
  20. callAjaxSoap();
  21. }else if(req===3){
  22. callXMLHttpRequest01();
  23. }else if(req===4){
  24. callXMLHttpRequest02();
  25. }else if(req===5){
  26. soapByJasper2();
  27. }else if(req===6){
  28. }
  29. }
  30.  
  31. function xmlhttphandler (xmlhttp) {
  32. if(xmlhttp==null){
  33. $("#eee2").html('onLost:');
  34. return;
  35. }
  36. if (xmlhttp.readyState === 4) {
  37. if (xmlhttp.status === 200) {
  38. $("#eee2").html('onSuccess:' + xmlhttp.responseText);
  39. } else {
  40. $("#eee2").html('onError:' + xmlhttp.statusText);
  41. }
  42. }else{
  43. $("#eee2").html('onCORSException:' + JSON.stringify(xmlhttp));
  44. }
  45. }
  46.  
  47. function createCrossDomainRequest(url, handler) {
  48. var isIE8 = window.XDomainRequest ? true : false;
  49. var request;
  50. if (isIE8) {
  51. request = new window.XDomainRequest();
  52. } else {
  53. request = new XMLHttpRequest();
  54. }
  55. return request;
  56. }
  57. function callInvocation(){
  58. var invocation = createCrossDomainRequest();
  59. var wsUrl = "http://www.webservicex.net/ConvertTemperature.asmx?op=ConvertTemp";
  60. var sr = '<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ConvertTemp xmlns="http://www.webserviceX.NET/"> <Temperature>40</Temperature> <FromUnit>degreeCelsius</FromUnit> <ToUnit>kelvin</ToUnit> </ConvertTemp> </soap:Body> </soap:Envelope>';
  61.  
  62. var wsUrl = 'http://192.168.211.28:9894/geogate/GeoGateWSServices';
  63. var sr = '<?xml version=\"1.0\" encoding=\"UTF-8\"?>' +
  64. '<soapenv:Envelope ' +
  65. 'xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ' +
  66. 'xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ' +
  67. 'xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" ' +
  68. 'xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" >' +
  69. '<soapenv:Header />' +
  70. '<soapenv:Body>' +
  71. '<adap:helloWorld xmlns:adap=\"http://adapter.ifb.silverlake.com\"/>' +
  72. '<adap:name>Ivan</name>' +
  73. '<adap:gentle>M</gentle>' +
  74. '</adap:helloWorld>' +
  75. '</soapenv:Body>' +
  76. '</soapenv:Envelope>';
  77.  
  78. $("#eee0").html(document.createTextNode(wsUrl));
  79. $("#eee1").html(document.createTextNode(sr));
  80. if(invocation)
  81. {
  82. invocation.open('POST', wsUrl, true);
  83. invocation.setRequestHeader('X-PINGOTHER', 'pingpong');
  84. invocation.setRequestHeader('Content-Type', 'application/xml');
  85. invocation.onreadystatechange = xmlhttphandler;
  86. invocation.send(sr);
  87. $("#eee2").html('pending...');
  88. }
  89. }
  90.  
  91. function callAjaxSoap() {
  92.  
  93.  
  94. var wsUrl = "http://www.webservicex.net/uszip.asmx";
  95. var sr = '<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetInfoByState xmlns="http://www.webserviceX.NET"> <USState>IL</USState> </GetInfoByState> </soap:Body> </soap:Envelope>';
  96.  
  97. var wsUrl = "http://www.webservicex.net/ConvertTemperature.asmx?op=ConvertTemp";
  98. var sr = '<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ConvertTemp xmlns="http://www.webserviceX.NET/"> <Temperature>40</Temperature> <FromUnit>degreeCelsius</FromUnit> <ToUnit>kelvin</ToUnit> </ConvertTemp> </soap:Body> </soap:Envelope>';
  99.  
  100. var wsUrl = "http://www.webservicex.com/globalweather.asmx";
  101. var sr = '<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetWeather xmlns="http://www.webserviceX.NET"> <CityName>string</CityName> <CountryName>string</CountryName> </GetWeather> </soap:Body> </soap:Envelope>';
  102.  
  103. var wsUrl = 'http://192.168.211.28:9894/geogate/GeoGateWSServices';
  104. var sr = '<?xml version=\"1.0\" encoding=\"UTF-8\"?>' +
  105. '<soapenv:Envelope ' +
  106. 'xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ' +
  107. 'xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ' +
  108. 'xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" ' +
  109. 'xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" >' +
  110. '<soapenv:Header />' +
  111. '<soapenv:Body>' +
  112. '<adap:helloWorld xmlns:adap=\"http://adapter.ifb.silverlake.com\"/>' +
  113. '<adap:name>Ivan</name>' +
  114. '<adap:gentle>M</gentle>' +
  115. '</adap:helloWorld>' +
  116. '</soapenv:Body>' +
  117. '</soapenv:Envelope>';
  118.  
  119. $("#eee0").html(document.createTextNode(wsUrl));
  120. $("#eee1").html(document.createTextNode(sr));
  121. console.log(sr);
  122. $.ajax({
  123. url: wsUrl,
  124. type: "POST",
  125. dataType: "xml",
  126. data: sr,
  127. crossDomain: true,
  128. processData: false,
  129. contentType: "text/xml; charset='utf-8'",
  130. beforeSend: setHeader,
  131. success: function onSuccess(r) {
  132. $("#eee2").html('onSuccess:' + r);
  133. console.log(r);
  134. },
  135. error: function onError(err) {
  136. $("#eee2").html('onError:' + err);
  137. console.log(err);
  138. }
  139. });
  140.  
  141. function setHeader(xmlhttp) {
  142. xmlhttp.setRequestHeader('Access-Control-Allow-Origin', '*');
  143. xmlhttp.setRequestHeader('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTIONS');
  144. xmlhttp.setRequestHeader('Access-Control-Allow-Headers', 'Content-Type, Content-Range, Content-Disposition, Content-Description');
  145. $("#eee2").html('pending...');
  146. }
  147. }
  148.  
  149. function callXMLHttpRequest01() {
  150. var wsUrl = "http://www.webservicex.net/ConvertTemperature.asmx?op=ConvertTemp";
  151. var sr = '<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ConvertTemp xmlns="http://www.webserviceX.NET/"> <Temperature>40</Temperature> <FromUnit>degreeCelsius</FromUnit> <ToUnit>kelvin</ToUnit> </ConvertTemp> </soap:Body> </soap:Envelope>';
  152.  
  153. var wsUrl = 'http://192.168.211.28:9894/geogate/GeoGateWSServices';
  154. var sr = '<?xml version=\"1.0\" encoding=\"UTF-8\"?>' +
  155. '<soapenv:Envelope ' +
  156. 'xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ' +
  157. 'xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ' +
  158. 'xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" ' +
  159. 'xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" >' +
  160. '<soapenv:Header />' +
  161. '<soapenv:Body>' +
  162. '<adap:helloWorld xmlns:adap=\"http://adapter.ifb.silverlake.com\"/>' +
  163. '<adap:name>Ivan</name>' +
  164. '<adap:gentle>M</gentle>' +
  165. '</adap:helloWorld>' +
  166. '</soapenv:Body>' +
  167. '</soapenv:Envelope>';
  168.  
  169. $("#eee0").html(document.createTextNode(wsUrl));
  170. $("#eee1").html(document.createTextNode(sr));
  171.  
  172. var xmlhttp = new XMLHttpRequest();
  173. xmlhttp.open("POST", wsUrl, true);
  174. xmlhttp.onload = function(e) {
  175. if (xmlhttp.readyState === 4) {
  176. if (xmlhttp.status === 200) {
  177. $("#eee2").html('onSuccess:' + xmlhttp.responseText);
  178. } else {
  179. $("#eee2").html('onError:' + xmlhttp.statusText);
  180. }
  181. }
  182. };
  183. xmlhttp.onerror = function(e) {
  184. $("#eee2").html('onError:' + xmlhttp.statusText);
  185. };
  186. xmlhttp.setRequestHeader('Content-Type', 'text/xml');
  187. xmlhttp.send(sr);
  188. $("#eee2").html('pending...');
  189. }
  190.  
  191.  
  192. function callXMLHttpRequest02() {
  193.  
  194. var wsUrl = "https://staging.api.psngr.co/api/users/login";
  195. var sr = JSON.stringify({
  196. "email": "",
  197. "password": ""
  198. });
  199.  
  200. var wsUrl = 'http://192.168.211.28:9894/geogate/GeoGateWSServices';
  201. var sr = '<?xml version=\"1.0\" encoding=\"UTF-8\"?>' +
  202. '<soapenv:Envelope ' +
  203. 'xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ' +
  204. 'xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ' +
  205. 'xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" ' +
  206. 'xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" >' +
  207. '<soapenv:Header />' +
  208. '<soapenv:Body>' +
  209. '<adap:helloWorld xmlns:adap=\"http://adapter.ifb.silverlake.com\"/>' +
  210. '<adap:name>Ivan</name>' +
  211. '<adap:gentle>M</gentle>' +
  212. '</adap:helloWorld>' +
  213. '</soapenv:Body>' +
  214. '</soapenv:Envelope>';
  215.  
  216.  
  217. $("#eee0").html(document.createTextNode(wsUrl));
  218. $("#eee1").html(document.createTextNode(sr));
  219.  
  220. var xmlhttp = new XMLHttpRequest();
  221. xmlhttp.open("POST", wsUrl, true);
  222. xmlhttp.onload = function(e) {
  223. if (xmlhttp.readyState === 4) {
  224. if (xmlhttp.status === 200) {
  225. $("#eee2").html('onSuccess:' + xmlhttp.responseText);
  226. } else {
  227. $("#eee2").html('onError:' + xmlhttp.statusText);
  228. }
  229. }
  230. };
  231. xmlhttp.onerror = function(e) {
  232. $("#eee2").html('onError:' + xmlhttp.statusText);
  233. };
  234. xmlhttp.send(sr);
  235. $("#eee2").html('pending...');
  236. }
  237.  
  238. function soapByJasper2() {
  239. var wsUrl = "http://www.webservicex.net/ConvertTemperature.asmx?op=ConvertTemp";
  240. var sr = '<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ConvertTemp xmlns="http://www.webserviceX.NET/"> <Temperature>40</Temperature> <FromUnit>degreeCelsius</FromUnit> <ToUnit>kelvin</ToUnit> </ConvertTemp> </soap:Body> </soap:Envelope>';
  241.  
  242. var wsUrl = 'http://192.168.211.28:9894/geogate/GeoGateWSServices';
  243. var sr = '<?xml version=\"1.0\" encoding=\"UTF-8\"?>' +
  244. '<soapenv:Envelope ' +
  245. 'xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ' +
  246. 'xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ' +
  247. 'xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" ' +
  248. 'xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" >' +
  249. '<soapenv:Header />' +
  250. '<soapenv:Body>' +
  251. '<adap:helloWorld xmlns:adap=\"http://adapter.ifb.silverlake.com\"/>' +
  252. '<adap:name>Ivan</name>' +
  253. '<adap:gentle>M</gentle>' +
  254. '</adap:helloWorld>' +
  255. '</soapenv:Body>' +
  256. '</soapenv:Envelope>';
  257.  
  258. $("#eee0").html(document.createTextNode(wsUrl));
  259. $("#eee1").html(document.createTextNode(sr));
  260.  
  261. var postOptions = {
  262. hostname: 'www.webservicex.net',
  263. port: 80,
  264. path: '/ConvertTemperature.asmx?wsdl',
  265. method: 'POST',
  266. headers: {
  267. 'Host': 'server.com',
  268. 'Content-Type': 'text/xml;charset=utf-8',
  269. 'Content-Length': sr.length,
  270. 'SOAPAction': "",
  271. }
  272. };
  273.  
  274. var req = http.request(postOptions, function(res) {
  275. console.log('STATUS: ' + res.statusCode);
  276. console.log('HEADERS: ' + JSON.stringify(res.headers));
  277. res.setEncoding('utf8');
  278. res.on('data', function(chunk) {
  279. console.log('BODY: ' + chunk);
  280. $("#eee2").html('onSuccess:' + chunk);
  281. });
  282. });
  283. $("#eee2").html('pending...');
  284. req.on('error', function(e) {
  285. console.log('problem with request: ' + e.message);
  286. $("#eee2").html('onError:' + e);
  287. });
  288.  
  289. // write data to request body
  290. req.write(sr);
  291. req.end();
  292.  
  293. }
  294. </script>
  295. <p>----------------------------------------</p>
  296. Endpoint<br>
  297. <p>----------------------------------------</p>
  298. <p id="eee0">Connecting to...</p>
  299. <p>----------------------------------------</p>
  300. Request<br>
  301. <p>----------------------------------------</p>
  302. <p id="eee1">pending...</p>
  303. <p>----------------------------------------</p>
  304. Response<br>
  305. <p>----------------------------------------</p>
  306. <p id="eee2">nothing</p>
  307. </body>
  308.  
  309. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement