在ColdFusion中使用简单的SOAP调用有问题,但在php中有效


Trouble using simple SOAP call in ColdFusion, but works in php

我从来没有用SOAP和ColdFusion做过任何事情,所以我有一种感觉,我可能忽略了一些简单的东西。我读了很多书,也在网上看了一些例子,但运气不好。

我在php中有以下代码,运行良好:

<?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); 
?>

在ColdFusion中,我试图用以下代码复制此功能:

 <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>

我收到的错误是:

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.

我已经查看了API文档以及Java存根,但不知道我在ColdFusion端做了什么错误。


编辑:在阅读了Ben Nadel博客上的建议后,我也尝试了以下方法:

<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#">

并接收以下内容:

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 

比较PHP和ColdFusion中错误所在的参数,与传入的参数存在差异。

在PHP中,您有带有ColdFusion的"strDate",您将其命名为"strFromDate",也许可以将ColdFusionparam重命名为"strDate"。

您正在使用哪个版本的ColdFusion?因为在10(可能是9)您可以设置所使用的web服务(Axis)库的版本。

如果我没有指定WSVERSION为1,我总是会遇到web服务的问题。我还没有得到版本2工作在任何或我的CF代码。

最后,我们使用MX单元测试框架进行单元测试,它也不支持版本2。

因此,现在确保版本设置为1只是一种习惯。您可以在CFIDE中执行此操作,也可以使用"wsversion"组件参数逐个执行。