Solved

Consuming Webservices Using ColdFusion

Posted on 2006-11-29
7
593 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 12

Expert Comment

by:mmc98dl1
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now