I'm a total newbie Mac programmer having worked for years as a developer using Microsoft technologies. I've only written one Objective-C app, a simple 'hello world' program.
For my second app I want to connect to a simple test web service I've written using Microsoft VB.NET. This web service has two functions: Sum and Product. They each accept two numeric arguments and return, you guessed it, the sum or product of the two values. The web service works fine from a Microsoft app but I can't get it to work from my Objective-C app. I'm using code I copied from this forum and have modified, but clearly my modification is wrong The web service is being activated but it always returns an answer of zero which makes me suspect the parameters aren't being passed in correctly. I'm using Xcode 3.1 on Leopard.
1) How can I view the XML that's sent to, and received back from, the web service?
2) Can anyone see what's wrong with this code? It just takes the two parameters from two combo boxes, and writes the answer to a textview box.
Thanks guys. I've spent over a day on this without success.
For my second app I want to connect to a simple test web service I've written using Microsoft VB.NET. This web service has two functions: Sum and Product. They each accept two numeric arguments and return, you guessed it, the sum or product of the two values. The web service works fine from a Microsoft app but I can't get it to work from my Objective-C app. I'm using code I copied from this forum and have modified, but clearly my modification is wrong The web service is being activated but it always returns an answer of zero which makes me suspect the parameters aren't being passed in correctly. I'm using Xcode 3.1 on Leopard.
1) How can I view the XML that's sent to, and received back from, the web service?
2) Can anyone see what's wrong with this code? It just takes the two parameters from two combo boxes, and writes the answer to a textview box.
Thanks guys. I've spent over a day on this without success.
Code:
- (IBAction) doProduct: sender
{
NSString *myArg1 = [Arg1 stringValue];
NSLog(@"dblArg1 = %@", myArg1);
NSString *myArg2 = [Arg2 stringValue];
NSLog(@"dblArg2 = %@", myArg2);
WSMethodInvocationRef rpcCall;
NSURL *rpcURL = [NSURL URLWithString: @"http://www.vbsampler.net/testwebservice/maths.asmx"];
NSString *methodName = @"Product";
NSString *nameSpace = @"http://www.vbsampler.net/";
NSArray *vals = [NSArray arrayWithObjects: myArg1, myArg2, nil];
NSArray *keys = [NSArray arrayWithObjects:@"dblArg1", @"dblArg2", nil];
NSDictionary *params = [NSDictionary dictionaryWithObjects: vals forKeys: keys];
NSArray *paramOrder = [NSArray arrayWithObjects:@"dblArg1", @"dblArg2", nil];
//NSDictionary *result;
NSDictionary *headers = [NSDictionary dictionaryWithObject:@"http://tempuri.org/Product" forKey:@"SOAPAction"];
rpcCall = WSMethodInvocationCreate((CFURLRef) rpcURL, (CFStringRef) methodName, kWSSOAP2001Protocol);
WSMethodInvocationSetParameters (rpcCall, (CFDictionaryRef) params, (CFArrayRef)paramOrder);
WSMethodInvocationSetProperty(rpcCall, (CFStringRef) kWSHTTPExtraHeaders, (CFTypeRef) headers);
// for good measure, make the call follow redirects.
WSMethodInvocationSetProperty(rpcCall, kWSHTTPFollowsRedirects, kCFBooleanTrue);
WSMethodInvocationSetProperty(rpcCall, kWSSOAPMethodNamespaceURI, (CFStringRef) nameSpace);
// set debug props
WSMethodInvocationSetProperty(rpcCall, kWSDebugIncomingBody, kCFBooleanTrue);
WSMethodInvocationSetProperty(rpcCall, kWSDebugIncomingHeaders, kCFBooleanTrue);
WSMethodInvocationSetProperty(rpcCall, kWSDebugOutgoingBody, kCFBooleanTrue);
WSMethodInvocationSetProperty(rpcCall, kWSDebugOutgoingHeaders, kCFBooleanTrue);
NSDictionary *result = (NSDictionary *) (WSMethodInvocationInvoke(rpcCall));
if (WSMethodResultIsFault ((CFDictionaryRef) result)) {
NSLog(@"result = %@", [result objectForKey: (NSString *) kWSFaultString]);
[txtAnswer setString: @"Error"];
}
else
{
[txtAnswer setString: [result objectForKey:@"ProductResult"]];
NSLog(@"result = %@", [result objectForKey:@"ProductResult"]);
}
}