• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Web service need to save XML to a file

New Here ,
Oct 30, 2009 Oct 30, 2009

Copy link to clipboard

Copied

Hi,

I use a web service (use to be CFTTP and was working fine thanks to Ian Skinner) for a VIN decoder (Vehicle Identification Number) they charge per request and i can get all the car options in  3 language, they provided me with the CFM file i need to do the request and i got that part to work fine. but i need to save the XML result so i can have all the options on our server and not having to request it everytime we need to see it.

So this is the CFM that gets the vin from the web service. I need to know if it is possible to get the XML out of there and save it to a file.


<cffunction name="isNull" returntype="string" output="false">
    <cfargument name="test" type="variableName" required="Yes">
    <cfif isDefined(test)>
        <cfreturn Evaluate(test)>
    <cfelse>
        <cfreturn "">
    </cfif>
</cffunction>

<cfscript>

    webService = createObject("webservice", "MY_VIN_WS");

countryCode = "US";
    languageCode = "en";
if( IsDefined("url.countryCode") ){
  countryCode = url.countryCode;
} else {
  countryCode = "US";
}
if( IsDefined("url.languageCode") ){
  languageCode = url.languageCode;
} else {
  languageCode = "en";
}
if( languageCode EQ "es" AND countryCode EQ "CA" ){
  languageCode = "en";
}
if( languageCode EQ "fr" AND countryCode EQ "US" ){
  languageCode = "en";
}

    accountInfo = StructNew();
    accountInfo.accountNumber = "MY_ACCOUNTx";
    accountInfo.accountSecret = "MY_PASSWORD";
    accountInfo.locale = StructNew();
    accountInfo.locale.language = languageCode;
    accountInfo.locale.country = countryCode;

    version = "";
    dataVersionsRequest = StructNew();
    dataVersionsRequest.accountInfo = accountInfo;
    dataVersions = webService.getDataVersions(dataVersionsRequest);
    for (i = 1; i LTE ArrayLen(dataVersions); i=i+1) {
        if (dataVersions.country EQ "US"){
            version = dataVersions.country & " " & dataVersions.build & " (" & DateFormat(dataVersions.date) & " " & TimeFormat(dataVersions.date) & ")";
        }
    }

</cfscript>
<cfif IsDefined("url.vin")>
    <cfscript>

  returnParameters = StructNew();
        returnParameters.useSafeStandards = IsDefined("url.useSafeStandards");
        returnParameters.excludeFleetOnlyStyles = IsDefined("url.excludeFleetOnlyStyles");
        returnParameters.includeAvailableEquipment = IsDefined("url.includeAvailableEquipment");
        returnParameters.includeExtendedDescriptions = IsDefined("url.includeExtendedDescriptions");
        returnParameters.includeExtendedTechnicalSpecifications = IsDefined("url.includeExtendedTechnicalSpecifications");
        returnParameters.includeRegionSpecificStyles = IsDefined("url.includeRegionSpecificStyles");
        returnParameters.includeConsumerInformation = IsDefined("url.includeConsumerInformation");
  returnParameters.enableEnrichedVehicleEquipment = false;

        vinRequest = StructNew();
        vinRequest.accountInfo = accountInfo;
        vinRequest.vin = url.vin;
        vinRequest.manufacturerModelCode = url.manufacturerModelCode;
        vinRequest.trimName = url.trimName;
        vinRequest.wheelBase = val("url.wheelBase");
        vinRequest.manufacturerOptionCodes = ListToArray(url.manufacturerOptionCodes, ",");
        vinRequest.equipmentDescriptions = ListToArray(url.equipmentDescriptions, ",");
        vinRequest.secondaryEquipmentDescriptions = ListToArray(url.secondaryEquipmentDescriptions, ",");
        vinRequest.exteriorColorName = url.exteriorColorName;
  vinRequest.returnParameters = returnParameters;

        vehicleInfo = webService.getVehicleInformationFromVin(vinRequest);

  showInstallCause = IsDefined("url.includeCauseChain");
    </cfscript>
</cfif>

I also attach the entire file if you need to see it

Help would be greatly appreciated

TOPICS
Advanced techniques

Views

3.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 30, 2009 Oct 30, 2009

Copy link to clipboard

Copied

There may not be an XML for you to save.  That would depend on what features the builders of the web service have provided in their API.  If there is a function in the web service that returns the data in an XML format then that is what you would use, if this does not exist you will have to do it manually.

If XML is the goal and a function does not exist to get it, you would just create your own XML format, calling the various functions on the web service API to get the desired data for each node of your XML document.

If just persisting the object is the goal, you may want to look at the <cfwddx....> tag and|or serialization of the obect you received from the web service.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 30, 2009 Oct 30, 2009

Copy link to clipboard

Copied

Is there a way i can save the result in an HTML file then ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 30, 2009 Oct 30, 2009

Copy link to clipboard

Copied

Like Ian said, it depends on what they give you. Either look through the web service provider docs or do a cfdump of the webservice object. Look for any methods that may return the XML or HTML. If you find that, then saving that file is trivial because that data will be in the variable.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 30, 2009 Oct 30, 2009

Copy link to clipboard

Copied

To expand on the previous answer a little.

You can only consume what the web service gives you.  If they provide some method that allows you to get all the data in one bite then it is quite easy to save that data in any number of formats with ColdFusion.

If the web service does not give you a one method for it all choice then there is nothing you can do to change that.  You will have to use the methods they do provide you to pull the data out piece by piece and build it all together into a format of your choice.  Once you have built something, it is the same trival process to save this with ColdFusion as it would be in the first option above.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 30, 2009 Oct 30, 2009

