Showing posts with label wikibooks. Show all posts
Showing posts with label wikibooks. Show all posts

2006/11/05

Calculator.java revisted

As discussed yesterday, while implementing the CalulatorService, doubles are not good enough for precision —see the following lecture recommended by Ken Anderson: Floating point.

To fix this problem, the first thing to do is to re-implement the Calculator.java object to accept and return strings, instead of doubles, and operate with BigDecimals:
import java.math.BigDecimal;

public class Calculator extends Object {

public static String add(String addend1, String addend2) {

BigDecimal x = new BigDecimal(addend1);
BigDecimal y = new BigDecimal(addend2);
BigDecimal z = x.add(y);

return z.toString();
}

Re-make the stubs and then, re-implement our CPO.m to use, also, strings:
@implementation CPO
- (IBAction)add:(id)sender
{
id x = [[form cellAtIndex:0] stringValue];
id y = [[form cellAtIndex:1] stringValue];
id z = [CalculatorService add:x in_addend2:y];

[[form cellAtIndex:2] setStringValue:z];
}
@end

I wonder... how does types travel through the Web Service protocols?
Let us find out...

2006/10/04

Finally

It was much more easy than I thought...
following LeBer's advice, I went to the wikibooks and found that I better use the tool /Developer/Tools/WSMakeStubs.
It creates two objects (in my case Account.[hm] and WSGeneratedObject.[hm]) which I simply imported in a new project and, via some controller, they can invoke the service... I had to write the following two lines of code to see what was going on:

@implementation CPO
- (IBAction)servicio:(id)sender
{
id valor = [AccManagerService newAcc:[nombre stringValue]
in_who:[quien stringValue]];
NSRunAlertPanel(@"Servicio",
@"El valor es = %@",
nil,nil,nil,valor);
}
@end


Nice and beauty...

2006/09/17

I am back...

I had been away trying to tame a PLC which call for me to remember how to code in binary... finally the beast surrender.

So, now I have again time to continue my experiments with Web Services. An e-friend from WOdev-list at apple (David LeBer) suggests the following lecture:
Consuming with WebServicesCore.framework
I will take a look and come back later!