• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Cocoa, WebServices and J5EE working in harmony (almost)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cocoa, WebServices and J5EE working in harmony (almost)


  • Subject: Cocoa, WebServices and J5EE working in harmony (almost)
  • From: Alexander Hartner <email@hidden>
  • Date: Tue, 16 Jan 2007 01:51:15 +0000

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

/Developer/Tools/WSMakeStubs -x ObjC -dir syncClient/SyncClientWS/ - name SyncClient -url "http://localhost:8080/SynchroniserBean/ SynchroniserBean?WSDL"

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:

http://www.cocoadev.com/index.pl? WSMakeStubsWSGenerateObjCallingASPNETWebservice

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;
NSURL *rpcURL = [NSURL URLWithString: @"http://localhost:8080/ SynchroniserBean/SynchroniserBean"];
NSString *methodName = @"synchroniseNothing";
NSDictionary * params = [NSDictionary dictionary];
NSDictionary *result;
rpcCall = WSMethodInvocationCreate ((CFURLRef) rpcURL, (CFStringRef) methodName, kWSSOAP2001Protocol);
WSMethodInvocationSetProperty(rpcCall, kWSSOAPBodyEncodingStyle, (NSString*) kWSSOAPStyleDoc);
WSMethodInvocationSetParameters (rpcCall, (CFDictionaryRef) params, NULL);
WSMethodInvocationSetProperty(rpcCall, kWSSOAPMethodNamespaceURI, @"http://synchomatic.j2anywhere.com/";);
NSString * soapActionKey = @"SOAPAction";
NSString * soapAction = @"http://synchomatic.j2anywhere.com/ synchroniseNothing";
NSDictionary * headers = [[NSDictionary dictionaryWithObjects:&soapAction forKeys:&soapActionKey count:1] retain];
WSMethodInvocationSetProperty(rpcCall, kWSHTTPExtraHeaders, headers);
[headers release];
result = (NSDictionary *) (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.


tell application "http://localhost:8080/SynchroniserBean/ SynchroniserBean"
call soap {method name:"synchroniseNothing", method namespace uri:"http://synchomatic.j2anywhere.com/";, parameters:{}, SOAPAction:"http://synchomatic.j2anywhere.com/synchroniseNothing"}
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")
public 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
email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Bindling to array of NSImage
  • Next by Date: Re: setKeys + array operators = slowdown
  • Previous by thread: Re: Bindling to array of NSImage
  • Next by thread: Showing time differences. NSNumberFormatter?
  • Index(es):
    • Date
    • Thread