Copy link to clipboard

Copied

How would i do a dump of that service ?  If i can do that it would be a lot easier but i cant figure out how.

I manage to get it in HTML format and save it there must be a way to get it in XML

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 30, 2009 Oct 30, 2009

Copy link to clipboard

Copied

Just dump the variabel you stored the webservice call in.

<cfset myWebServiceVar = createObject ("webservice","url.to.webservice.wsdl")>

OR

<cfinvoke webservice="url.to.websservice.wsdl" retrunVariable="myWebServiceVar"...>

<cfdump var="#myWebServiceVar#>

P.S.

NOTE: This will dump the highest level methods of the webservice.  Often, with complex webservices, you will have to drill down from these top level functions to find other available functions.

I.E.

<cfdump var="#myWebServiceVar.methodOne()#>

OR

<cfdump var="#myWebServiceVar.methodTwo(someKeys).subMethodThree()#>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 01, 2009 Nov 01, 2009

Copy link to clipboard

Copied

Ok using the DUMP i manage to get this :


<cfset WS_var = createObject ("webservice","mywebservicename")>

<cfoutput><cfdump var="#WS_var#"></cfoutput>

dump_a.jpg

Now i'm trying to use CFinvoke to pass the username nad password and a vin number to get an actuel XML from a decoded VIN then saving it has an XML file on my server but i cant get it to work can you please check my code out. And also would that work ?

<cfinvoke method="getVehicleInformationFromVIN" webservice="aa_chrome" retrunVariable="WS_vartest">
<cfinvokeargument name="USERNAME_PROPERTY" value="myuser"/>
<cfinvokeargument name="PASSWORD_PROPERTY" value="mypass"/>
<cfinvokeargument name="VIN" value="an actual vin"/>
</cfinvoke>

<cfset XMLText=ToString(WS_vartest)>
<cffile action="write" file="C:\mypath\mytest2.xml" output="#XMLText#">

Thank you very much for the help so far.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 01, 2009 Nov 01, 2009

Copy link to clipboard

Copied

but i cant get it to work

What do you mean by "can't get it to work"?  What's happening instead of it working?

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2009 Nov 01, 2009

Copy link to clipboard

Copied

This may or may not solve the problem, but you should get it out of the way: returnVariable instead of retrunVariable.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 02, 2009 Nov 02, 2009

Copy link to clipboard

Copied

This is what is happening

<cfinvoke method="getVehicleInformationFromVIN" webservice="ws_name" returnVariable="WS_vartest">
<cfinvokeargument name="language" value="en"/>
<cfinvokeargument name="country" value="CA"/>
<cfinvokeargument name="VIN" value="1FMFU2058********"/>
</cfinvoke>

<cfset XMLText=ToString(WS_vartest)>
<cffile action="write" file="C:\mypath\mytest2.xml" output="#XMLText#">

Web service  operation "getVehicleInformationFromVIN" with parameters  {country={CA},VIN={1FMFU20586*****},language={fr}} could not be  found.


The  error occurred in C:\mypath\test_vin.cfm: line  6
4 :  <cfinvokeargument name="language" value="en"/>
5 :  <cfinvokeargument name="country" value="CA"/>
6 :  <cfinvokeargument name="VIN" value="1FMFU2058**** with a real vin"/>
7 : </cfinvoke>

what i m doing wrong

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 02, 2009 Nov 02, 2009

Copy link to clipboard

Copied

Gear_Head,

There is some confusion. In your posts, you've defined the webservice function getVehicleInformationFromVin in 3 different ways, namely

getVehicleInformationFromVin(vinRequest), where vinRequest is a struct
getVehicleInformationFromVIN(USERNAME_PROPERTY, PASSWORD_PROPERTY, VIN)
getVehicleInformationFromVIN(language, country, VIN)

So, which one will it be?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 02, 2009 Nov 02, 2009

Copy link to clipboard

Copied

The last 1

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 02, 2009 Nov 02, 2009

Copy link to clipboard

Copied

Web service  operation "getVehicleInformationFromVIN" with parameters  {country={CA},VIN={1FMFU20586*****},language={fr}} could not be  found.

This suggests there is no function having the arguments {country,VIN,language} in the web service.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 02, 2009 Nov 02, 2009

Copy link to clipboard

Copied

I'm really new to Web Service how do I send the vin number usigng Cfinvoke ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 02, 2009 Nov 02, 2009

Copy link to clipboard

Copied

LATEST

Three choices

<cfinvoke webservice="#WSVariable#"....>

  <cfinvokeArgument name="VIN" value="#vinValue#">

</cfinvoke>

OR

<cfset argumentStruct = structNew()>

<cfset argumentStruct.VIN = vinValue>

...

<cfinvoke webservice="#WSVariable#" argumentCollection="#argumentStruct#"...>

OR

<cfinvoke webservice="#WSVariable#" VIN="#vinValue#"....>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 02, 2009 Nov 02, 2009

Copy link to clipboard

Copied

| h1. Web service operation

"getVehicleInformationFromVIN" with parameters

{country={CA},VIN={1FMFU20586*****},language=} could not

be found.

That type of error often means CF is unable to match up the values you are passing with one of the webservice methods. Some common causes are when the number (or type) of arguments do not match the method parameters.

For example

A) Passing three (3) strings to a method that only expects two (2) strings

B) Passing three (3) strings to a method that expects two (2) strings and one (1) number

Can you post a snippet of wsdl, specifically the portion that defines getVehicleInformationFromVIN and its parameters?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation