API消耗Coldfusion

时间:2014-07-05 03:29:43

标签: web-services coldfusion

我正在尝试使用api并尝试将此代码转换为codfusion

    <?php
       $client = new SoapClient( 
      "http://trial.black011.com/retailer/Black011SvcDemo.wsdl”,
      array(  "trace"      => 1,
              "exceptions" => 0)
            );               
    try {
    $arr = $client->recharge( ‘TestID, "TestPassword", "BKLD", “1234567890”,                                                             
                                              10, "Any Comment1 of You"  );

    echo 'error_code' . $arr['error_code'];
    echo 'error_msg' . $arr['error_msg'];
    echo 'tx_id' . $arr['tx_id'];
    echo 'comment1' . $arr['comment1'];

    }catch (SoapFault $exception) {
     echo "Error Code:" . $exception->getCode();
     echo "Error Message:" . $exception->getMessage();
   }
   ?>

我使用下面的代码来使用api

 <cfinvoke webservice="http://trial.black011.com/retailer/Black011SvcDemo.wsdl" method="recharge" returnvariable="res"  refreshwsdl="true" >

 <cfinvokeargument name="user_id" value="TestID">
 <cfinvokeargument name="passwd" value="TestPassword">
 <cfinvokeargument name="prod_id" value="BKLD">
 <cfinvokeargument name="mdn" value="1112223333">
 <cfinvokeargument name="amount" value="10">
 <cfinvokeargument name="comment1" value="10">
</cfinvoke>

我也试过了 -

    <cfscript>
     ws = createObject("webservice",           "http://trial.black011.com/retailer/Black011SvcDemo.wsdl");
      writeDump(ws);
      result = ws.recharge( "TestID", "TestPassword", "BKLD", "19112223333", 10.00 );
      writeDump(result);
  </cfscript>

但每次我都在尝试,低于错误 -

无法找到带参数{}的Web服务操作充值。 任何人都可以看到我的代码有任何问题吗?

3 个答案:

答案 0 :(得分:2)

我有一个代码,似乎在我测试它时工作。

<cfsavecontent variable="soapBody">
  <cfoutput>
    <?xml version="1.0" encoding="utf-8"?>
     <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:black011">
       <soapenv:Header/>
        <soapenv:Body>
         <urn:recharge soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
          <user_id xsi:type="xsd:string">test</user_id>
          <passwd xsi:type="xsd:string">twawd</passwd>
          <prod_id xsi:type="xsd:string">"BKLD"</prod_id>
          <mdn xsi:type="xsd:string">"1234567890"</mdn>
          <amount xsi:type="xsd:float">20.0</amount>
          <comment1 xsi:type="xsd:string">"test"</comment1>
          </urn:recharge>
        </soapenv:Body>
       </soapenv:Envelope>
     </cfoutput>
   </cfsavecontent>
   <cfhttp url="http://trial.black011.com/retailer/OpenSvc.php" method="post" result="httpResponse">
    <cfhttpparam type="header" name="SOAPAction" value="http://trial.black011.com/retailer/OpenSvc.php/recharge" />
    <cfhttpparam type="header" name="accept-encoding" value="no-compression" />
    <cfhttpparam type="xml" value="#trim( soapBody )#" />
  </cfhttp>
  <cfif find( "200", httpResponse.statusCode )>
   <cfset soapResponse = xmlParse( httpResponse.fileContent ) />
   <cfdump var="#soapResponse#">
  </cfif>

答案 1 :(得分:0)

查看ws变量转储,方法recharge需要9个参数:

recharge(java.lang.String, 
         java.lang.String, 
         java.lang.String, 
         java.lang.String, 
         float, 
         javax.xml.rpc.holders.StringHolder, 
         javax.xml.rpc.holders.StringHolder, 
         javax.xml.rpc.holders.StringHolder, 
         javax.xml.rpc.holders.StringHolder) returns void 

似乎下面的代码工作正常:

<cfscript>
    wsargs = {};
    wsargs.refreshwsdl = "Yes";
    ws = createObject("webservice", 
                      "http://trial.black011.com/retailer/Black011SvcDemo.wsdl",
                      wsargs);
    result = ws.recharge("TestID", 
                         "TestPassword", 
                         "BKLD", 
                         "19112223333", 
                         10.0, 
                         "test", 
                         "test", 
                         "test", 
                         "test");
</cfscript>

希望这可以提供帮助

答案 2 :(得分:0)

在您的问题中,您声明您正在指定如下方法

result = ws.recharge( "TestID", "TestPassword", "BKLD", "19112223333", 10.00 );

其中有5个参数。 WSDL读取

<message name="rechargeRequest">
    <part name="user_id" type="xsd:string"/>
    <part name="passwd" type="xsd:string"/>
    <part name="prod_id" type="xsd:string"/>
    <part name="mdn" type="xsd:string"/>
    <part name="amount" type="xsd:float"/>
    <part name="comment1" type="xsd:string"/>
</message>

有6个论点。您需要为第6个参数指定一些内容,通常使用WSDL,参数有助于以与函数名称相同的方式定义函数。没有任何可选参数。这给出了以下哪些应该起作用

result = ws.recharge( 
    "TestID", 
    "TestPassword", 
    "BKLD", 
    "19112223333", 
    10.00,
    "Some comment here"
);