facebook

Consuming a web service in Javascript (AJAX)

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #258182 Reply

    Hi all,
    I’ve created a web service using the wizard, and it runs fine in the Web Service Explorer. All tutorials demonstrate creating a Java client, but I really want to consume the web service using AJAX. Can XFire web services be tested in the browser using GET (and passing a query string with the parameters?) What is the proper URL for accessing a web service (I’ve seen examples that seem to pass the method as part of the query string… http://wsURL?method=…) The web service name is UserThings and the method is getUserThings. For the example, the WSDL URL is http://localhost:8080/webServices/services/UserThings?WSDL . I’ve tried many combinations of URLS to test in the browser, but no luck. Please assist…

    #258319

    Riyad Kalla
    Member

    Moving to OT > Soft Dev.

    #258406

    well, here’s what i’ve found out… it seems that the XFire Web services don’t support the GET method and require a full SOAP document (as opposed to simple query string parameters). i was able to consume my web service by using POST and creating the SOAP document completely (i actually used SOAP UI and copy / pasted the soap request into a javascript string). in addition the web service method was called by making the top level element in the SOAP body be the name of the method. for example, my web service name was UserThings and the method was getUserThings (taking parameter user_id, which X-Fire compiles into in0 — i don’t know why they do this and it seems pretty stupid, but, oh well….) Here was the SOAP request which I passed that worked:

    <soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/&#8221; xmlns:web=”http://webServices”&gt;
    <soapenv:Body>
    <web:getUserThings>
    <web:in0>1</web:in0>
    </web:getUserThings>
    </soapenv:Body>
    </soapenv:Envelope>

    The method getUserThings had to be the top level element in the body. There are probably a few javascript libraries out there that do SOAP parsing, or you can make a simple one and replace the inputs as necessary.

    #258410

    Riyad Kalla
    Member

    Very cool find, thanks for following up for others.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Consuming a web service in Javascript (AJAX)

You must be logged in to post in the forum log in