2017-03-15 196 views
0

我需要將這段代碼從PHP轉換爲ColdFusion。將PHP代碼轉換爲ColdFusion代碼

PHP

$mothodOption = array(
'apiUsername' => 'username11', 
'apiPassword' => 'password11', 
'SchoolID' => 32923, 
'FirstName' => 'Mensaboy', 
'LastName' => 'Superfamily', 
'RequestedUsername' => '3537807', 
'Password' => 'Password123!', 
'StudentExternalID' => '3537807', 
'Email' => '[email protected]', 
'Street' => '334 Second Street', 
'City' => 'Catasauqua', 
'Zip' => '18032', 
'State' => 'TX', 
'HomePhone' => '333-555-6666', 
'AltPhone' => '222-333-4444', 
'GradeLevel' => 3, 
'BirthDate' => strtotime(date("Y-m-d H:i:s")), 
'StudentGender' => "Female", 
'Notes' => 'Some Notes' 
); 

$client = new SoapClient("example.com"); 
$response = $client->__soapCall('CreateStudentWithUsername', array('parameters' => $mothodOption)); 

上面的代碼工作正常,現在這裏是我已經試過了冷聚變代碼:

<CFSET unix_time = DateDiff("s", CreateDate(1970,1,1), Now()) /> 
<cfscript> 
ws = createObject("webservice", "#APIurl#"); 

args = { 
     apiUsername="username11" 
     ,apiPassword="password11" 
     ,SchoolID="32923" 
     ,FirstName="Mensaboy" 
     ,LastName="Superfamily" 
     ,RequestedUsername="3537807" 
     ,Password="Password123!" 
     ,StudentExternalID="3537807" 
     ,Email="[email protected]" 
     ,Street="334 Second Street" 
     ,City="Catasauqua" 
     ,Zip="18032" 
     ,State="TX" 
     ,HomePhone="333-555-6666" 
     ,AltPhone="222-333-4444" 
     ,GradeLevel="3" 
     ,BirthDate="#unix_time#" 
     ,StudentGender="Female" 
     ,Notes="Some Notes" 
    }; 

result = ws.CreateStudentWithUsername(argumentCollection=args); 
writeDump(result); 
</cfscript> 

當我運行上面的代碼中,我得到一個錯誤:

Web service operation CreateStudentWithUsername with parameters {...} cannot be found. 

這些是我需要發送的參數:

<xs:element name="CreateStudentWithUsername"> 
<xs:complexType> 
<xs:sequence> 
<xs:element minOccurs="0" name="apiUsername" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="apiPassword" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="SchoolID" type="xs:int"/> 
<xs:element minOccurs="0" name="FirstName" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="LastName" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="RequestedUsername" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="Password" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="StudentExternalID" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="Email" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="Street" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="City" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="Zip" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="State" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="HomePhone" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="AltPhone" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="GradeLevel" type="xs:int"/> 
<xs:element minOccurs="0" name="BirthDate" type="xs:dateTime"/> 
<xs:element xmlns:q18="http://schemas.datacontract.org/2004/07/Enumerations" minOccurs="0" name="StudentGender" type="q18:Gender"/> 
<xs:element minOccurs="0" name="Notes" nillable="true" type="xs:string"/> 
</xs:sequence> 
</xs:complexType> 
</xs:element> 

有什麼想法?

+0

開始什麼論據方法期望(來自CF POV)。 – Leigh

回答

0

嘗試使用CFHTTP或CFINVOKE象下面這樣:傾倒Web服務對象` `認準`CreateStudentWithUsername`簽名,看到

<cfhttp url="https://www.example.com/CreateStudentWithUsername" method="post" result="result" charset="utf-8"> 
    <cfhttpparam type="formfield" name="apiUsername" value="username11"> 
    <cfhttpparam type="formfield" name="apiPassword" value="password11"> 
    <cfhttpparam type="formfield" name="SchoolID" value="32923"> 
    ..... 
    ..... 
    ..... 
    so on... 
</cfhttp> 


<cfinvoke webservice = "https://www.example.com" method = "CreateStudentWithUsername" returnVariable = "result"> 

    <cfinvokeargument name="apiUsername" value="username11" > 
    <cfinvokeargument name="apiPassword" value="password11" > 
    <cfinvokeargument name="SchoolID" value="32923" > 
    <cfinvokeargument name="FirstName" value="Mensaboy" > 
    ..... 
    ..... 
    ..... 
    so on... 
</cfinvoke>