Consuming Web Service that returns a Complex Data Type

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Consuming Web Service that returns a Complex Data Type

    All,

    I'm trying to consume a web service that returns a complex data type. I'm not
    having any luck. Hoping someone can point me in the right direction.

    Here is what I have.

    <cfscript>
    ws = createObject("webservice",
    "http://www.jasongaylord.com/webservices/zipcodes.asmx?wsdl");
    retCityState = ws.ZipCodeToDetails("01863");
    </cfscript>

    I want to use this web service to get city and state from a zip code. If you
    uses <cfdump var="#retCityState#"/> it returns a list of methods. (below)


    --------------------------------------------------------------------------------
    ----------------------------------------------------------------------
    object of
    com.jasongaylord.[url]www.webservices.zipcodes.ZipCodeToDetailsResponseZ ipCodeToDetai[/url]
    lsResult

    Methods hashCode (returns int)
    equals (returns boolean)
    getSerializer (returns interface org.apache.axis.encoding.Serializer)
    getDeserializer (returns interface org.apache.axis.encoding.Deserializer)
    getTypeDesc (returns org.apache.axis.description.TypeDesc)
    get_any (returns [Lorg.apache.axis.message.MessageElement; )
    set_any (returns void)
    getClass (returns java.lang.Class)
    wait (returns void)
    wait (returns void)
    wait (returns void)
    notify (returns void)
    notifyAll (returns void)
    toString (returns java.lang.String)

    --------------------------------------------------------------------------------
    ----------------------------------------------------------------------

    Now i thought that I could just use dot notation to reference these variables
    but it doesn't work. ex. #retCityState.state# etc..

    I'm lost at this point.

    I'm running CF 7.0

    Thanks,

    walshd Guest

  2. Similar Questions and Discussions

    1. using Web Service with Complex-Type in WSDL
      I have a web service developed in BEA WebLogic that I am trying to call. The WSDL has two complex types in it and is of type document/literal. When...
    2. Webservice and complex data type issue
      I created a webservice that returned a structure which .Net doesn't seem to like. So I created a complex type using component and cfproperty to...
    3. creating web service with complex data types
      I am trying to create a web service that contains a function that should take an array of complex types. The function within the cfc that gets...
    4. Referencing web service complex data type within a second web service (like a delegate)
      Hi, I am trying to figure out if ASP.NET XML Web Services and the WSDL standard can handle this type of scenario: I have two web services, and...
    5. Consuming asp.net web service with arguments (of type Date)
      Here is my problem: Would like to consume web services (ASP.NET in IIS) from within Flash MX 2004. The consumption of all web services work fine,...
  3. #2

    Default Re: Consuming a Web Service that returns a Complex DataType

    This is probably returning a transfer object of some sort. The key here would
    be to find the correct field name. Looks like maybe any or _any so maybe
    retCityState.any or retCityState._any. I couldn't tell from the wsdl exactly
    what it was doing, but maybe give it a try.

    mrampson Guest

  4. #3

    Default Re: Consuming a Web Service that returns a Complex DataType

    funky kind of ws. it returns a 2 element array. the 1st is filled w/schema
    goop, the 2nd w/the "real" results. i actually don't see any methods to pull
    data out of the results though (the results are actually returned as
    org.apache.axis.message.MessageElement).

    if you're after free/cheap geocoding ws then maybe geocoder.us or terraserver
    would do.


    <cfscript>
    ws = createObject("webservice",
    "http://www.jasongaylord.com/webservices/zipcodes.asmx?wsdl");
    results = ws.ZipCodeToDetails("18452").get_any();
    </cfscript>

    <cfdump var="#results[2].getAsString()#" label="results as string">
    <br>
    <cfdump var="#results[2]#" label="the results object">

    ===================================geocoder.us==== ===========================
    <cfscript>

    geocoder=createObject("webservice","http://geocoder.us/dist/eg/clients/GeoCoder
    ..wsdl");
    geocodeResults=geocoder.geocode_address("714 River St,Peckville, PA 18452");
    </cfscript>

    <cfdump var="#geocodeResults#">

    <cfoutput>
    <cfloop index="i" from="1" to="#arrayLen(geocodeResults)#">
    latitude: #geocodeResults[i].getLat()#, longitude:
    #geocodeResults[i].get_Long()# <br>
    </cfloop>
    </cfoutput>

    <br>
    <cfdump var="#results[1].getAsString()#" label="schema goop">

    ==========================terraserver============= ==========================
    <cfscript>
    thisPath = ExpandPath("*.*");
    thisDir = GetDirectoryFromPath(thisPath);

    ws=createObject("webservice","http://terraserver.microsoft.com/TerraService2.as
    mx?WSDL");
    place=StructNew();
    place.City="Peckville";
    place.State="PA";
    place.Country="USA";
    point=ws.ConvertPlaceToLonLatPt(place);
    scale=structNew();
    scale.Scale16m="Scale16m";
    aBB=ws.GetAreaFromPt(point,1,Scale.Scale16m,600,40 0);
    tMD=ws.GetTileMetaFromLonLatPt(point,1,Scale.Scale 16m);
    tile=tMD.getID();
    image=ws.GetTile(tile);
    </cfscript>

    <cffile action="WRITE" file="#thisDir#\image.jpg" output="#toBinary(image)#"
    addnewline="No" fixnewline="No">
    <table cellspacing="2" cellpadding="2">
    <tr><td><cfoutput><b>that location</b>:
    latitude:=#point.getLat()#&nbsp;longitude:=#point. getLon()#</cfoutput></td></tr>
    <tr><td><img src="image.jpg" alt="" border="0"></td></tr>
    </table>
    <br>
    <cfdump var="#ws#">
    <br>
    <cfdump var="#point#" label="point object">
    <br>
    <cfdump var="#aBB#" label="bounding box object">
    <br>
    <cfdump var="#tMD#" label="tile metadata">
    <br>
    <cfdump var="#tile#" label="tile object">

    PaulH Guest

  5. #4

    Default Re: Consuming a Web Service that returns a Complex DataType

    Paul,

    Thanks for your help. I was using the results in the first part of the array.
    That is why I didn't see any data. Now it looks like i'm going to have to
    parse that string for the data. I looked at the other two examples you gave
    me, but neither of them just take a zip code. I'm really looking to get city
    and state from a zip.

    Does anyone know of another service that is free with this information?

    Thanks,

    walshd Guest

  6. #5

    Default Re: Consuming a Web Service that returns a Complex DataType

    geocoder.us only does, well, geocoding. terraserver has an "advanced find"
    which seems to work off of zipcodes. i guess you could try scraping/parsing
    [url]http://zip4.usps.com/zip4/citytown.jsp[/url]. the USPS does have a webtools API for
    for this sort of thing at [url]http://www.usps.com/webtools/address.htm[/url].

    but if this is all you want to do, i'd look at getting a zipcode db:
    [url]http://www.cfdynamics.com/cfdynamics/zipbase/index.cfm[/url] or if you were really
    intent & deranged maybe:
    [url]http://www.johnsample.com/articles/GeocodeWithSqlServer.aspx[/url] (need to get TIGER
    data from [url]http://www.census.gov/geo/www/tiger/tiger2004fe/tgr2004fe.html[/url]). once
    you built out the TIGER db, you could perform this kind of "reverse" geocode.



    PaulH Guest

  7. #6

    Default Re: Consuming a Web Service that returns a Complex DataType

    Alright I got this to work. Here is the details.

    Here is the Original Web Service I was having problems with.

    Hope it helps someone!!!!

    Thanks,



    <cfscript>
    ws = createObject("webservice",
    "http://www.jasongaylord.com/webservices/zipcodes.asmx?wsdl");
    retCityState = ws.ZipCodeToDetails("01863");
    results = retCityState.get_any();
    result = XmlParse(results[2].toString());
    state = xmlSearch(result,"/diffgr:diffgram/NewDataSet/Details/state");
    city = xmlSearch(result,"/diffgr:diffgram/NewDataSet/Details/city");
    </cfscript>
    City: <cfdump var="#city[1].xmltext#" label="City"/><br/>
    State: <cfdump var="#state[1].xmltext#" label="State"/>

    Found another webservice that looks like it might last longer.
    <cfscript>
    ws = createObject("webservice", "http://www.webservicex.net/uszip.asmx?WSDL");
    retCityState = ws.GetInfoByZIP("01863");
    results = retCityState.get_any();
    result = XmlParse(results[1].toString());
    </cfscript>

    <cfoutput>
    City: #result.NewDataSet.Table.CITY#<br/>
    State: #result.NewDataSet.Table.STATE#
    </cfoutput>

    walshd Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139