Consuming Webservices Using ColdFusion

I am brandy new to SOAP and XML. I am proficient with CFML. I need to request information from a hotel reservation webservice and store the response in a MS Access database to be used by my CFML application. I will be translating to mySQL later in the development of the application.

Below is the XML code that I received from the webservice provider:

Technical information

The Hotel interface runs onto HTTP protocol and both Xml request and responses should be into a SOAP message. This way allows multiple Xml functions in the same message and save in communications. But the main advantage is that SOAP offers many integration possibilities with many systems using free and available libraries by Internet. In any case the SOAP tags are optional and can be omitted.

See Soap-tags below:
Soap Request Sample      
<?xml version="1.0.1" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <barceloDS_requests>

.
.
.

    </barceloDS_requests>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>      


Soap Response Sample
<?xml version="1.0.1" encoding="ISO-8859-1" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
     <barceloDS_responses>

.
.
.

     </barceloDS_responses>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Webservice url address: http:// 194.224.184.162/barceloDS/interface/xml

'The XML Request Sample'

<?xml version="1.0" encoding="UTF-8"?>
<barceloDS_requests>
      <request type="availability list" id="1">
            <session_id>aaa6SP8c6P5BAJ</session_id>
            <language_code>ING</language_code>
            <agency>
                  <primary>888</primary>
                  <secondary>88</secondary>
                  <detail>888</detail>
                  <branch>1</branch>
            </agency>
            <contract/>
            <check_in_date>20030701</check_in_date>
            <check_out_date>20030707</check_out_date>
            <location>
                  <destination_code>PMI</destination_code>
                  <zone_code/>
            </location>
            <establishment>
                  <code/>
                  <category/>
            </establishment>
            <board_type_code/>
            <occupancy>
                  <adults>2</adults>
                  <children>1</children>
                  <rooms>1</rooms>
            </occupancy>
      </request>
</barceloDS_requests>


The XML Response Sample
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<barceloDS_responses xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
      <response>
            <request type="availability list" id="1">
                  <session_id>aaa6SP8c6P5BAJ</session_id>
                  <language_code>ING</language_code>
                  <agency>
                        <primary>888</primary>
                        <secondary>88</secondary>
                        <detail>888</detail>
                        <branch>1</branch>
                  </agency>
                  <contract/>
                  <check_in_date>20030706</check_in_date>
                  <check_out_date>20030707</check_out_date>
                  <location>
                        <destination_code>PMI</destination_code>
                        <zone_code/>
                  </location>
                  <establishment>
                        <code/>
                        <category/>
                  </establishment>
                  <board_type_code/>
                  <occupancy>
                        <adults>2</adults>
                        <children>1</children>
                        <rooms>1</rooms>
                  </occupancy>
            </request>
            <establishment>
                  <code>271</code>
                  <description>TRYP BELLVER</description>
                  <contract>3.V_BELLVER</contract>
                  <child_min_age>2</child_min_age>
                  <child_max_age>12</child_max_age>
                  <location>
                        <destination>
                              <code>PMI</code>
                              <description>MALLORCA</description>
                        </destination>
                        <zone>
                              <code>10</code>
                              <description>PALMA</description>
                        </zone>
                  </location>
                  <category>
                        <code>4EST</code>
                        <description>4 STARS</description>
                  </category>
                  <incoming_contract>0</incoming_contract>
                  <offer>YES</offer>
                  <classification>SPE</classification>
                  <room>
                        <code>DBL.TE</code>
                        <description>DOBLE TERRACE</description>
                        <availability>997</availability>
                        <type>P</type>
                        <occupancy>
                              <adults>2</adults>
                              <children>1</children>
                              <rooms>1</rooms>
                        </occupancy>
                        <price>
                              <board_type>
                                    <code>SA</code>
                                    <description>SELF CATERING</description>
                              </board_type>
                              <currency>EUR</currency>
                              <amount>14,08</amount>
                        </price>
                        <price>
                              <board_type>
                                    <code>MP</code>
                                    <description>HALF BOARD</description>
                              </board_type>
                              <currency>EUR</currency>
                              <amount>20,98</amount>
                        </price>
                  </room>
                  <room>
                        <code>A14.TE</code>
                        <description>APTO. 1 DORMITORIO 4 PAX TERRACE</description>
                        <availability>999</availability>
                        <type>U</type>
                        <occupancy>
                              <adults>2</adults>
                              <children>1</children>
                              <rooms>1</rooms>
                        </occupancy>
                        <price>
                              <board_type>
                                    <code>SA</code>
                                    <description>SELF CATERING</description>
                              </board_type>
                              <currency>EUR</currency>
                              <amount>36,8</amount>
                        </price>
                        <price>
                              <board_type>
                                    <code>MP</code>
                                    <description>HALF BOARD</description>
                              </board_type>
                              <currency>EUR</currency>
                              <amount>57,5</amount>
                        </price>
                  </room>
            </establishment>
            <establishment>
                  <code>297</code>
                  <description>BARCELO PUEBLO PALMA</description>
                  <contract>3.VARIOS</contract>
                  <child_min_age>2</child_min_age>
                  <child_max_age>12</child_max_age>
                  <location>
                        <destination>
                              <code>PMI</code>
                              <description>MALLORCA</description>
                        </destination>
                        <zone>
                              <code>20</code>
                              <description>PLAYA DE PALMA</description>
                        </zone>
                  </location>
                  <category>
                        <code>3EST</code>
                        <description>3 STARS</description>
                  </category>
                  <incoming_contract>0</incoming_contract>
                  <offer>YES</offer>
                  <classification>SPE</classification>
                  <room>
                        <code>DBL.ST</code>
                        <description>DOBLE STANDARD</description>
                        <availability>994</availability>
                        <type>P</type>
                        <occupancy>
                              <adults>2</adults>
                              <children>1</children>
                              <rooms>1</rooms>
                        </occupancy>
                        <price>
                              <board_type>
                                    <code>MP</code>
                                    <description>HALF BOARD</description>
                              </board_type>
                              <currency>EUR</currency>
                              <amount>16</amount>
                        </price>
                  </room>
            </establishment>
      </response>
