April 18, 2024, 12:34:09 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Dispatch Helper Example Exchange Rate

Started by Allan, March 05, 2009, 06:25:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Allan

March 05, 2009, 06:25:15 PM Last Edit: March 05, 2009, 10:18:35 PM by Allan
I have tried to convert the Excahange Rate Example that comes with the Dispatch Helper Download.

It says it works but it does not give any results back.

Dont see why not. Must be wrong understanding on my part somehow.

Any Help is appreciated.

The code contains all the Example as well.

' Soap - Exchange Rate

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

OPENCONSOLE
string c1,c2

PRINT
' c1 = "USA"
c1 = "Fiji"
c2 = "Australia"
print("\nRunning ExchangeRate sample...\n\n")
ExchangeRate(c1, c2)


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


/* **************************************************************************
* ExchangeRate:
*   Demonstrates using XMethod's Exchange Rate service to get the exchange
* rate between the currencies of two countries.
* http://xmethods.net/ve2/ViewListing.po;?key=uuid:D784C184-99B2-DA25-ED45-3665D11A12E5
*
============================================================================ */

SUB ExchangeRate(string szCountry1, string szCountry2)
int rets

'DISPATCH_OBJ(psEnvelope);
IDispatch psEnvelope

'DISPATCH_OBJ(psTransport);
IDispatch psTransport

'LPWSTR szEnvelope =  NULL;
pointer szEnvelope = NULL
double dblRate

' HR_TRY( dhCreateObject(L"PocketSOAP.Envelope.2", NULL, &psEnvelope) );
psEnvelope = CreateComObject("PocketSOAP.Envelope.2", "")

' HR_TRY( dhCallMethod(psEnvelope, L".SetMethod(%S, %S)",
'                           L"getRate", L"urn:xmethods-CurrencyExchange") );

rets = CallObjectMethod(psEnvelope, ".SetMethod(%S, %S)", "getRate", "urn:xmethods-CurrencyExchange")
if rets <> 0 then print "CallObjectMethod Failed 1"

'HR_TRY( dhCallMethod(psEnvelope, L".Parameters.Create(%S, %T)", L"country1", szCountry1) );
rets = CallObjectMethod(psEnvelope, ".Parameters.Create(%S, %T)", "country1", szCountry1)
if rets <> 0 then print "CallObjectMethod Failed 2"

' HR_TRY( dhCallMethod(psEnvelope, L".Parameters.Create(%S, %T)", L"country2", szCountry2) );
rets = CallObjectMethod(psEnvelope, ".Parameters.Create(%S, %T)", "country2", szCountry2)
if rets <> 0 then print "CallObjectMethod Failed 3"

' ======================================================================

' HR_TRY( dhCreateObject(L"PocketSoap.HTTPTransport.2", NULL, &psTransport) );
psTransport = CreateComObject("PocketSoap.HTTPTransport.2", "")


' HR_TRY( dhPutValue(psTransport, L".SOAPAction = %S", L"") );
rets = SetComProperty(psTransport, ".SOAPAction = %S", "")
if rets <> 0 then print "SetComProperty Failed a"

' HR_TRY( dhGetValue(L"%S", &szEnvelope, psEnvelope, L".serialize") );
rets = GetComProperty(psEnvelope, "%S", &szEnvelope, psEnvelope, ".serialize")
if rets <> 0 then print "GetComProperty Failed b"

' HR_TRY( dhCallMethod(psTransport, L".Send(%S, %S)",
'                L"http://services.xmethods.net:80/soap", szEnvelope) );
rets = CallObjectMethod(psTransport, ".Send(%S, %S)", "http://services.xmethods.net:80/soap", szEnvelope)
if rets <> 0 then print "CallObjectMethod Failed c"

' HR_TRY( dhCallMethod(psEnvelope, L".Parse(%o)", psTransport) );
rets = CallObjectMethod(psEnvelope, ".Parse(%o)", psTransport)
if rets <> 0 then print "CallObjectMethod Failed d"

