calling web services from javascript

Discussion in 'Apache' started by zibididu, Apr 1, 2008.

  1. #1
    Hi, this isnt directly related to Apache but I didnt exactly know where to post it, since I am a new member.

    I have developed a webservice in java using NetBeans IDE and tested it using the IDE generated service tester. Now I need to call the web service from javascript. I am using the following code:

    function testWebService(){
    try {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
    } catch (e) {
    alert(e);
    return false;
    }

    var params = new Array();
    params[0] = new SOAPParameter("peter","username");
    params[1] = new SOAPParameter("paul","password");

    var soapCall = new SOAPCall();
    soapCall.transportURI = 'http://localhost:8081/TestApplication/TestWSService';
    soapCall.encode(0, "loginUser", 'http://test/', 0, null, params.length, params);
    var response = new SOAPResponse();
    response = soapCall.invoke();
    alert(response.body.textContent);
    }

    This method is supposed to return true or false. However, it returns a NullPointerException. This exception is repeated for every Webmethod requiring some form of input parameter. However, when I call a test method "getTime" (which need no input), the response is correct.

    Does anyone have any idea what could be the problem? You would save my life!! Thanks
     
    zibididu, Apr 1, 2008 IP
  2. Arkserver

    Arkserver Banned

    Messages:
    2,533
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I've coded a Java webservice using EJB3.0 and JSP frontend but i never heard of javascript that could call the webservice. (but then again my knowledge about javascript is limited)

    Without seeing your webservice as a whole i can't spot where the error comes from. My advice is to system out every line you think the error might occour and see if you can fix it yourself.
     
    Arkserver, Apr 2, 2008 IP