A SOAP request XML looks like the following:
<soapenv:Body>
<net:GetAvailability>
<net:request>
<inh:UserCredentials>
<inh:AgentID>**</inh:AgentID><inh:Password>**</inh:Password>
<inh:Username>**</inh:Username>
</inh:UserCredentials>
<net:AccessCircuit>
<arr:string>All</arr:string>
</net:AccessCircuit>
<net:RequestDetails xsi:type="net:TelephoneNumberAvailabilityRequest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<net:PerformMPFACCheck>No</net:PerformMPFACCheck>
<net:ProxyCLI>true</net:ProxyCLI>
<net:TelephoneNumber>0121****</net:TelephoneNumber>
</net:RequestDetails>
<net:UserConsent>Yes</net:UserConsent>
</net:request>
</net:GetAvailability>
</soapenv:Body>
What I need to do is send this XML request using PHP SOAP however im not able to get this working. My current code is as follows:
$APIParameters = array(
'request' => array(
'UserCredentials' => array(
'Username' => $this->apiUsername,
'Password' => $this->apiPassword,
'AgentID' => $this->apiResellerID,
),
'AccessCircuit' => array(
'string' => 'All'
),
'UserConsent' => 'Yes',
)
);
$APIParameters['request']['RequestDetails'] = new SoapParam( array('PerformMPFACCheck' => 'Yes', 'Postcode' => "****", 'ProxyCLI' => "true", 'TelephoneNumber' => '****'), "TelephoneNumberAvailabilityRequest");
print_r($APIParameters);
$apiResult = $SOAPClient->GetAvailability($APIParameters);
The print_r() returns the following:
Array
(
[request] => Array
(
[UserCredentials] => Array
(
[Username] => ****
[Password] => ****
[AgentID] => ****
)
[AccessCircuit] => Array
(
[string] => All
)
[UserConsent] => Yes
[RequestDetails] => SoapParam Object
(
[param_name] => TelephoneNumberAvailabilityRequest
[param_data] => Array
(
[PerformMPFACCheck] => Yes
[Postcode] => ****
[ProxyCLI] => true
[TelephoneNumber] => 0121****
)
)
)
)
Yet the SOAP request fails with a Fatal error: Uncaught SoapFault exception: [a:InternalServiceFault]. What am I doing wrong?! Appreciate any help!
first check that your wsld soap access granted using this code
<?php
// enter your url
$client = new SoapClient('enteryoururl');
var_dump($client->__getFunctions());
?>
then check which function have in this url if you have access and your function list show your function then try this
Fatal error: Uncaught SoapFault exception: [ns1:Client.AUTH_1] Authentication Failed
Related
I have a file I am using as a PHP to act as a config file to store info that might need to be changed frequently. I return the array as an object, like so:
return (object) array(
"host" => array(
"URL" => "https://thomas-smyth.co.uk"
),
"dbconfig" => array(
"DBHost" => "localhost",
"DBPort" => "3306",
"DBUser" => "thomassm_sqlogin",
"DBPassword" => "SQLLoginPassword1234",
"DBName" => "thomassm_CadetPortal"
),
"reCaptcha" => array(
"reCaptchaURL" => "https://www.google.com/recaptcha/api/siteverify",
"reCaptchaSecretKey" => "IWouldNotBeSecretIfIPostedItHere"
)
);
In my classes I have a constructor to call this:
private $config;
function __construct(){
$this->config = require('core.config.php');
}
And the use it like:
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('secret' => $this->config->reCaptcha->reCaptchaSecretKey, 'response' => $StrToken)));
However, I am given the error:
[18-Apr-2017 21:18:02 UTC] PHP Notice: Trying to get property of non-object in /home/thomassm/public_html/php/lib/CoreFunctions.php on line 21
I don't understand why this is happening considering the thing is returned as an object and it seemed to work for other people, as I got this idea from another question. Any suggestions?
In your example only $this->config is an object. The properties are arrays, so you would use:
$this->config->reCaptcha['reCaptchaSecretKey']
The object looks like this:
stdClass Object
(
[host] => Array
(
[URL] => https://thomas-smyth.co.uk
)
[dbconfig] => Array
(
[DBHost] => localhost
[DBPort] => 3306
[DBUser] => thomassm_sqlogin
[DBPassword] => SQLLoginPassword1234
[DBName] => thomassm_CadetPortal
)
[reCaptcha] => Array
(
[reCaptchaURL] => https://www.google.com/recaptcha/api/siteverify
[reCaptchaSecretKey] => IWouldNotBeSecretIfIPostedItHere
)
)
To have all objects you could JSON encode and then decode:
$this->config = json_decode(json_encode($this->config));
I believe this should work, but it doesn't:
$response = $client->updateItem(array(
'TableName' => 'ximoIsThisYou',
'KeyConditionExpression' => 'rep_num = :v_hash and record_created = :v_range',
'ExpressionAttributeValues' => array (
':v_hash' => array('S' => $rep_num),
':v_range' => array('N' => $record_created),
':val1' => array('S' => '447747')
),
'UpdateExpression' => 'set vimeo_id = :val1',
'ReturnValues' => 'ALL_NEW'
));
I get this error:
Uncaught Aws\DynamoDb\Exception\ValidationException:
AWS Error Code: ValidationException, Status Code: 400,
AWS Request ID: UOPKLQER1MI3ANF48PU92IAC3VVV4KQNSO5AEMVJF66Q9ASUAAJG,
AWS Error Type: client,
AWS Error Message: 1 validation error detected: Value null at 'key' failed to satisfy constraint: Member must not be null,
User-Agent: aws-sdk-php2/2.8.2 Guzzle/3.9.3 curl/7.35.0 PHP/5.5.9-1ubuntu4.11
This however does work:
$response = $client->query(array(
'TableName' => 'ximoIsThisYou',
'KeyConditionExpression' => 'rep_num = :v_hash and record_created = :v_range',
'ExpressionAttributeValues' => array (
':v_hash' => array('S' => $rep_num),
':v_range' => array('N' => $record_created)
),
));
KeyConditionExpression is a parameter used for Query.
The condition that specifies the key value(s) for items to be retrieved by the Query action.
You are trying to call UpdateItem, which requires Key. You are getting the validation error because you have not set the required request parameter Key.
I got an issue here. I am trying make a request to a Web Appi: http://www.speedex.gr/getvoutrans/getvoutrans.asmx?WSDL
And I am sending a request to insertPodData();
I am using PHP and SOAP.
I am succesfull at connecting and giving the correct credentials. However I am not able to send a Dataset (cause I do not know the right way), so i get an empty dataset.
Datasets are for .NET lang. So it is kind of tricky with the php.
I tried already to send it as an array, i still get an empty result.
Here are some coding.
PHP:
$dataset = array(
'schema' => array(
'Enter_Branch_Id' => $speedex_branch_id,
'SND_Customer_Id' => $speedex_cust_id,
'SND_Agreement_Id' => $speedex_appi_key,
'RCV_Name' => 'Test',
'RCV_Addre1' => 'Test Adress',
'RCV_Zip_Code' => '54636',
'RCV_City' => 'Thessaloniki',
'RCV_Country' => 'Greece',
'RCV_Tel1' => '*******',
'Voucher_Weight' => '0',
),
'any' => ''
);
try {
$soap = new SoapClient("http://www.speedex.gr/getvoutrans/getvoutrans.asmx?WSDL",array('trace' => true));
$oAuthResult = $soap->insertPodData(
array(
'username' => $speedex_usrn,
'password' => $speedex_psw,
'VoucherTable' => $dataset,
'_tableFlag' => 3
)
);
$resultVoucher = $oAuthResult;
print_r($resultVoucher);
echo '<br>';
echo "REQUEST:\n" . htmlentities($soap->__getLastRequest()) . "\n";
die();
}catch(SoapFault $fault) {
die('<h1>Ooooops something is broken. Refresh or contact module creator </h1><br>'.$fault);
}
This is returning this result
RESULT: stdClass Object ( [insertPodDataResult] => 1 [newVoucherTable] => stdClass Object ( [schema] => [any] => ) )
REQUEST:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:insertPodData>
<ns1:username>****</ns1:username>
<ns1:password>****</ns1:password>
<ns1:VoucherTable>********************TestTest Adress54636ThessalonikiGreece********</ns1:VoucherTable>
<ns1:_tableFlag>3</ns1:_tableFlag>
</ns1:insertPodData>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
As you can observe the Dataset is not created and all the values are passed with out a reference.
Any ideas clues? Thanks in advance!
There are many questions relating to this online which are just unanswered and I am looking for a solution all over the place.
So I have a Soap Server with NuSoap and I am trying to return an array of database rows (modelled here as a hardcoded list of PS4 game entities).
The code below here works (with slight modification) for returning a single array, however I am unable to get more than 1 of them to be returned.
Does anyone have a solution for this as I have spent the day trying various solutions from online as well as the code below:
//Settings
$ns = 'http://'.$_SERVER['HTTP_HOST'].'/index.php/soapserver/';
$this->load->library("Nusoap_library");
$this->nusoap_server = new soap_server();
$this->nusoap_server->configureWSDL("Nusoap Server", $ns);
$this->nusoap_server->wsdl->schemaTargetNamespace = $ns;
//Complex Types and Function registers on server
// Complex Type "Game":
$this->nusoap_server->wsdl->addComplexType(
'Game', // the type's name
'complexType',
'struct',
'all',
'',
array(
'title' => array('name'=>'title','type'=>'xsd:string'),
'description' => array('name'=>'description','type'=>'xsd:string'),
'price' => array('name'=>'price','type'=>'xsd:string'),
)
);
// Complex Type "Games" (array of Game):
$this->nusoap_server->wsdl->addComplexType(
'Games',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array(
'ref'=>'SOAP-ENC:arrayType',
'wsdl:arrayType'=>'tns:Game[]'
)
),
'tns:Game'
);
// Get_Games
$this->nusoap_server->register(
'get_games',
array('instance_id' => 'xsd:string'),
array('return'=>'tns:Games'),
'',
false,
'rpc',
'encoded',
'Return array of Games'
);
// [REGISTERED METHODS]:
function get_games($instance_id)
{
// [Hardcoded Games list]:
$games = array(
array(
'title' => 'Killzone: Shadow Fall',
'description' => 'test desc ',
'price' => '49.99'
),
array(
'title' => 'Battlefield',
'description' => 'blah blah',
'price' => '54.99'
)
);
return $games;
}
QUESTION:
What changes do I need to make to the above code to get this server to return an array of game entities.
It works fine if I return $games[0] with some minor changes to the code, however I can not seem to get the above code to work.
Any help or advice appreciated...
EDIT:
I consistantly get the following error:
Error
XML error parsing SOAP payload on line 10: Invalid document end
Response
HTTP/1.1 200 OK
Date: Sun, 16 Mar 2014 20:35:35 GMT
Server: Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.5.6
X-Powered-By: PHP/5.5.6
X-SOAP-Server: NuSOAP/0.9.5 (1.123)
Content-Length: 1688
Content-Type: text/xml; charset=ISO-8859-1
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message: Array to string conversion</p>
<p>Filename: lib/nusoap.php</p>
<p>Line Number: 6132</p>
</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message: Array to string conversion</p>
<p>Filename: lib/nusoap.php</p>
<p>Line Number: 6132</p>
</div><?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://localhost/index.php/soapserver/"><SOAP-ENV:Body><ns1:get_gamesResponse xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"><return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:Game[2]"><item xsi:type="tns:Game"><title xsi:type="xsd:string">Killzone: Shadow Fall</title><description xsi:type="xsd:string">test desc</description><price xsi:type="xsd:string">49.99</price></item><item xsi:type="tns:Game"><title xsi:type="xsd:string">Battlefield</title><description xsi:type="xsd:string">blah blah</description><price xsi:type="xsd:string">54.99</price></item></return></ns1:get_gamesResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
This is what I did:
// Complex Array Keys and Types ++++++++++++++++++++++++++++++++++++++++++
$server->wsdl->addComplexType('notaryConnectionData','complexType','struct','all','',
array(
'id' => array('name'=>'id','type'=>'xsd:int'),
'name' => array('name'=>'name','type'=>'xsd:string')
)
);
// *************************************************************************
// Complex Array ++++++++++++++++++++++++++++++++++++++++++
$server->wsdl->addComplexType('notaryConnectionArray','complexType','array','','SOAP-ENC:Array',
array(),
array(
array(
'ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:notaryConnectionData[]'
)
)
);
// *************************************************************************
// This is where I register my method and use the notaryConnectionArray
$server->register("listNotaryConnections",
array('token' => 'xsd:string'),
array('result' => 'xsd:bool', 'notary_array' => 'tns:notaryConnectionArray', 'error' => 'xsd:string'),
'urn:closingorder',
'urn:closingorder#listNotaryConnections',
'rpc',
'encoded',
'Use this service to list notaries connected to the signed-in title company.');
// In my function, I query the data and do:
$list = array();
$results = mysql_query($query);
while($row = mysql_fetch_assoc($results)) {
array_push($list, array('id' => intval($row['na_id']), 'name' => $row['agency_name']));
}
return array("result" => true, "notary_array" => $list);
// The output is:
Array
(
[result] => 1
[notary_array] => Array
(
[0] => Array
(
[id] => 1
[name] => Agency 1
)
[1] => Array
(
[id] => 3
[name] => Agency 3
)
[2] => Array
(
[id] => 4
[name] => Agency 4
)
)
[error] =>
)
Hope this helps.
I have made a web service: client & server wich works fine in my browser but when I add it into my references, I can't access my function!
here is my code of the web server:
<?php
require 'nusoap.php';
$server=new nusoap_server();
$server->configureWSDL("demo","urn:demo");
$server->soap_defencoding = 'utf-8';
$server->wsdl->addComplexType('getAllKeyData','complexType','struct','all','',
array(
'id'=> array('name'=>'id', 'type' =>'xsd:int'),
'emailadres'=> array('name'=>'emailadres', 'type' =>'xsd:String'),
'familienaam'=> array('name'=>'familienaam', 'type' =>'xsd:String'),
'paswoord'=> array('name'=>'paswoord', 'type' =>'xsd:String'),
'status'=> array('name'=>'status', 'type' =>'xsd:String'),
'voornaam'=> array('name'=>'voornaam', 'type' =>'xsd:String')
)
);
$server->wsdl->addComplexType(
'MySoapObjectArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:getAllKeyData[]')),'tns:getAllKeyData');
$server->register(
'getAllKeys', //name of function
array(), //inputs
array('return'=>'tns:MySoapObjectArray'), //outputs
'urn:getAllKeyswsdl',
'urn:getAllKeyswsdl#getAllKeys',
'rpc',
'encoded',
'Processes an array of MySoapObjects and returns one of them'
);
function getAllKeys(){
$con=mysql_connect('localhost','root','')or die("cannot connect");
mysql_select_db('test')or die("cannot select db");
$sql = 'Select * from personen';
$result=mysql_query($sql,$con);
$out=array();
while($row = mysql_fetch_assoc($result))
{
$out[]=$row;
}
return $out;
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
Of course I tested this with my web client and I can see my data perfectly in arrays:
[0] => Array
(
[id] => 1
[emailadres] => braril.com
[familienaam] => Vandenbogaerde
[paswoord] => test
[status] => aktief
[voornaam] => Bram
)
[1] => Array
(
[id] = 50
[emailadres] => koeaenussel.be
[familienaam] => Christiaens
[paswoord] => HoofdletterH
[status] => aktief
[voornaam] => Koen
)
[2] => Array
(
[id] => 5
[emailadres] => som
[familienaam] => Furler
[paswoord] => Titanium
[status] => aktief
[voornaam] => Sia Kate Isobelle
)
Now I added my webserver into my service references
and afterwards I declared my service just like this:
var client2 = new ServiceReference2.demoPortTypeClient();
But my big problem is now that I can't use my function that I made in my web server!
http://prntscr.com/319wv2
If you have any idea, please help!
problem solved:
$server->register(
'getAllKeys', //name of function
array(), //inputs
array('return'=>'xsd:Array'), //outputs
'urn:getAllKeyswsdl',
'urn:getAllKeyswsdl#getAllKeys',
'rpc',
'encoded',
'Processes an array of MySoapObjects and returns one of them'
);
The return type had to be: xsd:Array