Accessing a JBoss Web Service using JavaScript (AJAX) - A Comprehensive Guide

After experimenting with JBOSS's Web Services, I have successfully set up the following:

http://127.0.0.1:8080/IM/TestService?wsdl

My next challenge is to call Web Methods from that Web Service using JavaScript.

For example, if there's a web method called foo in TestService, how can I use ajax to invoke it?

I attempted to access the method through

http://127.0.0.1:8080/IM/TestService/foo
, but encountered an HTTP Status 404 error.

Answer №1

In my JavaScript code, I have implemented a way to invoke Web Methods from the JBoss Web Service.

Required Libraries


var WS = function (url, ns, nsName) {
    return function (method, parameters, callback) {
        var i, j, para, soapBody = new SOAPObject(method), sr, response;
        soapBody.ns = {
            name: nsName,
            uri: ns
        };
        if (typeof parameters === "function") {
            callback = parameters;
        } else if (parameters && parameters.length) {
            for (i = 0, j = parameters.length; i < j; ++i) {
                para = parameters[i];
                soapBody.appendChild(new SOAPObject(para.name)).val(para.value);
            }
        }
        sr = new SOAPRequest(method, soapBody);
        SOAPClient.Proxy = url;
        SOAPClient.SendRequest(sr, function (r) {
            response = r.Body[0][method + "Response"][0]["return"][0]["Text"];
            if (callback) {
                callback.call(sr, response);
            }
        });
    }
};

How to Use

var ws = WS("http://127.0.0.1:8080/IM/TestService", "http://wservices/", "ns2");

ws("foo", [{name: "name", value:"dreas"}], function (r) {
    console.log(r);
});

Note: This code has not been extensively tested, so be cautious when using it

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Next.js endeavors to interpret MDX files as basic JavaScript code

Currently, I'm in the process of creating a website using Next.js and incorporating (local) MDX files for my content. However, I've encountered an issue where whenever I add a .MDX file to my source tree and attempt to navigate to it, Next.js thr ...

Filling JTextField with the most recent KeyStroke input

In my UI, the use case involves populating two JTextField components by double clicking items in a JList. Currently, this is achieved by using a JCheckBox to determine which text field should be populated based on selection. While this method works perfect ...

When I click the button, the page goes blank and keeps loading endlessly

http://jsfiddle.net/iansan5653/7EPjH/17/ <head> <script type='text/javascript' src='https://www.google.com/jsapi'></script> <script type="text/javascript"> function chart() { var pressure; ...

Is there a way to retrieve the filename from a callback in gulp-contains?

Currently, I am utilizing gulp-contains to scan for a specific string. If the target string is found, I intend to trigger an error message stating "String found in file abc." The 'file' parameter holds the entire object comprising filename + Buff ...

Having some trouble with node.js and the fs module when checking if a file exists. Let

I'm a bit confused about the various methods in Node.js to check if a file exists using fs(). One option is to use fs.readFile(): fs.readFile('somefile.html', function (err, data) { if (err) { /* file doesn't exist */ } else { /* ...

Choosing the relevant kendo row on two different pages

I am facing a situation where I have a Kendo grid displayed on a dashboard page. Whenever a user selects a row in this grid, I need to load the same row in another Kendo grid on a separate ticket page to showcase the details of that particular ticket. The ...

Design a CreateJS/EaselJS website, comprised of multiple web pages, that is not focused on gaming

I have developed an existing HTML5 Canvas webpage composed of multiple pages, buttons, and hotspots using pure canvas javascript code. The reason I refer to 'buttons' and 'hotspots' in quotes is because I created them from scratch in j ...

Retrieve the attributes of a class beyond the mqtt callback limitation

Currently, I am utilizing npm-mqtt to retrieve information from a different mqtt broker. My objective is to add the obtained data to the array property of a specific class/component every time a message is received. However, I'm facing an issue wher ...

GeoJson with timestamp and marked directional indicator

I am looking to create an animation of a boat traveling along a specific route. Currently, I am able to display the route as a line and the boat as a circle using TimestampedGeoJson: # circle with following line features = [ { 'type': ...

Encountering an issue with connecting nodejs to mqlight

I have been working with nodejs and mqlight to test out some sample code provided on https://www.npmjs.com/package/mqlight. My current setup consists of nodejs 5.5.0 and npm version 3.3.12. To install mqlight, I used the command npm install mqlight. ...

Leveraging AWS Aurora data API for Java in conjunction with the AWS SDK for Java 2.x

Recently, I've been working on utilizing the Aurora AWS data API within my Lambda functions to carry out operations like inserting and updating data in tables. However, I've hit a roadblock as the official documentation only covers using AWS SDK ...

Using Vue.js to make an AJAX request to an API that returns a list in JSON format

I am attempting to utilize an AJAX call with the free API located at that returns a list in JSON format. My goal is to display the result on my HTML using Vue.js, but unfortunately, it doesn't seem to work as expected. This is my JavaScript code: va ...

What is the best way to trigger a function once another one has finished executing?

After opening the modal, I am creating some functions. The RefreshBirths() function requires the motherId and fatherId which are obtained from the getDictionaryMother() and getDictionaryFather() functions (these display my mothers and fathers on the page s ...

Which Linux Distribution is Most Suitable for Web Development?

Interested in getting started with HTML and AJAX on a Linux operating system. Seeking recommendations for a distribution that includes: A Local Host Admin interface similar to PHPmyAdmin An IDE suitable for developing Javascript... etc ...

In the event of any unexpected errors while utilizing an API, a ticket will be automatically generated on Jira through the use of Vue.js

After successfully hitting the API through Postman and creating a ticket on Jira, I encountered a CORS error when attempting to do the same using an index.js file in VueJS. The flow is unclear to me as generating a demo error results in nothing being sho ...

Detach attention from TextField select component in Material UI and React through manual means

When I create a select input using the TextField component from Material-UI library, I need to manually remove focus after an option is selected. I attempted to achieve this by using a reference to the TextField with the 'inputRef' prop. However, ...

Encountering difficulties during the migration process from a JavaScript to a TypeScript React Component

I've encountered some challenges with configuring TypeScript in my project. Initially, I developed my application using plain JavaScript. However, eager to learn TypeScript, I decided to convert my JavaScript project into a TypeScript one. To achiev ...

When trying to access the DOM from another module in nwjs, it appears to be empty

When working with modules in my nwjs application that utilize document, it appears that they are unable to access the DOM of the main page correctly. Below is a simple test demonstrating this issue. The following files are involved: package.json ... "ma ...

Is XMLHttpRequest just sitting idle...?

As a newcomer to the world of javascript and AJAX, I've been stuck on a single problem for the past 8 hours. Despite my best efforts, I just can't seem to figure out what's going wrong. On my website, I have an image with an onclick event ca ...

Changing a single image within a v-for loop of images in Vue

I am currently working with an array in Vue where I am using v-for to create 3 columns of information. Each column includes an image, and I would like to be able to change only the specific image that is being hovered over without affecting any others. How ...