' HR_TRY( dhGetValue(L"%e", &dblRate, psEnvelope, L".Parameters.Item(%d).Value", 0) );
rets = GetComProperty(psEnvelope, "%e", &dblRate, ".Parameters.Item(%d).Value", 0)
if rets <> 0 then print "GetComProperty Failed e"

' _tprintf(TEXT("The exchange rate between %s and %s is %.2f.\n"), szCountry1, szCountry2, dblRate);
_printf("The exchange rate between %s and %s is %.2f.\n", szCountry1, szCountry2, dblRate)

' dhFreeString(szEnvelope);
FreeComString(szEnvelope)

' SAFE_RELEASE(psEnvelope);
psEnvelope->Release()

' SAFE_RELEASE(psTransport);
psTransport->Release()
ENDSUB



Allan

PS - Have installed PocketSoap

EDIT - Found one of my mistakes

Quote'   HR_TRY( dhGetValue(L"%S", &szEnvelope, psEnvelope, L".serialize") );
   rets = GetComProperty(psEnvelope, "%S", &szEnvelope, psEnvelope, ".serialize")
   if rets <> 0 then print "GetComProperty Failed b"

Should be:-

rets = GetComProperty(psEnvelope, "%S", &szEnvelope, ".serialize")

Still does not work though. Does not even look like it goes out onto the internet???

Ionic Wind Support Team

It's your strings.

See the users guide on GetComProperty

%S and %T are unicode (WSTRING)
%s is a STRING

So either use the L modifier like the C example does, or change the parameters from %S to %s

Paul.
Ionic Wind Support Team

Ionic Wind Support Team

And it is also the string returns.

When using %S or %T in GetComProperty you are requesting a pointer to a WSTRING, as in this example from the users guide:


IDispatch Connection
POINTER szResponse
INT _status
Connection = CreateComObject("MSXML2.XMLHTTP.3.0", "")
CallObjectMethod(Connection, ".Open(%s, %s, %b)", "GET", "http://myserver.com/test.xml", FALSE)
CallObjectMethod(Connection, ".Send")
GetComProperty(Connection, "%d", &_status, ".status")
if _status = 200
       GetComProperty(Connection, "%T", &_szResponse, ".ResponseXML.xml")
       PRINT w2s(*<wstring>_szResponse)
       FreeComString(_szResponse)
endif
Connection->Release()


And in CallObjectMethod parameters as well:

rets = CallObjectMethod(psEnvelope, ".SetMethod(%S, %S)", "getRate", "urn:xmethods-CurrencyExchange")

Should be:

rets = CallObjectMethod(psEnvelope, ".SetMethod(%s, %s)", "getRate", "urn:xmethods-CurrencyExchange")

OR

rets = CallObjectMethod(psEnvelope, ".SetMethod(%S, %S)", L"getRate", L"urn:xmethods-CurrencyExchange")

Paul.
Ionic Wind Support Team

Allan

March 06, 2009, 08:42:31 AM #3 Last Edit: March 06, 2009, 10:20:08 AM by Allan
Thank you Paul.

I had tried the  L WSTRING before but it did not work either.

Redid it as I see from you reply both ways.  Unless I have one wrong somewhere then the program is a failure as it return 0.00 in the double all the time.

With string:-
' Soap - Exchange Rate

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

OPENCONSOLE
int rets
wstring szCountry1, szCountry2

PRINT
szCountry2 = L"United States"
szCountry1 = L"Australia"
print("\nRunning ExchangeRate sample...\n\n")

IDispatch psEnvelope
IDispatch psTransport

pointer szEnvelope = NULL
' string szEnvelope = ""
double dblRate

psEnvelope = CreateComObject("PocketSOAP.Envelope.2", "")
if psEnvelope = NULL then print "CreateComObject failed"

