I set out with the goal of calling a EJB3 Stateless Session bean via a webservice. I started out by declaring a session bean and annotating it as a webservice(see below). Once deployed and tested I generated stubs using
It generated 4 files (2 x .h and 2 x .m). After a bit of searching around I figured I should be using the following code to invoke my service :
NSDictionary * params = [NSDictionary dictionary]; id result = [SynchroniserBeanService synchroniseNothing:params]; NSLog(@"Result : %@",result);
This however did not produce the result I expected. After some further googling I came accross the following article which suggested a solution:
In the end I didn't use the generated stubs and got the following code to work. I am still battling passing objects as parameters including user defined types. If anybody has an example of getting either the stubs working or how to pass parameters I would be very grateful.
WSMethodInvocationRef rpcCall; NSString *me
thodName = @"synchroniseNothing"; NSDictionary * params = [NSDictionary dictionary]; NSDictionary *result; rpcCall = WSMethodInvocationCreate ((CFURLRef) rpcURL, (CFStringRef) methodName, kWSSOAP2001Protocol); WSMethodInvocationSetProperty(rpcCall, kWSSOAPBodyEncodingStyle, (NSString*) kWSSOAPStyleDoc); WSMethodInvocationS
etParameters (rpcCall, (CFDictionaryRef) params, NULL); NSString * soapActionKey = @"SOAPAction"; NSDictionary * headers = [[NSDictionary dictionaryWithObjects:&soapAction forKeys:&soapActionKey count:1] retain]; WSMethodInvocationSetProperty(rpcCall, kWSHTTPExtraHeaders, headers); [headers release]; result = (NSDicti
onary *) (WSMethodInvocationInvoke (rpcCall)); NSEnumerator *enumerator = [result keyEnumerator]; id key; id value; while ((key = [enumerator nextObject])) { value = [result objectForKey:key]; NSLog(@"Result : %@ -
> %@",key,value); }
During my searching around I also put the following AppleScript together which might be useful to some developers.
end tell
// EJB3 Session Bean package com.j2anywhere.synchomatic; import javax.ejb.Stateless; import javax.jws.WebMethod; import javax.jws.WebService; @Stateless @WebService(serviceName = "SynchroniserBean") pu
blic class SynchroniserBean implements com.j2anywhere.synchomatic.SynchroniserRemote, com.j2anywhere.synchomatic.SynchroniserLocal { @WebMethod(operationName="synchroniseNothing") public String synchroniseNothing() { System.out.println("Synchronising Nothing"); return "THIS IS A WEB SERVICE"; } @WebMethod(operationName="synchroniseText") public String synchroniseText(String input) { System.out.println("Synchronising Text"); return input.toUpperCase(); } @WebMethod(operationName="synchronise") public String synchronise(Contact[] people) { System.out.println("Synchronising Objects"); return "Processed : "+people.length+" contacts"; } }
Alexander Hartner
Does a good farmer neglect a crop he has planted? Does a good teacher overlook even the most humble student? Does a good father allow a single child to starve? Does a good programmer refuse to maintain his code? - The T
ao of Programming
|