4 Replies Latest reply on Jun 23, 2006 9:35 AM by Newsgroup_User

    Webservice -- int and boolean arguments post as strings

    rachelcp
      I'm having some trouble with data type mismatches when invoking a webservice. It seems ColdFusion sends in all parameters as strings, when SOAP wants boolean or int and they aren't matching.

      The webservice has the following parameters (I've only included the parts that are giving me problems):

      <wsdl:message name="doPassProductSearchRequest">
      <wsdl:part name="nCountries" type="xsd:int"/>
      <wsdl:part name="isFlexible" type="xsd:boolean"/>
      </wsdl:message>

      Here is my call to it:

      <cfinvoke webservice="#webservice#" method="doPassProductSearch" returnvariable="getProduct" >
      <cfinvokeargument name="nCountries" value="0">
      <cfinvokeargument name="isFlexible" value="1">
      </cfinvoke>

      Here is the error I receive:

      Could not perform web service invocation "doPassProductSearch".
      Here is the fault returned when invoking the web service operation:

      java.lang.IllegalArgumentException: argument type mismatch

      Does anyone know how I should code this so the cfinvoke will definitely send in a boolean and an int? I assumed just sending a number would do it, but the developer on the other end says no.

      Thanks!
        • 1. Re: Webservice -- int and boolean arguments post as strings
          Level 7
          It's not the most intuitive feature but you can you the <cfparam ...>
          tag to set data types for variables.

          <cfparam name="nCountries" value="0" type="int">
          <cfparam name="isFlexible value="true" type="boolean">

          ...

          <cfinvokeargument name="nCountries" value="#nCountries#">
          <cfinvokeargument name="isFlexible" value="#isFlexible#">

          I've posted a working test case I once created to get the NOAA's weather
          forecast data.

          rachelcp wrote:
          > I'm having some trouble with data type mismatches when invoking a webservice.
          > It seems ColdFusion sends in all parameters as strings, when SOAP wants boolean
          > or int and they aren't matching.
          >
          > The webservice has the following parameters (I've only included the parts that
          > are giving me problems):
          >
          > <wsdl:message name="doPassProductSearchRequest">
          > <wsdl:part name="nCountries" type="xsd:int"/>
          > <wsdl:part name="isFlexible" type="xsd:boolean"/>
          > </wsdl:message>
          >
          > Here is my call to it:
          >
          > <cfinvoke webservice="#webservice#" method="doPassProductSearch"
          > returnvariable="getProduct" >
          > <cfinvokeargument name="nCountries" value="0">
          > <cfinvokeargument name="isFlexible" value="1">
          > </cfinvoke>
          >
          > Here is the error I receive:
          >
          > Could not perform web service invocation "doPassProductSearch".
          > Here is the fault returned when invoking the web service operation:
          >
          > java.lang.IllegalArgumentException: argument type mismatch
          >
          > Does anyone know how I should code this so the cfinvoke will definitely send
          > in a boolean and an int? I assumed just sending a number would do it, but the
          > developer on the other end says no.
          >
          > Thanks!
          >

          <cfparam name="WAVEH" default = false type="boolean">
          <cfparam name="maxt" default = true type="boolean">
          <cfparam name="mint" default = true type="boolean">
          <cfparam name="tempx" default = false type="boolean">
          <cfparam name="dew" default = false type="boolean">
          <cfparam name="pop12" default = false type="boolean">
          <cfparam name="qpf" default = false type="boolean">
          <cfparam name="snow" default = false type="boolean">
          <cfparam name="sky" default = false type="boolean">
          <cfparam name="wspd" default = false type="boolean">
          <cfparam name="wdir" default = false type="boolean">
          <cfparam name="wx" default = false type="boolean">
          <cfparam name="icons" default = false type="boolean">
          <cfparam name="waveh" default = false type="boolean">
          <cfparam name="startDate" default="#now()#" type="date">
          <cfparam name="numDays" default="2" type="numeric">
          <cfparam name="format" default="24 hourly" type="string">

          <cfset strWeatherParameters = STRUCTNEW() />
          <cfset strWeatherParameters.WAVEH = WAVEH />
          <cfset strWeatherParameters.maxt = maxt />
          <cfset strWeatherParameters.mint = mint />
          <cfset strWeatherParameters.temp = tempx />
          <cfset strWeatherParameters.dew = dew />
          <cfset strWeatherParameters.pop12 = pop12 />
          <cfset strWeatherParameters.qpf = qpf />
          <cfset strWeatherParameters.snow = snow />
          <cfset strWeatherParameters.sky = sky />
          <cfset strWeatherParameters.wspd = wspd />
          <cfset strWeatherParameters.wdir = wdir />
          <cfset strWeatherParameters.wx = wx />
          <cfset strWeatherParameters.icons = icons />
          <cfset strWeatherParameters.waveh = waveh />

          <cfinvoke webservice =
          " http://weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl"
          method = "NDFDgenByDay"
          returnvariable = "xmlWeatherData">

          <cfinvokeargument name="latitude" value="42.3485"/>
          <cfinvokeargument name="longitude" value="-71.0733"/>
          <cfinvokeargument name="startDate" value="#startDate#"/>
          <cfinvokeargument name="numDays" value="#numDays#"/>
          <cfinvokeargument name="format" value="#format#"/>

          </cfinvoke>

          <cfset NDFDgenByDayData = XMLParse(xmlWeatherData) />

          <cfinvoke webservice =
          " http://weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl"
          method = "NDFDgen"
          returnvariable = "xmlWeatherData">

          <cfinvokeargument name="latitude" value="42.3485"/>
          <cfinvokeargument name="longitude" value="-71.0733"/>
          <cfinvokeargument name="product" value="time-series"/>
          <cfinvokeargument name="startTime" value="#now()#"/>
          <cfinvokeargument name="endTime" value="#dateAdd('d',3,now())#"/>
          <cfinvokeargument name="weatherParameters" value="#strWeatherParameters#"/>

          </cfinvoke>

          <cfset NDFDgenData = XMLParse(xmlWeatherData) />

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          " http://www.w3.org/TR/html4/loose.dtd">
          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
          <title>Untitled Document</title>
          </head>

          <body>
          <cfdump var="#server#">
          <cfdump var="#NDFDgenByDayData#">
          <cfdump var="#NDFDgenData#">
          </body>
          </html>
          • 2. Re: Webservice -- int and boolean arguments post as strings
            Level 7
            That of course should be:
            <cfparam name="nCountries" value="0" type="integer">

            Thats what I get for typing off the cuff again, and not checking the
            documentation.

            Ian Skinner wrote:
            > <cfparam name="nCountries" value="0" type="int">

            • 3. Re: Webservice -- int and boolean arguments post as strings
              Level 7
              Actually, isn't it type numeric?

              Ian Skinner wrote:
              > That of course should be:
              > <cfparam name="nCountries" value="0" type="integer">
              >
              > Thats what I get for typing off the cuff again, and not checking the
              > documentation.
              >
              > Ian Skinner wrote:
              >> <cfparam name="nCountries" value="0" type="int">
              >
              • 4. Re: Webservice -- int and boolean arguments post as strings
                rachelcp Level 1
                Ian - thank you for your help. When I tried this code, it seemed to work just the same without the cfparams. I commented those out and just used:

                <cfset strWeatherParameters = STRUCTNEW() />
                <cfset strWeatherParameters.WAVEH = false />
                <cfset strWeatherParameters.maxt = true />
                <cfset strWeatherParameters.mint = true />
                <cfset strWeatherParameters.temp = 0 />
                <cfset strWeatherParameters.dew = 0 />
                <cfset strWeatherParameters.pop12 = 0 />
                <cfset strWeatherParameters.qpf = 0 />
                <cfset strWeatherParameters.snow = 0 />
                <cfset strWeatherParameters.sky = 0 />
                <cfset strWeatherParameters.wspd = 0 />
                <cfset strWeatherParameters.wdir = 0 />
                <cfset strWeatherParameters.wx = 0 />
                <cfset strWeatherParameters.icons = 0 />
                <cfset strWeatherParameters.waveh = 0 />

                It ran without errors. I looked at the WSDL for this service and it does say "xsd:boolean". It must be the "xsd:int" inputs that are failing in my code. Excellent idea to try a public webservice that has those inputs.