Solved

Consuming Webservices Using ColdFusion

Posted on 2006-11-29
7
599 Views
Last Modified: 2013-12-20
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
0
Comment
Question by:wsessoms
  • 3
  • 2
  • 2
7 Comments
 
LVL 12

Expert Comment

by:mmc98dl1
ID: 18062901
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
 
LVL 11

Accepted Solution

by:
jimmy282 earned 500 total points
ID: 18063144
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
 

Author Comment

by:wsessoms
ID: 18063305
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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 12

Expert Comment

by:mmc98dl1
ID: 18064590
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
 
LVL 11

Expert Comment

by:jimmy282
ID: 18064640
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
 

Author Comment

by:wsessoms
ID: 18136157
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
 
LVL 11

Expert Comment

by:jimmy282
ID: 18137772
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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question