3

I'm trying to use jsonRpcService to print a value on console. Just for testing. But when i call the method i recieve this error on browser console:

POST http://localhost/Teste.nsf/Teste.xsp/RpcService?$$viewid=!ei0pdt23xx! 400 (Bad Request)
Error: Unable to load /Teste.nsf/Teste.xsp/RpcService?$$viewid=!ei0pdt23xx! status:400(…)  
Unable to load /Teste.nsf/Teste.xsp/RpcService?$$viewid=!ei0pdt23xx! status:400  
Error: Unable to load /Teste.nsf/Teste.xsp/RpcService?$$viewid=!ei0pdt23xx! status:400(…)  
Error: Unable to load /Teste.nsf/Teste.xsp/RpcService?$$viewid=!ei0pdt23xx! status:400(…)

Here is the image of the error: https://i.stack.imgur.com/T5ekl.jpg

I already searched a lot for one solution to this error but i got nothing.

This is the code that i'm using:

<xe:jsonRpcService id="jsonRpcService1" serviceName="metodos"
    pathInfo="RpcService">
<xe:this.methods>
    <xe:remoteMethod name="teste" script="print('teste')"></xe:remoteMethod>
</xe:this.methods>
</xe:jsonRpcService>

And this is the code that i'm using on console to call the function

metodos.teste()

Does anyone knows what i'm doing wrong?

Thanks

Bruno Dias
  • 83
  • 1
  • 6
  • "metodos" is the name of the jsonRpcService. The browser recognize it and if i use "metodos.teste()" the function will be called, but after this the service returns an error and because of that error i cant handle the return of the function. – Bruno Dias Aug 31 '16 at 21:14

1 Answers1

1

You have to return a value in your script and your client has to wait for answer with a callback function.

This is a working example:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view
    xmlns:xp="http://www.ibm.com/xsp/core"
    xmlns:xe="http://www.ibm.com/xsp/coreex">
    <xe:jsonRpcService
        id="jsonRpcService1"
        serviceName="metodos"
        pathInfo="RpcService">
        <xe:this.methods>
            <xe:remoteMethod
                name="teste"
                script="return 'teste'">
            </xe:remoteMethod>          
        </xe:this.methods>
    </xe:jsonRpcService>

    <xp:button
        value="Test"
        id="button1">
        <xp:eventHandler
            event="onclick"
            submit="false">
            <xp:this.script><![CDATA[
                var deferred = metodos.teste();
                deferred.addCallback(function(result) {
                    alert(result);
                });]]></xp:this.script>
        </xp:eventHandler>
    </xp:button>

</xp:view>

When you click on button "Test" an alert box shows up with the message "teste".

You can add additional code before return 'teste' like your original print('teste'). The script just has to return something...

Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
  • Thank you, That was the problem. – Bruno Dias Sep 01 '16 at 11:33
  • Knut, On my local application this code works, but when i put it on another application that is on a server the code returns me the same error. Do you know any possible cause for this? – Bruno Dias Sep 01 '16 at 13:36
  • 1
    I think this error is caused by some server config. I'll try to solve it. If i succeed i'll post here. – Bruno Dias Sep 01 '16 at 13:52
  • Doing tests here i realize that if i restart the http server the code works great, but when i login in any database on the server the code stops to work even if i log out. – Bruno Dias Sep 01 '16 at 16:36