Skip to main content
Participant
July 11, 2006
Answered

Web Services Insert

I am looking for example code of a web service inserting data into a database. I have usuccessfully been taking a crack at it. Below is the code:

page that calls the web service:

<cfinvoke webservice = " http://localhost/cf_test/StoryBuild.cfc?wsdl"
method = "insertSBdata" returnVariable = "insertSBdata">

<cfinvokeargument name="inputParam1" value="Fname">
<cfinvokeargument name="inputParam2" value="Lname">
<cfinvokeargument name="inputParam3" value="Department">
<cfinvokeargument name="inputParam4" value="Story">

</cfinvoke>
<cfdump var="#insertSBdata#">


web service:

<cfcomponent>
<cffunction name="insertSBdata" access="remote" returntype="any">
<cfquery name="qStoryBuild" datasource="EDStoryBuild">
INSERT INTO story_tb
VALUES ('#inputParam1#', '#inputParam2#', '#inputParam3#','#inputParam4#')
</cfquery>
</cffunction>
</cfcomponent>

Any help would be greatly appreciated.
This topic is closed to new replies. Start a new post to keep the conversation going.
Jared13Correct answer
Participant
July 13, 2006
Your cfinvoke tag specifies a return variable but your function doesn't return anything.
That did it thanks.

4 replies

Inspiring
July 11, 2006
I would guess your main problem is that your SQL syntax is wrong. You
do not have the name of the fields the values are supposed to be
inserted into.

>INSERT INTO story_tb
(FieldNameOne,FieldNameTeo,FieldName3,FieldName4)
>VALUES ('#inputParam1#', '#inputParam2#', '#inputParam3#','#inputParam4#')

This would not cause an error, but you can provide more control of the
data being passed into the function by adding <cfargument ...> tags.

><cffunction name="insertSBdata" access="remote" returntype="any">
<cfargument name="inputParam1" required="true" ...>
<cfargument name="inputParam2" required="false" default="foobar" ...>
etc.

And finally you really should scope the variables when using them inside
the function.

> VALUES ('#arguments.inputParam1#', '#arguments.inputParam2#',
'#arguments.inputParam3#','#arguments.inputParam4#')

Jared13 wrote:
> I am looking for example code of a web service inserting data into a database.
> I have usuccessfully been taking a crack at it. Below is the code:
>
> page that calls the web service:
>
> <cfinvoke webservice = " http://localhost/cf_test/StoryBuild.cfc?wsdl"
> method = "insertSBdata" returnVariable = "insertSBdata">
>
> <cfinvokeargument name="inputParam1" value="Fname">
> <cfinvokeargument name="inputParam2" value="Lname">
> <cfinvokeargument name="inputParam3" value="Department">
> <cfinvokeargument name="inputParam4" value="Story">
>
> </cfinvoke>
> <cfdump var="#insertSBdata#">
>
>
> web service:
>
> <cfcomponent>
> <cffunction name="insertSBdata" access="remote" returntype="any">
> <cfquery name="qStoryBuild" datasource="EDStoryBuild">
> INSERT INTO story_tb
> VALUES ('#inputParam1#', '#inputParam2#', '#inputParam3#','#inputParam4#')
> </cfquery>
> </cffunction>
> </cfcomponent>
>
> Any help would be greatly appreciated.
>
>
Translate
Jared13Author
Participant
July 12, 2006
I update the code and the data is being inserted into the database, but I am still receving the following error:

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

AxisFault
faultCode: { http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.lang.NullPointerException
faultActor:
faultNode:
faultDetail:
{ http://xml.apache.org/axis/}hostname:DC-ENTERDEV


The update code is as follows:

web services:
<cfcomponent>
<cffunction name="insertSBdata" access="remote" returntype="any">
<cfargument name="inputParam1" required="true" type="string" default="Fname">
<cfargument name="inputParam2" required="true" type="string" default="Lname">
<cfargument name="inputParam3" required="true" type="string" default="Department">
<cfargument name="inputParam4" required="true" type="string" default="This is the story that will be submitted.">
<cfquery name="qStoryBuild" datasource="EDStoryBuild">
INSERT INTO story_tb
(Fname,Lname,dept,story)
VALUES ('#arguments.inputParam1#', '#arguments.inputParam2#', '#arguments.inputParam3#','#arguments.inputParam4#')
</cfquery
</cffunction>
</cfcomponent>

The page that calls the web service:

<cfinvoke webservice = " http://localhost/cf_test/StoryBuild.cfc?wsdl"
method = "insertSBdata">
</cfinvoke>
<cfdump var="#insertSBdata#">

I believe that there is a issue with my code that invokes the web service, but I am not sure what.

Thanks
Translate
Inspiring
July 12, 2006
Your cfinvoke tag specifies a return variable but your function doesn't return anything.
Translate