rets = CallObjectMethod(psEnvelope, ".SetMethod(%s, %s)", "getRate", "urn:xmethods-CurrencyExchange")
if rets <> 0 then print "CallObjectMethod Failed 1"

' rets = CallObjectMethod(psEnvelope, ".Parameters.Create(%s, %s)", "country1", szCountry1)
rets = CallObjectMethod(psEnvelope, ".Parameters.Create(%s, %T)", "country1", szCountry1)
if rets <> 0 then print "CallObjectMethod Failed 2"

' rets = CallObjectMethod(psEnvelope, ".Parameters.Create(%s, %s)", "country2", szCountry2)
rets = CallObjectMethod(psEnvelope, ".Parameters.Create(%s, %T)", "country2", szCountry2)
if rets <> 0 then print "CallObjectMethod Failed 3"

' ======================================================================

psTransport = CreateComObject("PocketSoap.HTTPTransport.2", "")
        if psTransport = NULL then print "CreateComObject failed"

rets = SetComProperty(psTransport, ".SOAPAction = %s", "")
if rets <> 0 then print "SetComProperty Failed a"

rets = GetComProperty(psEnvelope, "%s", &szEnvelope, ".serialize")
if rets <> 0 then print "GetComProperty Failed b"

rets = CallObjectMethod(psTransport, ".Send(%s, %s)", "http://services.xmethods.net:80/soap", szEnvelope)
if rets <> 0 then print "CallObjectMethod Failed c"

rets = CallObjectMethod(psEnvelope, ".Parse(%o)", psTransport)
if rets <> 0 then print "CallObjectMethod Failed d"

rets = GetComProperty(psEnvelope, "%e", &dblRate, ".Parameters.Item(%d).Value", 0)
if rets <> 0 then print "GetComProperty Failed e"

_printf("The exchange rate between %s and %s is %.2f.\n", w2s(szCountry1), w2s(szCountry2), dblRate)

FreeComString(szEnvelope)

psEnvelope->Release()

psTransport->Release()

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


Using WSTRINGS -
The following line will not allow an  L as in their example:
QuotepsEnvelope = CreateComObject("PocketSOAP.Envelope.2", "")

' Soap - Exchange Rate

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

OPENCONSOLE
int rets
wstring szCountry1, szCountry2

PRINT
szCountry1 = L"United States"
szCountry2 = L"Australia"
print("\nRunning ExchangeRate sample...\n\n")

'DISPATCH_OBJ(psEnvelope);
IDispatch psEnvelope

'DISPATCH_OBJ(psTransport);
IDispatch psTransport

'LPWSTR szEnvelope =  NULL;
pointer szEnvelope = NULL
' wstring szEnvelope = L""
double dblRate

' HR_TRY( dhCreateObject(L"PocketSOAP.Envelope.2", NULL, &psEnvelope) );
psEnvelope = CreateComObject("PocketSOAP.Envelope.2", "")
if psEnvelope = NULL then print "CreateComObject failed"

' HR_TRY( dhCallMethod(psEnvelope, L".SetMethod(%S, %S)",
'                           L"getRate", L"urn:xmethods-CurrencyExchange") );

rets = CallObjectMethod(psEnvelope, ".SetMethod(%S, %S)", L"getRate", L"urn:xmethods-CurrencyExchange")
if rets <> 0 then print "CallObjectMethod Failed 1"

'HR_TRY( dhCallMethod(psEnvelope, L".Parameters.Create(%S, %T)", L"country1", szCountry1) );
rets = CallObjectMethod(psEnvelope, ".Parameters.Create(%S, %T)", L"country1", szCountry1)
if rets <> 0 then print "CallObjectMethod Failed 2"

' HR_TRY( dhCallMethod(psEnvelope, L".Parameters.Create(%S, %T)", L"country2", szCountry2) );
rets = CallObjectMethod(psEnvelope, ".Parameters.Create(%S, %T)", L"country2", szCountry2)
if rets <> 0 then print "CallObjectMethod Failed 3"

