Hello i have some request in soap but i have some error when i try the request in my website.
Fatal error: Call to a member function Body() on a non-object in /home/loraclec/public_html/pick5.php on line 14
Request :
<?php
/** define the SOAP client using the url for the service**/
$SoapiClient = new soapclient('http://14.141.212.201/ConRsltAPI/Result.asmx?WSDL', array('trace' => 1));
$lStrCred = "GI2304CON15";
$lStrGameName = "PICK3";
$lstrStatus = "0";
$thearray = array(
'lStrCred' => $lStrCred,
'lStrGameName' => $lStrGameName,
'lstrStatus' => $lstrStatus
);
$result = $client->Body($thearray);
if (is_soap_fault($result)):
echo '<h1>ERRROR</h1><pre>';
print_r($result);
echo '</pre>';
else:
echo '<h1>Working FINE</h1><pre>';
print_r($result);
echo '</pre>';
endif;
// see the last SOAP request
echo htmlspecialchars($client->__getLastRequest(), ENT_QUOTES);
// print the SOAP response
echo htmlspecialchars($client->__getLastResponse(), ENT_QUOTES);
/** lets store the login token just in case we want to use it for later use**/
$token = $result->token;
?>
$client doesn't exist on line 14. Change:
$result = $client->Body($thearray);
to
$result = $SoapiClient->Body($thearray);
Related
My wsdl file :-
<?php
/**
#Description: Book Information Server Side Web Service:
This Sctript creates a web service using NuSOAP php library.
fetchBookData function accepts ISBN and sends back book information.
#Author: http://programmerblog.net/
#Website: http://programmerblog.net/
*/
require_once('dbconn.php');
require_once('lib/nusoap.php');
$server = new nusoap_server();
/* Fetch 1 book data */
function presentStatusPull($rnbcode){
global $dbconn;
$sql = "SELECT * FROM rnb_gpl_data where did = :rnbcode";
// prepare sql and bind parameters
$stmt = $dbconn->prepare($sql);
$stmt->bindParam(":rnbcode", $rnbcode);
// insert a row
$stmt->execute();
$data = $stmt->fetch(PDO::FETCH_ASSOC);
return json_encode($data);
$dbconn = null;
}
$server->configureWSDL('index', 'urn:index');
$server->register('presentStatusPull',
array('rnbcode' => 'xsd:string'),
array('data' => 'xsd:string'),
'urn:index',
'urn:index#presentStatusPull'
);
$server->service(file_get_contents("php://input"));
?>
Then my php file for call the wsdl server:-
<?php
require_once('lib/nusoap.php');
$result = array();
$wsdl = "http://meter.digireach.com/RnBCode/index.php?wsdl";
$rnbcode = $_GET['rnbcode'];
//create client object
$client = new nusoap_client($wsdl, true);
$result = $client->call('presentStatusPull', array($rnbcode));
// $result = json_decode($result);
// echo json_encode($result);
echo json_encode($result, JSON_NUMERIC_CHECK);
?>
and response of url :- http://meter.digireach.com/RnBCode/presentstatus.php?rnbcode=DR00098EM
and output is like this:-
"{\"srno\":\"1\",\"tr_date\":\"2017-08-22 11:53:33\",\"did\":\"DR00098EM\",\"p1\":\"455\",\"p2\":\"0\",\"p3\":\"0\",\"p4\":\"48\",\"p5\":\"0\",\"p6\":\"0\",\"p7\":\"60\",\"p8\":\"40\",\"p9\":\"0\",\"p10\":\"0\",\"p11\":\"5\",\"p12\":\"0\",\"p13\":\"0\",\"p14\":\"1103\",\"p15\":\"36170\",\"p16\":\"511046\",\"p17\":\"0\",\"p18\":\"1\",\"p19\":\"1\",\"p20\":\"1\",\"tno\":\"Ideal\",\"ser_date\":\"2017-08-22 11:54:12\"}"
so,I want to remove backslash() from this json response.
You didn't set valid JSON header this is why your API response is string not JSON.
Solution 1:
You should set valid Content-Type header before JSON output. Like following:
header('Content-Type: application/json');
echo json_encode($result, JSON_NUMERIC_CHECK);
or, Solution 2:
Decode your output twice json_decode(json_decode($json))
I am trying to pass a 2D Array via SOAP for SAP Webservice.
But I am unable to pass the same.
I am able to pass a value, also I am able to accept a table output from SAP.
Please guide.
I tried to typecast array as an object.
My Code:
<?php
include("include/config.php");
$sql = "SELECT tid,OrderNumber FROM transhistory ORDER by timestamp ASC limit 2";
$result= mysqli_query($db,$sql);
$i=0;
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
//Array based on output table
$pmt[$i][0] = ""; //Mandt
$pmt[$i][1] = $row["tid"]; //Refnum
$pmt[$i][2] = $row["OrderNumber"]; //Orderno
$i++;
}
/*Two methods I tried */
$object = (object) $pmt;
$object = json_decode(json_encode($pmt), FALSE);
#Define Authentication
$SOAP_AUTH = array( 'login' => 'abc',
'password' => 'abc');
#Specify WSDL
$WSDL = "working URL here";
#Create Client Object, download and parse WSDL
$client = new SoapClient($WSDL,$SOAP_AUTH);
#Setup input parameters (SAP Likes to Capitalise the parameter names)
$params = array(
'Zpmt' => $object
);
#Call Operation (Function). Catch and display any errors
try {
$result = $client->ZphpOT($params);
} catch (SoapFault $exception) {
echo 'Error!Server Connectivity issue. Please try again later.';
die();
}
?>
I don't know if the answer may be useful for somebody but usually you send parameters like this
$result = $client->ZphpOT("VARIABLE_NAME"=>$params);
This is my Soap Response xml,I need to get RebillCustomerID
How I can do this?
<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><eWAYHeader
xmlns="http://www.eway.com.au/gateway/rebill/manageRebill">
<eWAYCustomerID>87654321</eWAYCustomerID><Username>test#eway.com.au</Username>
<Password>test123</Password></eWAYHeader></soap:Header><soap:Body>
<CreateRebillCustomerResponse xmlns="http://www.eway.com.au/gateway/rebill/manageRebill"><CreateRebillCustomerResult>
<Result>Success</Result><ErrorSeverity /><ErrorDetails />
<RebillCustomerID>90246</RebillCustomerID></CreateRebillCustomerResult>
</CreateRebillCustomerResponse></soap:Body></soap:Envelope><pre></pre>
try the code below. I am assuming your xml response is in $soapXMLResult variable
$soap = simplexml_load_string($soapXMLResult);
$response = $soap->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children()->CreateRebillCustomerResponse;
$customerId = (string) $response->CreateRebillCustomerResult->RebillCustomerID;
echo $customerId;
How I did, create eway soap request and get eway soap result,may help others!
<?php
$URL = "https://www.eway.com.au/gateway/rebill/test/manageRebill_test.asmx?wsdl";
$option = array("trace"=>true);
$client = new SOAPClient($URL, $option);
$functions = $client->__getFunctions();
$headeroptions=array('eWAYCustomerID'=>"87654321",'Username'=>"test#eway.com.au","Password"=>"test123");
$header = new SOAPHeader('http://www.eway.com.au/gateway/rebill/manageRebill', 'eWAYHeader',$headeroptions);
$bodyoptions = array(
"CreateRebillCustomer" => array(
"customerTitle" => "Mr",
"customerFirstName"=>"Muhammad",
"customerLastName"=>"Shahzad",
"customerAddress"=>"cust ome rAddress",
"customerSuburb"=>"customer Suburb",
"customerState"=>"ACT",
"customerCompany"=>"customer Company",
"customerPostCode"=>"2345",
"customerCountry"=>">Australia",
"customerEmail"=>"test#gamil.com",
"customerFax"=>"0298989898",
"customerPhone1"=>"0297979797",
"customerPhone2"=>"0297979797",
"customerRef"=>"Ref123",
"customerJobDesc"=>"customerJobDesc",
"customerComments"=>"customerComments",
"customerURL" => "http://www.acme.com.au"
)
);
try{
$response = $client->__soapCall("CreateRebillCustomer", $bodyoptions,NULL,$header,$outputHeader);
//echo $client->__getLastRequest();
//$response = $client->CreateRebillCustomer($bodyoptions);
//echo "<pre>";echo "<br/>";
// print_r($response);
echo $result = $response->CreateRebillCustomerResult->Result;echo "<br/>";
echo $customerId = $response->CreateRebillCustomerResult->RebillCustomerID;echo "<br/>";
echo "<br/>";
if($result=='Success' AND $customerId){
echo 'Member Created at eWay Successfully!...<br/>';
echo 'Creating Recurring Billing Cycle on eWay,Please wait......<br/>';
//$UpdateRebillCustomer = CreateRebillEvent($customerId);
//print_r($UpdateRebillCustomer);
}
else{
echo $ErrorSeverity = $response->CreateRebillCustomerResult->ErrorSeverity;echo "<br/>";
echo $ErrorDetails = $response->CreateRebillCustomerResult->ErrorDetails;echo "<br/>";
}
}
catch(SOAPFault $e){
print $e;
}
if($customerId){
$bodyoptions2 = array(
"CreateRebillEvent " => array(
"RebillCustomerID" => $customerId,
"RebillInvRef" => "Ref123",
"RebillInvDes"=>"description",
"RebillCCName"=>"Mr Andy Person",
"RebillCCNumber"=>"4444333322221111",
"RebillCCExpMonth"=>"12",
"RebillCCExpYear"=>"15",
"RebillInitAmt"=>"100",
"RebillInitDate"=>date('d/m/Y'),
"RebillRecurAmt"=>"200",
"RebillStartDate"=>date('d/m/Y'),
"RebillInterval"=>"31",
"RebillIntervalType"=>"1",
"RebillEndDate"=>"31/12/2013",
)
);
try{
$response = $client->__soapCall("CreateRebillEvent", $bodyoptions2,NULL,$header,$outputHeader);
//echo $client->__getLastRequest();
//print_r($response);
echo "<br/>";
echo $result2 = $response->CreateRebillEventResult->Result;echo "<br/>";
echo $RebillCustomerID = $response->CreateRebillEventResult->RebillCustomerID;echo "<br/>";
if($result2=='Success'){
echo 'Recurring Cycle Created Successfully at eWay!...<br/>';
echo 'Member Id is ===>'.$RebillCustomerID;
//$UpdateRebillCustomer = CreateRebillEvent($customerId);
//print_r($UpdateRebillCustomer);
}
else{
echo $ErrorSeverity = $response->CreateRebillEventResult->ErrorSeverity;echo "<br/>";
echo $ErrorDetails = $response->CreateRebillEventResult->ErrorDetails;echo "<br/>";
}
}
catch(SOAPFault $e){
print $e;
}
}
?>
If you are writing a client for a SOAP service and you want to manipulate or test their response by placing it in a local file and parsing that (maybe their response has errors and you want to fix the errors yourself), you can override the URL that your soapClient uses to call methods by calling __soapCall() directly:
$result = $this->soap_client->__soapCall( 'function_call_name', ['location' => $file_location] );
Where $file_location is the absolute or relative path to your copy of their xml response. What you put as your function call name doesn't matter, since the soap client will get the same xml response regardless of what function you try to call this way. The only thing that matters is that your $file_location be correct and that the xml file has the correct permissions to be read by apache if you run this in a browser.
You can then var_dump($response) and find the node you need rather than using simplexml_load_string. If you do it this way you can easily swap out your xml for their response later on.
i want to display the server's data in multiple rows to the client side. The current implementation shows only one row i.e. value of 'ABC' to client
Here is the server side:
<?php
function getStockQuote($symbol) {
mysql_connect('server','user','pass');
mysql_select_db('test');
$query = "SELECT stock_price FROM stockprices "
. "WHERE stock_symbol = '$symbol'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
return $row['stock_price'];
}
require('nusoap.php');
$server = new soap_server();
$server->configureWSDL('stockserver', 'urn:stockquote');
$server->register("getStockQuote",
array('symbol' => 'xsd:string'),
array('return' => 'xsd:decimal'),
'urn:stockquote',
'urn:stockquote#getStockQuote');
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)
? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
And here is the client side:
<?php
require_once('nusoap.php');
$c = new soapclient('http://localhost/stockserver.php');
$stockprice = $c->call('getStockQuote',
array('symbol' => 'ABC'));
echo "The stock price for 'ABC' is $stockprice.";
?>
You must specify an WSDL as endpoint, so change the endpoint with the wsdl, and need to call to your method (call method doesn't exist on your server)
My client code that i test and works:
<?php
require_once('nusoap.php');
$c = new soapclient('http://localhost/stockserver.php?wsdl');
$stockprice = $c->getStockQuote('ABC');
echo "The stock price for 'ABC' is $stockprice.";
?>
And please stop using deprecated mysql_* functions
Ok my .net 4.0 client works fine. People using java all have no issues. But when it comes to php our php developer cant get anything to work.
Now keep in mind i did not create a Wcflibray project, i created a regular asp 4.0 website and then added a WCF Service so i do not have a app.config, i have a web.config.
We have went down to the bare essentials of creating two methods
string HelloWorld()
{
return "Hello!";
}
and
string HellowTomorrow(string sret)
{
return sret;
}
In debug mode i will see him enter my method but only with null. If i packet sniff with wireshark, he is not passing the paramater envelope.
I have googled endlessly but all examples are from a WCF service project, not a website that has added a WCF Service too it. (rememember, everyone else is having no problems, java, .net 2.0, etc)
Here is his php 5.3
error_reporting(E_ALL);
ini_set('display_errors','On');
$client = new SoapClient("http://99-mxl9461k9f:6062/DynamicWCFService.svc?wsdl", array('soap_version' => SOAP_1_1));
$client->soap_defencoding = 'UTF-8';
//$args = array('john');
$args = array('param1'=>'john');
$webService = $client->__soapCall('HelloTomorrow',$args);
//$webService = $client->HelloTomorrow($args);
var_dumpp($webService);
?>
While working with WCF service .net as Server and PHP-soap as client you need to follow guideline strictly. The documentation of PHP-soap is not enough to debug and not that clear either. PHP nusoap is little better on documentation but still not enough on example and not a great choice for the beginners. There are a few examples for nusoap but most of them don’t work.
I would suggest following debug checklist:
Check the binding in your web.config file. It has to be “basicHttpBinding” for PHP
PHP, $client->__soapCall() function sends all arguments as an array so if your web-service function require input parameters as an array then arguments has to be in an extra array. Example#3 is given below to clear.
If required then pass “array('soap_version' => SOAP_1_1)” or “array('soap_version' => SOAP_1_2)” to SoapClient() object to explicitly declare soap version.
Always try declaring “array( "trace" => 1 )” to SoapClient Object to read the Request & Response strings.
Use “__getLastResponse();” function to read Response String.
Use “__getLastRequest();” function to read Request String.
IMPORTANT:If you are getting NULL return for any value passed as
parameter then check your .cs(.net) file that look like this:
[ServiceContract]
public interface IDynamicWCFService
{
[OperationContract]
string HelloYesterday(string test);
}
The variable name passes here, have to match with when you call it in PHP. I am taking it as “test” for my examples below.
Example #1: using php-soap with single parameter for HelloYesterday function
<?php
$url="http://99-mxl9461k9f:6062/DynamicWCFService.svc?WSDL";
$client = new SoapClient($url, array( "trace" => 1 ));
$result = $client->HelloYesterday(array('test' => 'this is a string'));
var_dump($result);
$respXML = $client->__getLastResponse();
$requXML = $client->__getLastRequest();
echo "Request: <br>";
var_dump($requXML);
echo "Response: <br>";
var_dump($respXML);
?>
Example #2 : using nusoap with single parameter for HelloYesterday function
<?php
require_once('../lib/nusoap.php');
$proxyhost = isset($_POST['proxyhost']) ? $_POST['proxyhost'] : '';
$proxyport = isset($_POST['proxyport']) ? $_POST['proxyport'] : '';
$proxyusername = isset($_POST['proxyusername']) ? $_POST['proxyusername'] : '';
$proxypassword = isset($_POST['proxypassword']) ? $_POST['proxypassword'] : '';
$url="http://99-mxl9461k9f:6062/DynamicWCFService.svc?WSDL";
$client = new nusoap_client($url, 'wsdl', $proxyhost, $proxyport, $proxyusername, $proxypassword); $client->soap_defencoding = 'UTF-8'; // this is only if you get error of soap encoding mismatch.
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
// Doc/lit parameters get wrapped
$param = array('test' => ' This is a string for nusoap');
$result = $client->call('HelloYesterday', array('parameters' => $param), '', '', false, true);
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
One more example… passing array as a parameter or pass mixed type parameter then check the following example:
Example #3: passing mixed type parameter including array parameter to Soap function.
Example of .net operation file
[ServiceContract]
public interface IDynamicWCFService
{
[OperationContract]
string[] HelloYesterday (string[] testA, string testB, int testC );
}
PHP code
<?php
$url="http://99-mxl9461k9f:6062/DynamicWCFService.svc?WSDL";
$client = new SoapClient($url, array( "trace" => 1 ));
$params = array(
"testA" => array(0=>"Value1",1=>"Value2",2=>"Value3"),
"testB" => “this is string abc”,
"testC" =>123
); // consider the first parameter is an array, and other parameters are string & int type.
$result = $client->GetData($params);
var_dump($result);
$respXML = $client->__getLastResponse();
$requXML = $client->__getLastRequest();
echo "Request: <br>";
var_dump($requXML);
echo "Response: <br>";
var_dump($respXML);
?>
Hope the above examples will help.
Since you're passing the wsdl location into the SoapClient constructor, you should be able to call $client->HelloTomorrow($args). There seem to be a few typos, though, can you verify that they are all correct in your actual code? In your web service code, you name the function HellowTomorrow but you're calling HelloTomorrow in your PHP code. Also, the parameter is named sret in your web service, but it's being passed as param1 in the $args associative array. Does it work calling HelloWorld() which doesn't expect any parameters?
Update:
See NuSOAP and content type
Try using the built-in PHP SoapClient instead of the NuSOAP version. PHP's SoapClient looks like it defaults to UTF-8, where NuSOAP seems to be hard-coded to ISO-8859-1