Hi

I am actually testing how to use web services using VFP8.
I have written a sample code (see below) to consume the web service on the
link below:
http://www.webservicex.net/WS/WSDetails.aspx?CATID=12&WSID=64

---------------------------------------------------------------------------------------------------------
LOCAL oWS AS "XML Web Service"
LOCAL loGeoIP

TRY
oWS = CREATEOBJECT("MSSOAP.SoapClient")
oWS.MSSoapInit("http://www.webservicex.net/geoipservice.asmx?WSDL")
loGeoIP = oWS.GetGeoIPContext()
CATCH TO oErr
MESSAGEBOX(oErr.Message)
ENDTRY

IF VARTYPE(oWS) = "O"
RELEASE oWS
ENDIF
---------------------------------------------------------------------------------------------------------

The method GetGeoIPContext() return a complextype GeoIP.

Below is the GeoIP extract portion from the WSDL file.

- <s:complexType name="GeoIP">
- <s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="ReturnCode" type="s:int" />
<s:element minOccurs="0" maxOccurs="1" name="IP" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="ReturnCodeDetails"
type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="CountryName" type="s:string"
/>
<s:element minOccurs="0" maxOccurs="1" name="CountryCode" type="s:string"
/>
</s:sequence>
</s:complexType>


Does anyone know how to extract the complextype data in VFP8?

Appreciate your help.

Tham

Re: How to get the complextype data return from a web services? by Villi

Villi
Thu Aug 10 05:21:37 CDT 2006

tham wrote:

> The method GetGeoIPContext() return a complextype GeoIP.
> Below is the GeoIP extract portion from the WSDL file.
> <s:complexType name="GeoIP">
> <s:sequence>
> <...> && elements omitted
> </s:sequence>
> </s:complexType>
>
> Does anyone know how to extract the complextype data in VFP8?

Is this portion of XML from the same XML document containing the data? If
so, it's an "inline schema" and this helps a lot: you should be able to read
that XML with a single XMLTOCURSOR() instruction, which will put the result
into a cursor. Each element of the complex data type will be in a separate
field.
--
Villi Bernaroli
Studio K s.r.l.



Re: How to get the complextype data return from a web services? by tham

tham
Thu Aug 10 05:47:16 CDT 2006

Hi Villi


I have tried the code below but does not work. The XMLTOCURSOR trigger an
error.

---------------------------------------
oResult = oWS.GetGeoIPContext()
XMLTOCURSOR(oResult, "tmpResult")
---------------------------------------

Can you give me some examples?

Thanks



"Villi Bernaroli" <a@b.invalid> wrote in message
news:%23atN7aGvGHA.4140@TK2MSFTNGP03.phx.gbl...
> tham wrote:
>
>> The method GetGeoIPContext() return a complextype GeoIP.
>> Below is the GeoIP extract portion from the WSDL file.
>> <s:complexType name="GeoIP">
>> <s:sequence>
>> <...> && elements omitted
>> </s:sequence>
>> </s:complexType>
>>
>> Does anyone know how to extract the complextype data in VFP8?
>
> Is this portion of XML from the same XML document containing the data? If
> so, it's an "inline schema" and this helps a lot: you should be able to
> read that XML with a single XMLTOCURSOR() instruction, which will put the
> result into a cursor. Each element of the complex data type will be in a
> separate field.
> --
> Villi Bernaroli
> Studio K s.r.l.
>



Re: How to get the complextype data return from a web services? by Villi

Villi
Thu Aug 10 07:43:33 CDT 2006

tham wrote:

> I have tried the code below but does not work. The XMLTOCURSOR trigger an
> error.
> ---------------------------------------
> oResult = oWS.GetGeoIPContext()
> XMLTOCURSOR(oResult, "tmpResult")
> ---------------------------------------

Which error?
--
Villi Bernaroli
Studio K s.r.l.



Re: How to get the complextype data return from a web services? by Olaf

Olaf
Thu Aug 10 08:55:08 CDT 2006

Hi tham,

execute this:
Public goWS
Public goGeoIP

TRY
goWS = CREATEOBJECT("MSSOAP.SoapClient")
goWS.MSSoapInit("http://www.webservicex.net/geoipservice.asmx?WSDL")
goGeoIP = goWS.GetGeoIPContext()
CATCH TO oErr
MESSAGEBOX(oErr.Message)
ENDTRY


Then play around with goGeoIP and let Intellisense tell you it's
properties by typing:

goGeoIP.

I see the properties:
item : a collection of nodes
length: the number of nodes in the object
nextnode: a method to go to the next node
reset: a method to go to the first node

Not using the methods I then simply examined the items collection:
goGeoIP.item(n).
with n from 0...4 (0...loGeoIP.length-1)
and found several properties there, eg the XML property

? goGeoIP.item(0).xml
? goGeoIP.item(1).xml
? goGeoIP.item(2).xml
? goGeoIP.item(3).xml
? goGeoIP.item(4).xml

Or the nodeName and text property, eg:
? goGeoIP.item(3).nodeName
? goGeoIP.item(3).text

Or get the whole XML file by:
? loGeoIP.item(0).ownerDocument.xml

With the next Web Service the returned Object surely will be constructed
different.
So this is not meant as a general method to extract results from a
Webservice.

Bye, Olaf.



Re: How to get the complextype data return from a web services? by tham

tham
Thu Aug 10 21:34:03 CDT 2006

Hi Villi

The error is : "Function argument value, type, or count is invalid"


I have tried another method and it works. The code is below:
-----------------------------------------------------------------------------
LOCAL oWS AS "XML Web Service"
LOCAL oNodeList AS MSXML2.IXMLDOMNodeList
LOCAL sText AS String

TRY
WAIT WINDOW "Connecting to Web Services..." NOWAIT NOCLEAR

oWS = CREATEOBJECT("MSSOAP.SoapClient")
oWS.MSSoapInit("http://www.webservicex.net/geoipservice.asmx?WSDL")
oNodeList = oWS.GetGeoIPContext()

WAIT WINDOW "Invoking Web Service method..." NOWAIT NOCLEAR
oNodeList = oWS.GetGeoIPContext()

sText = ""
FOR EACH Elem In oNodeList
sText = sText + Elem.tagName + " = " + Elem.text + CHR(13)
ENDFOR

WAIT CLEAR
MESSAGEBOX(sText)

CATCH TO oErr
WAIT CLEAR
MESSAGEBOX(oErr.Message)
FINALLY
IF VARTYPE(oWS) = "O"
RELEASE oWS
ENDIF
ENDTRY
-----------------------------------------------------------------------------



"Villi Bernaroli" <a@b.invalid> wrote in message
news:OcL8PqHvGHA.356@TK2MSFTNGP04.phx.gbl...
> tham wrote:
>
>> I have tried the code below but does not work. The XMLTOCURSOR trigger an
>> error.
>> ---------------------------------------
>> oResult = oWS.GetGeoIPContext()
>> XMLTOCURSOR(oResult, "tmpResult")
>> ---------------------------------------
>
> Which error?
> --
> Villi Bernaroli
> Studio K s.r.l.
>



Re: How to get the complextype data return from a web services? by Olaf

Olaf
Mon Aug 14 06:40:49 CDT 2006

Hi tham,

your code works fine for me.

> CATCH TO oErr
> WAIT CLEAR
> MESSAGEBOX(oErr.Message)

You should display more about the error to know which line caused it.
You could eg also display oErr.LineNo and oErr.LineContents.

Bye, Olaf.