Skip to content

Instantly share code, notes, and snippets.

@bardware
Last active September 6, 2015 12:02
Show Gist options
  • Save bardware/36385fe3abf870540f61 to your computer and use it in GitHub Desktop.
Save bardware/36385fe3abf870540f61 to your computer and use it in GitHub Desktop.
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