</barceloDS_responses>

Thank you in advance for your help
wsessomsAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
jimmy282Connect With a Mentor Commented:
or the best way to do this is this :-

generate the SOAP request in a variable using cfsavecontent

<cfsavecontent variable="SOAP">
....
</cfsavecontent>

and then use CFHTTP to send it to the service
<cfhttp url ="WSDLUrl" method="post" >
<cfhttpheader name="SOAPACTION" value="" />
</cfhttp>

and then once you get the response you can save it wherever you want.

<cfoutput>
#cfhttp.filecontent# -
</cfoutput>

Lemme know if it doesnt work out.
0
 
mmc98dl1Commented:
Are you using CF 7 ?
Do you have a URL for this webService that contains wsdl or .wsdl?
The URL you provided in the code here times out, so I cant help you any further.

Its really easy to do:

<cfinvoke
  webservice="http://194.224.184.162/barceloDS/interface/xml/"
  method="getAvailability"
  returnvariable="aTemp">
    <cfinvokeargument name="check_in_date" value="2006-12-04"/>
...
...
etc...
</cfinvoke>
0
 
wsessomsAuthor Commented:
Thanks for all the replies. I am going to try them today. I am starting to believe that there may be a problem on the web service end, If none of the suggestions work I am going to contact the web service providers and see if they have changed their URL for the WSDL address. In the documentation that I have the URL for the WSDL info is http://194.224.184.162/barceloDS/interface/example. When I try to contact this url I get page cannot be found. I will update this post when I get more info.

Thanks
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
mmc98dl1Commented:
jimmy282 - 'the best way'? Why put yourself throught the pain of creating a soap request and headers when CF can do it for you?
0
 
jimmy282Commented:
mmcd98dl1 - From my expereince, consuming webservices from CF has some problems, e.g. with Java Complex types and .NET dataset types. Whereas if you use some XML editor like XMLSpy to generate a blank SOAP request (takes 2 seconds).......or for that matter, any soap client (e.g. www.soapclient.com) to generate the SOAP request and then populate it with CF variables, there is never any problem with datatypes. You just get the SOAP response and you can play with it the way you want.

0
 
