java - Call Web Service from AJAX -


i've looked through number of posts/tutorials on calling ws via ajax, still not able this. not environment matters but... wrote java class in eclipse, i'm running on glassfish, , i'm able hit endpoint via soapui.

java class:

package com.tester.gf;  import java.util.arraylist; import java.util.list; import javax.jws.webservice;  @webservice public class glassfishtestapp {      public list<string> getbrands() {         list<string> brands = new arraylist<>();         brands.add("chevrolet");         brands.add("dodge");         brands.add("ford");         return brands;     } } 

endpoint:

localhost:8080/glassfishtestapp/glassfishtestappservice?wsdl 

when load following web page, see "error: " displayed in .

<html>     <head>         <title>soap ws test</title>         <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>         <script>             $(document).ready(function () {                 $.ajax(                     type: 'get',                     url: 'http://localhost:8080/glassfishtestapp/glassfishtestappservice',                     success: function (data) {                         $('#results').text(data);                     },                     error: function (request, status, error) {                         $('#results').text('error: ' + request.responsetext);                     }                 });             });         </script>     </head>     <body>         <div id="results"></div>     </body> <html> 

soapui request:

<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:gf="http://gf.tester.com/">     <soapenv:header/>         <soapenv:body>             <gf:getbrands/>         </soapenv:body> </soapenv:envelope> 

soapui respose:

<s:envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">     <s:body>         <ns2:getbrandsresponse xmlns:ns2="http://gf.tester.com/">              <return>chevrolet</return>              <return>dodge</return>              <return>ford</return>         </ns2:getbrandsresponse>     </s:body> </s:envelope> 

thanks input on this!

got it!

var soapmessage =     '<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:gf="http://gf.tester.com/">' +         '<soapenv:header/>' +             '<soapenv:body>' +                 '<gf:getbrands/>' +             '</soapenv:body>' +     '</soapenv:envelope>';  $.ajax({     url: "/glassfishtestapp/glassfishtestappservice",     type: "post",     datatype: "xml",     contenttype: "text/xml; charset=\"utf-8\"",     headers: {         soapaction: "/glassfishtestapp/glassfishtestappservice/getbrands"     },     data: soapmessage,     success: function(data) {         $('#results').text(data);     },     error: function (request, status, error) {         $('#results').text('error: ' + error);     } }); 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -