March 28, 2024, 04:40:05 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Dispatch Helper Stock Quote

Started by Allan, March 06, 2009, 03:50:29 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Allan

March 06, 2009, 03:50:29 PM Last Edit: March 06, 2009, 04:02:23 PM by Allan
Stock Quote looks an easy C Code to convert to use the DispHelper.

It does go onto the net (first time used) but returns strange amounts. There seems to be no errors from the running of the program.

Using the MSSoap.SoapClient  does not seem to be working as expected. Any suggestions??

' Stock Quote

DECLARE CDECL EXTERN _printf(format as STRING,...)

OPENCONSOLE
wstring stockname
PRINT
print "\nRunning Stock Quote sample...\n"
stockname = L"MSFT"
StockQuote(stockname)
PRINT
stockname = L"YHOO"
StockQuote(stockname)
PRINT
stockname = L"TIVO"
StockQuote(stockname)
PRINT
stockname = L"GOOG"
StockQuote(stockname)
PRINT
print "FINISHED > > >"
PRINT

PRINT "Press Q to quit"
DO: UNTIL INKEY$ = "Q"
CLOSECONSOLE
END


SUB StockQuote(wstring szStockSymbol)
' DISPATCH_OBJ(SoapClient);
IDispatch SoapClient
double dblStockPrice
int rets

SoapClient = CreateComObject("MSSoap.SoapClient", "")
IF SoapClient = NULL
PRINT "CreateComObject SoapClient Failed"
RETURN
ELSE
rets = CallObjectMethod(SoapClient, ".mssoapinit(%s)", "http://services.xmethods.net/soap/urn:xmethods-delayed-quotes.wsdl")
IF rets <> 0
PRINT "CallObjectMethod .mssoapinit Failed "
RETURN
ELSE
rets = GetComProperty(SoapClient, "%e", &dblStockPrice, ".getQuote(%T)", szStockSymbol)
IF rets <> 0
PRINT "GetComProperty .getQuote Failed"
RETURN
ENDIF
ENDIF
ENDIF

if rets = 0
_printf("Stock Price(%s): $%.2f\n", w2s(szStockSymbol), dblStockPrice)
ENDIF

SoapClient->Release()

'  C  Source Code from Examples c
' if (SUCCEEDED(dhCreateObject(L"MSSoap.SoapClient", NULL, &SoapClient)) &&

'     SUCCEEDED(dhCallMethod(SoapClient, L".mssoapinit(%S)", L"http://services.xmethods.net/soap/urn:xmethods-delayed-quotes.wsdl")) &&

'     SUCCEEDED(dhGetValue(L"%e", &dblStockPrice, SoapClient, L".getQuote(%T)", szStockSymbol)))
' {
' _tprintf(TEXT("Stock Price(%s): $%.2f\n"), szStockSymbol, dblStockPrice);  (%s ??)
' }

' SAFE_RELEASE(SoapClient);
ENDSUB


Wanting to explore further I tested the program by changing the Stockname to just a   string

rets = GetComProperty(SoapClient, "%e", &dblStockPrice, ".getQuote(%T)", szStockSymbol)

This gave back all the Quoted prices as   $0.00   which seemed better than the $-1.#R when using WCHAR.

I read in CBuilder help files that TCHAR was a macro for UNICODE.

Allan

Ionic Wind Support Team

I have to admit I am completely unfamiliar with soap, what it does or why you are trying to use it.

For what I have used DH for it has always worked, such as downloading and parsing XML.

Why keep using printf?   Emergence has it's own output and formatting statements. 

In any event I'll see if I can make it work.  I have a feeling it has to do with specifying the item parameter in the GetComProperty string, as I have had to separate the calls in the past.

Paul.
Ionic Wind Support Team

Ionic Wind Support Team

Part of the problem might be that:

http://www.xmethods.com/ve2/ViewListing.po?serviceid=2

Shows that services.xmethods.net doesn't resolve to anything when you click on Analyze WSDL

Paul.
Ionic Wind Support Team

Allan

Quotesoap, what it does or why you are trying to use it.

Soap is a protocol where the server is requested for data and the server finds the data in its resources and formats it into XML and Returns it to the SoapClient, as far as I understand it.

