#1 2016-09-29 15:02:38

dexter
Member
Registered: 2015-04-24
Posts: 53

Calling mORMot webservice from Java

Hi,

I'm trying to consume a mORMot webservice from java.
In documentation is mentioned that mORMot supports JSON-RPC.
Is it about the official JSON-RPC 2.0 (https://en.wikipedia.org/wiki/JSON-RPC) ?

I'm trying to call Calculator.Add method from 14 - Interface based services examples (removed authentification from server for the time being) and I get http error code 400, "Bad request".

The JSON request is built according to JSON-RPC 2.0 standards: {"id":"req-001","method":"Add","params":{"n1":1,"n2":2},"jsonrpc":"2.0"}
Tried {"id":"req-001","method":"Calculator.Add","params":{"n1":1,"n2":2},"jsonrpc":"2.0"} as well with same result.

Is this format accepted by mORMot? If not, how shall I build the JSON request in order to get the expected result "{"result":[3]}"?

Or,

is there any other option to call it?

Regards,
Alex.

Last edited by dexter (2016-09-29 15:03:47)

Offline

#2 2016-10-04 14:47:27

willo
Member
From: Cape Town, South Africa
Registered: 2014-11-15
Posts: 67
Website

Re: Calling mORMot webservice from Java

Dexter,

I've never tried using it like that. From our use cases it's always been RESTfull, so the method to call is encoded in the URI, while the paramters are either POSTed or encoded as GET parameters (.../calculator/add?n1=1&n2=2)

Hope this helps

Offline

#3 2016-10-05 08:19:49

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Calling mORMot webservice from Java

It is JSON-RPC like, not true JSON-RPC, and to be honnest, there are several implementations of JSON-RPC around.
So the mORMot format is not exactly what you expect.

For the answer, try to set the ResultAsJSONObject/ResultAsJSONObjectWithoutResult options.

Offline

#4 2016-10-05 11:48:10

dexter
Member
Registered: 2015-04-24
Posts: 53

Re: Calling mORMot webservice from Java

willo wrote:

Dexter,

I've never tried using it like that. From our use cases it's always been RESTfull, so the method to call is encoded in the URI, while the paramters are either POSTed or encoded as GET parameters (.../calculator/add?n1=1&n2=2)

Hope this helps

Yes, it's working this way. Thanks.

Last edited by dexter (2016-10-05 11:49:26)

Offline

#5 2016-10-13 19:12:40

DKA
Member
Registered: 2016-07-05
Posts: 39

Re: Calling mORMot webservice from Java

Hi,

I'm Newbie and I wonder if there is a way to find the URI string just looking to the server code.

For example, Project06Sever (remote JSON REST Service), I tried (on EWB) : http://localhost/Service/Sum?A=1&B=4...No success

Offline

#6 2016-10-13 19:54:41

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Re: Calling mORMot webservice from Java

The TSQLRest class has a 
   property Services: TServiceContainer read fServices;
   which you can access to the interface-based services list, so can get a list such as:

[{
"contract" : "MyService",
"implementation" : "shared",
"methods" : [{
		"method" : "Add",
		"arguments" : [{
				"argument" : "Self",
				"direction" : "in",
				"type" : "self"
			}, {
				"argument" : "n1",
				"direction" : "in",
				"type" : "integer"
			}, {
				"argument" : "n2",
				"direction" : "in",
				"type" : "integer"
			}, {
				"argument" : "Result",
				"direction" : "out",
				"type" : "integer"
			}
		]
	}, {
		"method" : "GetSampleRecord",
		"arguments" : [{
				"argument" : "Self",
				"direction" : "in",
				"type" : "self"
			}, {
				"argument" : "id",
				"direction" : "in",
				"type" : "int64"
			}, {
				"argument" : "SampleRecord",
				"direction" : "out",
				"type" : "TSQLSampleRecord"
			}, {
				"argument" : "Result",
				"direction" : "out",
				"type" : "boolean"
			}
		]
	}
]
}]

Offline

#7 2016-10-17 16:50:51

DKA
Member
Registered: 2016-07-05
Posts: 39

Re: Calling mORMot webservice from Java

Thanks WarleyAlex. In witch project did you copy/paste this?

Offline

Board footer

Powered by FluxBB