• 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: email@hidden
  • Date: Thu, 25 Jan 2007 12:20:14 -0000 (UTC)
  • Importance: Normal

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

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?WSMa keStubsWSGenerateObjCallingASPNETWebservice

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 *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);
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 = (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.

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")
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
email@hidden


Alexander Hartner
email@hidden

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


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: re: Internet Connect Notification on failure
  • Next by Date: DHCP Inform
  • Previous by thread: re: Internet Connect Notification on failure
  • Next by thread: DHCP Inform
  • Index(es):
    • Date
    • Thread