Though I believe JavaScript is becoming more popular for this type of work from what I have read in newsflashes.

QuoteWhy keep using printf?   Emergence has it's own output and formatting statements. 

No real reason other than the HELP File does not have a lot of detail on USING. I use help file a lot to get example code and check Params needed!
Though it is easy for me to use my NEW Retriever program to find any info I need, which I have just done and found code needed.

PRINT using("Stock Price & $#.##", w2s(szStockSymbol), dblStockPrice)

Thanks for looking at the code.

Allan





Ionic Wind Support Team

I think the help is pretty extensive on USING.  See Formatting Output

http://www.ionicwind.com/guides/emergence/writing_programs_outputformatting.htm

Link above is to the online version.

Paul.

P.S.  Just verified that services.xmethods.net is no longer a valid domain, the other IP address they give on that page is also not active.  So your program probably works fine, just nothing on the other end to get data from.



Ionic Wind Support Team

Allan

March 06, 2009, 05:39:17 PM #5 Last Edit: March 06, 2009, 06:22:45 PM by Paul Turley
Format Output - OK.

I usually type in the keyword    USING     double click on the keyword, and then right click the mouse and select   Search Help.

QuoteNo longer a valid domain

Blow!  have to find another...

Tried this one before but it just hung on the request...

http://www.webservicex.net/stockquote.asmx?WSDL

Allan

Allan

http://www.webservicex.net/stockquote.asmx?WSDL   does work ok just needed to look at the WSDL on their web page to see the input and reply types - which turns out to be strings.

Here is the code I used to get the Dispatch Helper to use its SOAP protocol.  Though it is not a full SOAP application which can do much with the returned data. Noticed on their web site to that the HTTP can be used so would be probably quicker to use the NCS components.

' Stock Quote

OPENCONSOLE
string stockname
PRINT
print "\nRunning Stock Quote sample...\n"
stockname = "MSFT"
StockQuote(stockname)
PRINT
stockname = "YHOO"
StockQuote(stockname)
PRINT
stockname = "TIVO"
StockQuote(stockname)
PRINT
stockname = "GOOG"
StockQuote(stockname)

PRINT
print "FINISHED > > >"
PRINT

PRINT "Press Q to quit"
DO: UNTIL INKEY$ = "Q"
CLOSECONSOLE
END


SUB StockQuote(string szStockSymbol)
' DISPATCH_OBJ(SoapClient);
IDispatch SoapClient
pointer sdblStockPrice
int rets, spos, epos
string str1

SoapClient = CreateComObject("MSSoap.SoapClient", "")
IF SoapClient = NULL
PRINT "CreateComObject SoapClient Failed"
RETURN
ELSE
rets = CallObjectMethod(SoapClient, ".mssoapinit(%s)", "http://www.webservicex.net/stockquote.asmx?WSDL")
IF rets <> 0
PRINT "CallObjectMethod .mssoapinit Failed "
RETURN
ELSE
' web page shows the WSDL and that a STRING is used for:
' the SYMBOL and a STRING for the REPLY (%s)
rets = GetComProperty(SoapClient, "%s", &sdblStockPrice, ".getQuote(%s)", szStockSymbol)
IF rets <> 0
PRINT "GetComProperty .getQuote Failed"
RETURN
ENDIF
ENDIF
ENDIF

IF rets = 0
' print out the XML Response returned from the SOAP Request
PRINT
PRINT "Stock Symbol - ", szStockSymbol, "  -  SOAP Response..."
PRINT
PRINT #<string>sdblStockPrice
PRINT
' extract Last Price for Stock from XML
spos = INSTR(UCASE$(#<string>sdblStockPrice), "<LAST>")
IF spos > 0
epos =  INSTR(UCASE$(#<string>sdblStockPrice), "</LAST>")
IF epos > 0
spos = spos + 6
str1 = MID$(#<string>sdblStockPrice, spos, epos-spos)
' print summary of Stock Quote
PRINT using("Stock Price for & is:  $&", szStockSymbol, str1)
ENDIF
ENDIF
PRINT
ENDIF
SoapClient->Release()
ENDSUB


Allan