Skip to main content
Known Participant
January 22, 2009
Question

web services

  • January 22, 2009
  • 6 replies
  • 854 views
I want to use webservices for one of my applications to be developed. The project is : I have to get a file(XML) from another server (remote) and process and put the file in that remote server. Can anybody help me with the idea of webservice and how to use it. Cdoe is much more of a help. Any help is appreciated.

Thank you.
Aruna
This topic has been closed for replies.

6 replies

Inspiring
January 23, 2009
Aruna,

I see an issue in your code. Based on the snippet above, you're uploading the file twice. Once in the function and once outside the function. Is there a reason for this?

In the first upload instance, outside the function, it appears to be correct.

In the second upload instance, inside the function, you are passing a string (arguments.filename1) to the filefield attribute of CFFILE. This won't work because the filefield attribute must refer to a form field, not a string (see CF LiveDocs on CFFILE action=upload for more details).

Is there a reason to upload twice or is this a mistake/typo?

As a quick test, try the following CFML code (I just edited your sample):
<cfset request.directory=#GetDirectoryFromPath(ExpandPath('\'))#>
<cfset request.directoryfile = "Aruna\Datafiles\">

<cfinvoke method="UploadFile" returnvariable="strng">
<cfinvokeargument name="formfields" value="#form#">
</cfinvoke>

<cffunction name="UploadFile" returntype="string">
<cfargument name="formfields" required="true" type="struct">
<cffile action="upload" nameconflict="overwrite" destination="#request.directory##request.directoryFile#" filefield="formfields.filename">
<cfset strng="File loaded Successfully">
<cfreturn #strng#>
</cffunction>

<cfoutput>#strng#</cfoutput>

In this instance, you are passing in the form scope to your function and from there you can properly let CF know from which form field to upload a file.
arunaumucAuthor
Known Participant
January 23, 2009
I get the error:

The form field "filename1" did not contain a file.

Aruna
Inspiring
January 23, 2009
That's why I suggested starting with something simple. I tried to browse your wdsl and got Internet Explorer cannot display the webpage.

That could mean that the path is wrong, or that it's behind a firewall. Can you browse it?

Also, post your function code and your cfinvoke code.
arunaumucAuthor
Known Participant
January 23, 2009
dan and craig,

Thankyou, but I noticed I did not generate wsdl of my cfc before I called it from the file. Hence the error. But I am in a strange loop now.

I send a filename to the function I invoke for uploading the file, It doesnot take the file name. It gives an error. Do you have any idea. The code is below. I intend to put this cfm code into cfc for webservices.



---------------html--------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="Upload" action="Upload.cfm" method="post" enctype="multipart/form-data" >
Upload the filename: <input type="file" name="Filename">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>




------------cfm--------------


<Cfset request.directory=#GetDirectoryFromPath(ExpandPath('\'))#>
<cfset request.directoryfile = "Aruna\Datafiles\">



<cfoutput>#request.directory#,#request.directoryFile#</cfoutput>
<cffile action="upload" nameconflict="overwrite" destination="#request.directory##request.directoryFile#" filefield="filename">

<cfinvoke method="UploadFile" returnvariable="strng">
<cfinvokeargument name="Filename1" value="#form.Filename#">
</cfinvoke>

<cffunction name="UploadFile" returntype="string">
<cfargument name="filename1" required="true">
<cfoutput>#filename1#</cfoutput>
<cffile action="upload" nameconflict="overwrite" destination="#request.directory##request.directoryFile#" filefield="filename1">
<!--- <cftry>

<cfcatch type="any">
<Cfoutput>hello</Cfoutput>
<cfabort>
</cfcatch>
</cftry> --->
<cfset strng="File loaded Successfully">
<cfreturn #strng#>
</cffunction>
<Cfoutput>#strng#</Cfoutput>
Inspiring
January 23, 2009
Aruna,

Can you post your justFunction CFC code? It will probably help more to see what you have in place than just the error message.

As Dan noted, publishing a web service essentially involves making your CFC has at least one method with access="remote".
arunaumucAuthor
Known Participant
January 23, 2009
Dan,

How do I publish webservices. Do I need to make any changes on the server. I get the following error.

------------------------
Could not generate stub objects for web service invocation.
Name: http:wsdev.umuc.edu/aruna/ws/justFunction.cfc?wsdl. WSDL: http:wsdev.umuc.edu/aruna/ws/justFunction.cfc?wsdl. WSDLException (at /h1): faultCode=INVALID_WSDL: Expected element '{ http://schemas.xmlsoap.org/wsdl/}definitions'.: It is recommended that you use a web browser to retrieve and examine the requested WSDL document for correctness. If the requested WSDL document can't be retrieved or it is dynamically generated, it is likely that the target web service has programming errors.

-------------------------
Inspiring
January 22, 2009
I suggest you start with a "hello world" web service and progress from there.

To build a webservice, put a function into a cfc with access="remote"

To call it, refer to the cfml reference manual section on cfinvoke.