Skip to content

Instantly share code, notes, and snippets.

@bardware

bardware/webservice.cfc

Last active Sep 6, 2015
Embed
What would you like to do?
SOAP web service with optional arguments
<!--- http://stackoverflow.com/questions/32385955/soap-web-service-with-optional-arguments?noredirect=1#comment52650901_32385955 --->
<cfcomponent output="false">
<cffunction name="myFunc" returntype="struct" access="remote">
<cfargument name="mParam" type="numeric" required="true">
<cfargument name="oParam" type="string" required="false" default="strDefault">
<cfreturn Arguments>
</cffunction>
</cfcomponent>
<!--- only works when both cfinvokeargument tags are present --->
<cfinvoke method="myFunc" webservice="http://tester002/webservice.cfc?wsdl" returnvariable="ws">
<cfinvokeargument name="mParam" value="1">
<cfinvokeargument name="oParam" value="1">
</cfinvoke>
<cfdump var="#ws#">
<?php
// works if only one argument is present
$requestParams = array(
'mParam' => 2
);
try {
$client = new SoapClient('http://tester002/webservice.cfc?wsdl');
$response = $client->myFunc($requestParams);
print_r($response);
} catch( Exception $ex ) {
var_dump( $ex );
}
' works if only one parameter is set
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim c = New webservice001.webservice.webservicecfcPortTypeClient("webservice.cfcHttpSoap12Endpoint")
Dim r As New webservice001.webservice.myFuncRequest
r.mParam = 1
Dim resp = c.webservice_webservicecfcPortType_myFunc(r)
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment