1 Reply Latest reply on Jun 18, 2007 1:45 PM by insuractive

    Advanced webservices

    John-ModernEarth
      Hi, I'm trying to consume a SOAP web service that requires complex datatypes. The relevant portions of the WSDL:

      <s:element name="SearchHotels">
      <s:complexType>
      <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="sDestination" type="s:string"/>
      <s:element minOccurs="0" maxOccurs="1" name="sHotelCityName" type="s:string"/>
      <s:element minOccurs="0" maxOccurs="1" name="sHotelLocationName" type="s:string"/>
      <s:element minOccurs="0" maxOccurs="1" name="sHotelName" type="s:string"/>
      <s:element minOccurs="1" maxOccurs="1" name="dtCheckIn" type="s:date"/>
      <s:element minOccurs="1" maxOccurs="1" name="dtCheckOut" type="s:date"/>
      <s:element minOccurs="0" maxOccurs="1" name="roomsInformation" type="tns:ArrayOfRoomInfo"/>
      <s:element minOccurs="1" maxOccurs="1" name="maxPrice" type="s:decimal"/>
      <s:element minOccurs="1" maxOccurs="1" name="starLevel" type="s:decimal"/>
      <s:element minOccurs="1" maxOccurs="1" name="fAvailableOnly" type="s:boolean"/>
      </s:sequence>
      </s:complexType>
      </s:element>

      <s:complexType name="ArrayOfRoomInfo">
      <s:sequence>
      <s:element minOccurs="0" maxOccurs="unbounded" name="RoomInfo" nillable="true" type="tns:RoomInfo"/>
      </s:sequence>
      </s:complexType>

      <s:complexType name="RoomInfo">
      <s:sequence>
      <s:element minOccurs="1" maxOccurs="1" name="AdultsNum" type="s:int"/>
      <s:element minOccurs="1" maxOccurs="1" name="ChildNum" type="s:int"/>
      <s:element minOccurs="0" maxOccurs="1" name="ChildAges" type="tns:ArrayOfInt"/>
      </s:sequence>
      </s:complexType>

      How do I construct these sequence sections? It's possible to have more than once occurrance of an element with the same name e.g. RoomInfo so I can't see how I'd use a Struct here?

      I've tried this:

      hotelservice = CreateObject("webservice", " http://....?wsdl");

      room1 = StructNew();
      room1.AdultsNum = 1;
      room1.ChildNum = 0;

      ages = StructNew();
      ages.ChildAge = 0;
      room1.ChildAges = ages;

      roomsinfo = StructNew();
      roomsinfo.RoomInfo = room1;

      ret = hotelservice.SearchHotels( sDestination = "NYC",
      sHotelCityName = "",
      sHotelLocationName = "",
      sHotelName = "",
      dtCheckIn = CreateDate(2007,09,09),
      dtCheckOut = CreateDate(2007,09,10),
      roomsInformation = roomsinfo,
      maxPrice = 999.0,
      starLevel = 2.0,
      fAvailableOnly = true );

      Any help would be welcome!
        • 1. Re: Advanced webservices
          insuractive Level 3
          Can you also post the ArrayOfInt type? It looks like you are on the right track, but you seem to be missing an array:

          <cfscript>
          stArgs = StructNew();
          stArgs.sDestination = "Nowhere";
          stArgs.sHotelCityName = "Las Vegas";
          stArgs.sHotelLocationName = "Hotel Location Name";
          stArgs.sHotelName = "Hotel Name";
          stArgs.dtCheckIn = CreateDate(2007, 09, 09);
          stArgs.dtCheckOut = CreateDate(2007, 09,10);
          stArgs.maxPrice = "999.0";
          stArgs.starLevel = "2.0";
          stArgs.fAvailableOnly = true;
          stAgs.roomsInformation = ArrayNew(1);
          stAgs.roomsInformation[1] = StructNew();
          stAgs.roomsInformation[1].AdultsNum = 1;
          stAgs.roomsInformation[1].ChildNum = 0;

          <cfscript>

          <cfinvoke webservice=" http://...?wsdl" method="SearchHotels" argumentscollection="#stAgs#" returnvariable="sResult">

          Hope that helps.