Trouble using simple SOAP call in ColdFusion, but works in php
I've never done anything with SOAP and ColdFusion, so I have a feeling I may be overlooking something simple. I've done quite a bit of reading and looked at examples online, but am not having any luck.
I have the following code in php that functions fine:
<?php
ini_set("soap.wsdl_cache_enabled", "1");
$myDate = '09/05/2013 01:11am';
$client = new SoapClient("https://www.domain.com/remote/service.svc?wsdl");
$client->response_timeout = 60;//seconds
//paramaters to the webservice
$param=array("requestID"=>uniqid(),
"APIUser"=>"apiuser",
"APIKey"=>"apikey",
"pageCode"=>"pagecode",
"strDate"=> $myDate);
$result = $client->AppointmentTimes($param);
?>
In ColdFusion, I'm trying to replicate this functionality with the following code:
<cfscript>
stCust = StructNew();
stCust.requestID = CreateUUID();
stCust.APIUser = "apiuser";
stCust.APIKey="apikey";
stCust.pageCode="pageCode";
stCust.strFromDate = "09/05/2013 01:11am";
checkTimes = CreateObject("webservice","https://www.domain.com/remote/service.svc?wsdl" );
availTimes = checkTimes.AppointmentTimes(stCust);
</cfscript>
The error that I'm receiving is:
Web service operation AppointmentTimes with parameters {{
STRFROMDATE={09/05/2013 01:11am},
APIUSER={apiuser},
PAGECODE={pagecode},
REQUESTID={0E6D4260-1143-300A-67B00B0F8203F795},
APIKEY={apikey}
}}
cannot be found.
I've reviewed the API documentation as well as the Java stubs, but can't figure out what I'm doing wrong on the ColdFusion end.
edit: I've also tried the following approach after reading suggestions on Ben Nadel's blog:
<cfsavecontent variable="soap">
<cfoutput>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soap-env:envelope xmlns:soap-env="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"
xmlns:tns="http://tempuri.org/"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsp="http://www.w3.org/ns/ws-policy"
xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:wsa10="http://www.w3.org/2005/08/addressing"
xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap-env:body>
<tns:appointmenttimes xmlns:tns="http://tempuri.org/">
<tns:requestid>
5126adcc913f6
</tns:requestid>
<tns:apiuser>
userid
</tns:apiuser>
<tns:apikey>
apikey
</tns:apikey>
<tns:pagecode>
pagecode
</tns:pagecode>
<tns:strdate>
09/05/2013 01:11am
</tns:strdate>
</tns:appointmenttimes>
</soap-env:body>
</soap-env:envelope>
</cfoutput>
</cfsavecontent>
<cfdump var="#soap#">
<cfhttp url="https://www.domain.com/remote/service.svc" method="post" result="httpResponse">
<cfhttpparam type="header" name="content-type" value="text/xml">
<cfhttpparam type="header" name="SOAPAction" value="">
<cfhttpparam type="header" name="content-length" value="#len(soap)#">
<cfhttpparam type="header" name="charset" value="utf-8">
<cfhttpparam type="xml" name="message" value="#trim(soap)#">
</cfhttp>
<cfdump var="#httpResponse#">
and receive the following:
struct
Charset [empty string]
ErrorDetail [empty string]
Filecontent Bad Request
Header HTTP/1.1 400 Bad Request
Content-Type: text/html
Date: Wed, 04 Sep 2013 08:29:03 GMT
Cache-Control: private
X-AspNet-Version: 2.0.50727
Content-Length: 11
Server: Microsoft-IIS/7.5
Mimetype text/html
Responseheader
struct
Cache-Control private
Content-Length 11
Content-Type text/html
Date Wed, 04 Sep 2013 08:29:03 GMT
Explanation Bad Request
Http_Version HTTP/1.1
Server Microsoft-IIS/7.5
Status_Code 400
X-AspNet-Version 2.0.50727
Statuscode 400 Bad Request
Text YES
Answer
Solution:
Comparing the Parameters in PHP and ColdFusion where the error lies, there is a difference with the parameters being passed in.
In PHP you have 'strDate' with ColdFusion you have named it 'strFromDate', perhaps rename the ColdFusion param to 'strDate'.
Answer
Solution:
What version of ColdFusion are you using? Because in 10 (possibly 9) You can set the version of the web-services (Axis) library that is used.
I have ALWAYS had issues with web-services if i do NOT specify a WSVERSION of 1. I am yet to get version 2 to work in any or my CF code.
Lastly, we use the MX unit testing framework for unit testing and it also doesn't support version 2, either.
So it is just habit now to ensure that we have the version set to 1. You can do this in the CFIDE, or on a CFC by CFC basis with the "wsversion" component parameter.