wsessomsAuthor Commented:
jimmy282, Your answer to my partially worked. I was unable to use the <cfhttpheader> tag and instead had to use <cfhttpparam type="xml" value="#xmlSoapRequest#"> then it all worked. I nonw have the second half of this problem to solve which is how do I now format the response into a table.
Below is the XML response stream that is displayed on the screen when I do a <cfoutput>#cfhttp.filecontent#</cfoutput>

aaa6SP8c6P5BAJ ING 888888881 20061222 20061229 NYC 2 1 1 969511113451Thirty Thirty3.3RDXML012NYCNew York City - NY11Midtown East3EST3 STARSX60052002YESNOREURDBL.SUDOUBLE/ TWIN SUPERIOR995211HDBED AND BREAKFAST386.54DBL.STDOUBLE/ TWIN STANDARD998211HDBED AND BREAKFAST544.74

Or is there a way to get the response back as XML like the output below:

XML Response

  <?xml version="1.0" encoding="iso-8859-1" standalone="no" ?>
- <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:msxsl="urn:schemas-microsoft-com:xslt" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
- <SOAP-ENV:Body>
- <barceloDS_responses ip="69.121.64.141">
- <response>
- <request type="valued availability list" id="1">
  <session_id>aaa6SP8c6P5BAJ</session_id>
  <language_code>ING</language_code>
- <agency>
  <primary>888</primary>
  <secondary>88</secondary>
  <detail>888</detail>
  <branch>1</branch>
  </agency>
  <contract />
  <check_in_date>20061222</check_in_date>
  <check_out_date>20061229</check_out_date>
- <location>
  <destination_code>NYC</destination_code>
  <zone_code />
  </location>
- <establishment>
  <code />
  <category />
  </establishment>
  <board_type />
- <occupancy>
  <adults>2</adults>
  <children>1</children>
  <rooms>1</rooms>
  </occupancy>
  </request>
- <valued_list>
  <valuation_file_number>9919</valuation_file_number>
  <total_pages>1</total_pages>
  <current_page>1</current_page>
  <total_hotels>1</total_hotels>
- <establishment>
  <code>13451</code>
  <description>Thirty Thirty</description>
  <contract>3.3RDXML</contract>
  <child_min_age>0</child_min_age>
  <child_max_age>12</child_max_age>
- <location>
- <destination>
  <code>NYC</code>
  <description>New York City - NY</description>
  </destination>
- <zone>
  <code>11</code>
  <description>Midtown East</description>
  </zone>
  </location>
- <category>
  <code>3EST</code>
  <description>3 STARS</description>
  </category>
  <incoming_contract>X60052235</incoming_contract>
  <offer>YES</offer>
  <classification>NOR</classification>
  <currency>EUR</currency>
- <room>
  <code>DBL.SU</code>
  <description>DOUBLE/ TWIN SUPERIOR</description>
  <availability>995</availability>
- <price>
- <occupancy>
  <adults>2</adults>
  <children>1</children>
  <rooms>1</rooms>
  </occupancy>
- <board_type>
  <code>HD</code>
  <description>BED AND BREAKFAST</description>
  </board_type>
  <amount>386.54</amount>
  </price>
  </room>
- <room>
  <code>DBL.ST</code>
  <description>DOUBLE/ TWIN STANDARD</description>
  <availability>998</availability>
- <price>
- <occupancy>
  <adults>2</adults>
  <children>1</children>
  <rooms>1</rooms>
  </occupancy>
- <board_type>
  <code>HD</code>
  <description>BED AND BREAKFAST</description>
  </board_type>
  <amount>544.74</amount>
  </price>
  </room>
  </establishment>
  </valued_list>
  </response>
  </barceloDS_responses>
  </SOAP-ENV:Body>
  </SOAP-ENV:Envelope>
0
 
jimmy282Commented:
Hi, you can use XmlParse to parse the response.

soapXml = XMLParse(cfhttp.filecontent);
responseBody = xmlSearch(soapXml,"//SOAP-ENV:Envelope/SOAP-ENV:Body") ;

Basically you get back a XML obviously but when you do a cfoutput, you dont see the XML ags, you just see the text, whereas if you save it in a variable , you will ntice you actually have the XML you wanted.

0
All Courses

From novice to tech pro — start learning today.