Question

So I'm very new to SOAP and I am trying to connect to the National Weather Service's SOAP service in order to pull forecast data to display on my webpage. Here is my short code for this process:

    <cfinvoke
    webservice="http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php?wsdl"
    method="NDFDgen"
    returnvariable="aTemp">

        <cfinvokeargument name="latitude" value="37.94"></cfinvokeargument>
        <cfinvokeargument name="longitude" value="-75.47"></cfinvokeargument>
        <cfinvokeargument name="product" value='"glance"'></cfinvokeargument>
        <cfinvokeargument name="startTime" value="2014-05-02T12:00"></cfinvokeargument>
        <cfinvokeargument name="endTime" value="2014-05-05T12:00"></cfinvokeargument>
        <cfinvokeargument name="Unit" value='"e"'></cfinvokeargument>
        <cfinvokeargument name="weatherParameters" value="maxt = TRUE"></cfinvokeargument>
    </cfinvoke>

The problem is, when I try and run my webpage, I'm getting the following error:

Web service operation NDFDgen with parameters {Unit={"e"},startTime={2014-05-02T12:00},endTime={2014-05-05T12:00},product={"glance"},longitude={-75.47},weatherParameters={maxt = TRUE},latitude={37.94}} cannot be found.

I'm a bit confused since the NDFDgen operation does indeed exist in the WSDL file I am retrieving, and I have addressed all of the required parameters for the NDFDgen operation.

Link to the WSDL file I am trying to use: http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php?wsdl

Link to the functions page with required parameters: http://graphical.weather.gov/xml/#use_it

Can anyone see anything wrong with my code? Is it perhaps something with my arguments I'm passing to SOAP? I even tried following the advice of this Stack Overflow question (Consuming ColdFusion webservice - Web service operation with parameters {} cannot be found) and added the

refreshwsdl="yes"

attribute to my <cfinvoke>, but I am still getting the same error.

Was it helpful?

Solution

With complex web services, it is often easier to go the xml + cfhttp route, as Chester suggested. However, to answer your question, there are a few things wrong with the arguments. That is what the error message means. A method by that name may exist, but its signature does not match the values you have supplied. There is either mismatch in the number of arguments, or in this case, the type of arguments.

  • According to the wsdl, the start/endTime values must be dates. While CF can implicitly convert a variety of U.S. date strings, it cannot parse the format you are using: yyyy-MM-ddThh:mm. So either use date objects, or use "parseable", date strings such as yyyy-MM-dd hh:mm:ss.

  • The "weatherParameters" argument should be structure (or complex type) not a string:

    <cfset weather = {maxt=true}>
    ...
    <cfinvokeargument name="weatherParameters" value="#weather#">

  • The Product and Unit values have too many quotes. By using value='"glance"' you are actually including the double quotes as part of the value. That will probably cause an error because the remote web service expects to receive glance (no quotes).

  • While it will not cause an error, you do not need to include closing tags: </cfinvokeargument>. If you prefer to close it, it is cleaner to use the shortcut <cfinvokeargument ... />


With those changes, your call should work as expected. Though you might want to consider switching to createObject, rather than cfinvoke. Then you can dump the web service object for debugging purposes. It is also less bulky IMO.

<cfscript>
    ws = createObject("webservice", "http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php?wsdl");
    //show web service methods for debugging purposes
    writeDump(ws);

    // construct arguments
    args = {latitude="37.94"
            , longitude="-75.47"
            , product="glance"
            , startTime="2014-05-02 12:00:00"
            , endTime="2014-05-05 12:00:00"
            , Unit="e"
            , weatherParameters={maxt=true}
        };

    // call the method
    result  = ws.NDFDgen(argumentCollection=args);

    writeDump(result)
</cfscript>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top