views:

343

answers:

1

I have an app that makes SOAP calls. To keep the UI from blocking, we are putting each SOAP call into a subclass of NSOperation. This works well, but we have a ton of different types of SOAP calls. So if we use 3 WSDLs each with 10 Ports or Operations, then we 30 different calls in SOAP and if we put each of those in a thread using NSOperation, we end up with 30 NSOperation subclasses.

This may not be a bad thing, but we are trying to create a reusable library, so we have one object per WSDL which encapsulates the calls. This is nice because we are using WSDL2ObjC and this encapsulates all that logic. But it seems odd then to have a nice api that we wrap calls to in these many NSOperations. Also, we are doing the threading in the api itself, so that the invoker can use it how he/she sees fit.

Any suggestions would be great.

+1  A: 

If I'm understanding you correctly you already have objects that encapsulate the calls to the SOAP service and you just want to cut down on the NSOperation subclasses.

Have you checked into NSInvocationOperation? It's a subclass of NSOperation that let's you make a message send to an object as an NSOperation call. So you still getting the non blocking operation, but you don't need multiple subclasses of NSOperation.

criscokid
I did. I was hoping to use the operation would send a notfication when it was complete. Maybe I could add the notification to the api and that is how return values are retrieved, but that seems like a bad design. I will think some more to see if this will work. I'll work on that and see what I can come up with. Thanks.
Brian
The issue have with the NSIvocationOperation is that it only allows you to pass one object. Is there a work around or some sort of dynamic binding I can do to get around this?
Brian
The best way around the one object problem that I can think of is just making another object that can hold all the stuff you need to pass.I'll have to think about the getting notified part. Do all of your WSDL objects have pretty much the same method?
criscokid
What I ended up with is creating a NSInvocation object ( new to me ) that you set up with the selector, target, and any and all arguments. Then you use NSInvocationOperation initWithInvocation: and give it your invocation object. Then, I created 2 copies of each method in my api --- authenticate and _threaded_authenticate. The idea is if calling from a thread and you can't have a return value, call the _threaded_ method, which basically calls the normal method, and does what ever is needed with the return and its turning into a notification. Thanks for pointing me back down this road.
Brian
Incase NSInvocation is new to you - an example : http://theocacao.com/document.page/264
Brian