Reputation: 53
I am trying to consume an api and trying to convert this code to 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();
}
?>
I am using below code to consume the 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>
I also tried this-
<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>
But every time I am trying, getting below error-
Web service operation recharge with parameters {} can not be found. Could anybody see any problem with my code?
Upvotes: 2
Views: 182
Reputation: 82
I have a code and seems to be working as I tested it.
<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>
Upvotes: 2
Reputation: 7027
In your question you state you are specifing the method as follows
result = ws.recharge( "TestID", "TestPassword", "BKLD", "19112223333", 10.00 );
Which has 5 arguments. The WSDL reads
<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>
There are 6 arguments. You need to specify something for the 6th arguments, as typically with WSDLs the arguments help define the function in the same way as the function name does. There aren't any optional arguments. This gives the following which should work
result = ws.recharge(
"TestID",
"TestPassword",
"BKLD",
"19112223333",
10.00,
"Some comment here"
);
Upvotes: 0
Reputation: 186
Look at ws
variable dump, method recharge
takes 9 parameters:
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
Seems the code below works fine:
<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>
Hope this could help
Upvotes: 0