Hi,
I am trying to get my app to retrieve stock quotes using web services. I found this
example in AppleScript, but my application is written in Cocoa and I don't know how to get return values from AppleScript into my Cocoa app.
So I did some more research and found an example in the Mac OS X Advanced Development Techniques book. Here is what my code looks like, very similar to the book's but with values from the AppleScript example above:
-(void)getStockQuote {
NSURL *soapURL;
soapURL = [NSURL URLWithString:@"http://services.xmethods.net:80/soap"];//[NSURL URLWithString: @"http://betty.userland.com/RPC2"];//
NSString *methodName = @"getQuote";
WSMethodInvocationRef soapCall;
soapCall = WSMethodInvocationCreate((CFURLRef) soapURL, (CFStringRef) methodName, kWSSOAP2001Protocol);
NSMutableDictionary *params;
NSMutableArray *paramsOrder;
params = [NSMutableDictionary dictionaryWithCapacity:1];
[params setObject:symbol forKey:@"symbol"];
paramsOrder = [NSArray arrayWithObjects:symbol, nil];
//set the method invocation parameters
//First parameter is the method invocation created above
//Second parameter is a dictionary containing parameters
//Thir pararmeter is an array specifying order of parameters, sometimes option for SOAP
WSMethodInvocationSetParameters(soapCall, (CFDictionaryRef)params, paramsOrder);
NSDictionary *result;
result = (NSDictionary *)WSMethodInvocationInvoke(soapCall);
if(WSMethodResultIsFault) {
NSLog(@"Error:");
NSLog([result description]);
} else {
NSLog(@"No Error:");
NSLog([result description]);
}
}
The problem is always get these errors in the returned result dictionary:
"/FaultCode" = -65794;
"/FaultExtra" = {domain = -1; error = -65795; msg = "HTTP/1.1 502 Proxy Error"; };
"/FaultString" = "/CFStreamFault";
"/kWSHTTPResponseMessage" = <NSCFType: 0x1cfd780>;
"/kWSResultIsFault" = 1;
SOAP is very new to me as is the CoreServices framework. Does anyone have any suggestions?