Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Cocoa, SOAP and Stock Quotes

Cocoa, SOAP and Stock Quotes
Thread Tools
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Aug 17, 2003, 01:50 PM
 
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?
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Aug 17, 2003, 06:43 PM
 
This isn't quite my area, but I can point out something you might have overlooked. See the /Developer/Tools/WSMakeStubs command-line tool... supposedly, it writes the WebServices code for you if you give it a URL and method invocation info -- it can even spit out an ObjC class to wrap the service for you.
Rick Roe
icons.cx | weblog
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Aug 18, 2003, 12:10 AM
 
Thanks for the tip Rickster. Unfortunately, I am not sure how to work with the WSMakeStubs command line tool. Anyone want to help walk me through using WSMakeStubs, maybe just a quick run down about how to use a command line tool?

Maybe I am stepping out of my league, but there is no better way to learn!
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Aug 18, 2003, 06:08 AM
 
You can get some info on the tool by running it:

Code:
/Developer/Tools/WSMakeStubs
Code:
/Developer/Tools/WSMakeStubs -x ObjC -name MyStockWebService -url http://services.xmethods.net/soap/ur...ed-quotes.wsdl

will generate the Stubs for the WebService you chose.

- x defines the Language they are generated in. -name sets the Name of the Stubs class Generated. -url passes the WDSL URI that specifies the webservice.

There will be more useful info here:

Code:
file:///Developer/Documentation/Networking/WebServices/index.html
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Aug 18, 2003, 12:01 PM
 
Thanks. I did the WSMakeStubs and found the source files that it created in my home directory. It looks like they might get me further down the track.
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Aug 18, 2003, 08:07 PM
 
Well, since I am very new to SOAP and suds (I mean stubs), I am coming back for more help.

I used the WSMakeStubs and it created two source files (and headers), called StockQuotes and WSGeneratedObj.

I then used this code, but I still get an error (see below):

WSMethodInvocationRef soapCall;
WSGeneratedObj *sq = [[WSGeneratedObj alloc] init];
soapCall = [sq
createInvocationRef: @"http://services.xmethods.net:9090/soap"
methodName: @"getQuote"
protocol: (NSString*) kWSSOAP2001Protocol
style: (NSString*) kWSSOAPStyleRPC
soapAction: @"urn:xmethods-delayed-quotes#getQuote"
methodNamespace: @"urn:xmethods-delayed-quotes"
];

NSString *symbol = @"APPL";
NSMutableDictionary *params;
NSMutableArray *paramsOrder;

params = [NSMutableDictionary dictionaryWithCapacity:1];
[params setObject:symbol forKey:@"symbol"];


paramsOrder = [NSArray arrayWithObjects:symbol, nil];

WSMethodInvocationSetParameters([sq getRef], (CFDictionaryRef)params, (CFArrayRef)paramsOrder);

NSDictionary *result;

result = (NSDictionary *)WSMethodInvocationInvoke(soapCall);

if(WSMethodResultIsFault) {
NSLog(@"Error:");
NSLog([result description]);
} else {
NSLog(@"No Error:");
NSLog([result description]);
}
[sq release];

/*END CODE*/

Here is the error:

"/FaultCode" = 0;
"/FaultString" = getQuote;
"/kWSHTTPResponseMessage" = <NSCFType: 0x1bc28a0>;
"/kWSResultIsFault" = 1;

Can anyone offer more help? (Thanks for all of the help up to this point). As you can see, I am really stumbling through this, but learning a lot!
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Aug 18, 2003, 11:44 PM
 
Ha-hah! Got it working. I didn't realized that inside the source file StockQuotes the class name is getQuote (note the lower case). I just called the setParameters and getResult methods on an instance of getQuote and it returned the values!

Thanks for all of the help.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:19 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2