' ======================================================================

' HR_TRY( dhCreateObject(L"PocketSoap.HTTPTransport.2", NULL, &psTransport) );
psTransport = CreateComObject("PocketSoap.HTTPTransport.2", "")


' HR_TRY( dhPutValue(psTransport, L".SOAPAction = %S", L"") );
rets = SetComProperty(psTransport, ".SOAPAction = %S", L"")
if rets <> 0 then print "SetComProperty Failed a"

' HR_TRY( dhGetValue(L"%S", &szEnvelope, psEnvelope, L".serialize") );
rets = GetComProperty(psEnvelope, "%S", &szEnvelope, ".serialize")
if rets <> 0 then print "GetComProperty Failed b"

' HR_TRY( dhCallMethod(psTransport, L".Send(%S, %S)",
'                L"http://services.xmethods.net:80/soap", szEnvelope) );
rets = CallObjectMethod(psTransport, ".Send(%S, %S)", L"http://services.xmethods.net:80/soap", szEnvelope)
if rets <> 0 then print "CallObjectMethod Failed c"

' HR_TRY( dhCallMethod(psEnvelope, L".Parse(%o)", psTransport) );
rets = CallObjectMethod(psEnvelope, ".Parse(%o)", psTransport)
if rets <> 0 then print "CallObjectMethod Failed d"

' HR_TRY( dhGetValue(L"%e", &dblRate, psEnvelope, L".Parameters.Item(%d).Value", 0) );
rets = GetComProperty(psEnvelope, "%e", &dblRate, ".Parameters.Item(%d).Value", 0)
if rets <> 0 then print "GetComProperty Failed e"

' _tprintf(TEXT("The exchange rate between %s and %s is %.2f.\n"), szCountry1, szCountry2, dblRate);
_printf("The exchange rate between %s and %s is %.2f.\n", w2s(szCountry1), w2s(szCountry2), dblRate)

' dhFreeString(szEnvelope);
FreeComString(szEnvelope)

' SAFE_RELEASE(psEnvelope);
psEnvelope->Release()

' SAFE_RELEASE(psTransport);
psTransport->Release()

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


Allan

Ionic Wind Support Team

I knew I was being too vague, sorry.

The only place it is necessary is when the parameter specifies %S or %T

If you look at the example I posted quoted strings don't have an L unless a parameter or return is asking for unicode.

So for example this is wrong:

rets = CallObjectMethod(psEnvelope, ".Parameters.Create(%s, %T)", "country1", szCountry1)

%T tells CallObjectMethod that you are passing a unicode string (WSTRING) and you are giving it an ansi string (STRING) szCountry1.

Also you need some better error checking.

psTransport = CreateComObject("PocketSoap.HTTPTransport.2", "")
if psTransport = NULL then print "Object Creation Failed"

Etc.

Since I don't have pocketsoap I can't test further than that.

Paul.
Ionic Wind Support Team

Allan

Thanks for the info Paul.

Have changed it again and the prog does run. Just returns 0.00.

I think I will do more research and try MSSOAP.

Allan



Ionic Wind Support Team

I've downloaded pocketSoap and gave it a go.  Same problem as you, it doesn't seem to generate any TCPIP activity.

Paul.
Ionic Wind Support Team

Allan

I can see the Blue Light in the internet connection Icon in the Tray the FIRST time I compile and run and the program will wait for a response. You can foolow that in the CONSOLE display.

Then returns the 0.00 in the console.  And after that the blue icon light shows again as if info is arriving too late.??

Maybe  a time out in the PocketSOAP??

Then try to run the program  again and it wont even go to the net to ask for info. No Blue light in the icon. Needs a certain period of time before you can get the program to run again!!

Something not right in it for sure.....

Thank you for looking into it.

Allan