Windows store app won't recognize function of web service - php

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

Related

authentication to MQ via mqseries library php

I need some help with php mqseries library.
I have some troubles connecting to Queue-manager. It does connect without authentication, but when I'm trying to use MQCSP, I get
2035 error.
I've contacted the developers, one of them told me that he no longer works on it, others don't respond.
It looks like on IBM it doesn't work.
Here is my connection code:
$cfg = array();
$cfg['ESB_ADDRESS'] = '10.4.116.110(1416)';
$cfg['ESB_CHANNEL'] = 'SITEEXT.SVRCONN';
$cfg['ESB_QUEUE_MANAGER'] = 'IIB.ADP.MI1';
$cfg['ESB_QUEUE_NAME'] = 'SITEEXT_TO_ESB';
$cfg['ESB_TOPIC_STRING'] = '';
$cfg['USERID'] = 'svcgo-site';
$cfg['PASSWORD'] = 'site91';
$cfg['QMgrName'] = 'IIB.ADP.MI1';
$cfg['DiscInterval'] = '10';
/*
$cfg['ESB_ADDRESS'] = '10.4.111.139(1414)';
$cfg['ESB_CHANNEL'] = 'SITEEXT.SVRCONN';
$cfg['ESB_QUEUE_MANAGER'] = 'QM01';
$cfg['ESB_QUEUE_NAME'] = 'TEST_QUEUE1';
//$cfg['ESB_QUEUE_NAME'] = 'SITEEXT_TO_ESB';
$cfg['ESB_TOPIC_STRING'] = '';
$cfg['USERID'] = 'svcgo-site';
$cfg['PASSWORD'] = 'site91';
//$cfg['QMgrName'] = 'QM01';
$cfg['DiscInterval'] = '10';
*/
$connectionOptions = array(
'StrucId' => MQSERIES_MQCNO_STRUC_ID,
'Version' => MQSERIES_MQCNO_CURRENT_VERSION,
'Options' => MQSERIES_MQCNO_STANDARD_BINDING,
//MQSERIES_USE_MQCSP_AUTHENTICATION,
'MQCD' => array(
//'Version' => MQSERIES_MQCD_VERSION_11,
'ChannelName' => $cfg['ESB_CHANNEL'],
'TransportType' => MQSERIES_MQXPT_TCP,
'ConnectionName' => $cfg['ESB_ADDRESS']
),
MQSERIES_USE_MQCSP_AUTHENTICATION => true,
MQSERIES_MQCSP_AUTHENTICATION => true,
USER_AUTHENTICATION_MQCSP => true,
USE_MQCSP_AUTHENTICATION => true,
MQSERIES_USER_AUTHENTICATION_MQCSP => true,
useMQCSPAuthentication => true,
'MQCSP' => array(
'Version' => MQSERIES_MQCSP_CURRENT_VERSION,
'StrucId' => MQSERIES_MQCSP_STRUC_ID,
'AuthenticationType' => MQSERIES_MQCSP_AUTH_USER_ID_AND_PWD,
'CSPUserIdPtr' => $cfg['USERID'],
'CSPUserIdLength' => strlen($cfg['USERID']),
'CSPPasswordLength' => strlen($cfg['PASSWORD']),
'CSPPasswordPtr' => $cfg['PASSWORD']
),
/*
'ClientConnPtr' => array(
//'Version' => MQSERIES_MQCD_VERSION_11,
'ChannelName' => $cfg['ESB_CHANNEL'],
'TransportType' => MQSERIES_MQXPT_TCP,
'ConnectionName' => $cfg['ESB_ADDRESS']
)
*/
);
mqseries_connx($cfg['ESB_QUEUE_MANAGER'], $connectionOptions, $connection, $completionCode, $reason);
if ($completionCode !== MQSERIES_MQCC_OK) {
die("Connx CompCode : {$completionCode} Reason : {$reason} Text : " . mqseries_strerror($reason));
}
else{echo "Good<br>";}
Php v.5.3.17
IBM MQ 9
Mqseries client library v 0.15.0
That PHP package does not have the code in it to handle the MQCSP structure and add it to the CNO. Looks like you would need to modify the _mqseries_set_mqcno_from_array function and how it is called.

Trying to get property of non-object from a returned object

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));

XML to PHP SOAP request

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

Nusoap php Response not of type

I try to create a nusoap client and a nusoap server. I got 2 operations declared but only one works.
There is my server_soap code;
$servidor = new nusoap_server();
$ns = "urn:AvertisWebService";
$servidor->configureWSDL("AvertisWebService",$ns);
$servidor->wsdl->schemaTargetNamespace = $ns;
$servidor->register(
"responseCorrecto",
array("numeroIN" => "xsd:Integer"),
array("return" => "xsd:Integer"), $ns);
$servidor->register(
"responseIncidencia",
array("incNomb" => "xsd:String",
"incTelf" => "xsd:String",
"incNif" => "xsd:String",
"incMun" => "xsd:String",
"incLoc" => "xsd:String",
"incCalle" => "xsd:String",
"incCp" => "xsd:String",
"incCordX" => "xsd:String",
"incCordY" => "xsd:String",
"incText" => "xsd:String"),
array("return" => "xsd:Integer"), $ns);
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : "";
$servidor->service($HTTP_RAW_POST_DATA);
function responseIncidencia(
$incNomb, $incTelf, $incNif, $incMun, $incLoc,
$incCalle, $incCp, $incCordX, $incCordY, $incText
){ [...]
And there is where i call my server:
include_once "lib/nusoap/nusoap.php";
include_once "lib/cargadorConf.php";
$conf = new cargadorCONF();
$cliente = new nusoap_client($conf->CONF["webServiceUrl"],true);
$param = array("numeroIN" => 5);
$resultado = ($cliente->call("responseCorrecto", $param));
echo $resultado; //Must be 50
$param = array(
"incNomb" => "javier", "incTelf" => "645876321" , "incNif" => "1254789" ,
"incMun" => "municipio" , "incLoc" => "localidad" , "incCalle" => "calle" ,
"incCp" => "36544" , "incCordX" => "1.2334" , "incCordY" => "-3.56634" , "incText" => "Hola Mundo");
$resultado = ($cliente->call("responseIncidencia", $param));
echo "resultado= ".$resultado;
echo $resultado; //Must be 1
This code returns:
50
And
Response not of type text/xml: text/html; charset=UTF-8
The first operation works fine but the second i got always this error.
I resolve this.
I got a internal problem in function "responseIncidencia" and SOAP try to return a PDOException. Then the client recibe a error on parsing.

Pass multidimensional array to soap complexType in PHP

I am pulling some emails from my mail server. There is a function should pull these emails and return a multidimensional array. I use this array in client web server to do the job for me. I don't know how to pass this array to the soap complexType. I wrote the following code:
$server->wsdl->addComplexType(
'MailTicket',
'complexType',
'struct',
'all',
'',
array(
'attachment' => array('name' => 'attachment', 'type' => 'xsd:string'),
'body' => array('name' => 'body', 'type' => 'xsd:string'),
'accountID' => array('name' => 'accountID', 'type' => 'xsd:string')
)
);
$server->wsdl->addComplexType(
'MailTicketReturn',
'complexType',
'struct',
'all',
'',
array(
'Done' => array('name' => 'result', 'type' => 'xsd:string')
)
);
// Register the method to expose
$server->register('createMailTicket', // method name
array('mailTicketData' => 'tns:MailTicket'), // input parameters
array('return' => 'tns:MailTicketReturn'), // output parameters
'urn:eticketing', // namespace
'urn:eticketing#createMailTicket', // soapaction
'rpc', // style
'encoded', // use
'create a ticket by mail' // documentation
);
and on the client, I wrote:
require_once('nusoap.php');
$wsdlURL="http://127.0.0.1/eticket/ETKWS.php?wsdl";
$client = new nusoap_client($wsdlURL,true);
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = false;
$finalArray=Array
(
[attachment] => Array
(
[0] => Array
(
[0] => file1
[1] => file2
)
[1] => Array
(
[0] => file1x
)
)
[body]=>Array
(
[0] => some text
[1] => some other text
)
[accountID] => Array
(
[0] => 5464654
[1] => 4654664
)
)
if(is_array($finalArray)) // creat new tickets
{
$result=$client->call('createMailTicket',$finalArray);
}
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
exit();
}
I got this error:
Constructor error
XML error parsing SOAP payload on line 1: Not well-formed (invalid token)
NuSOAP support return multidimensional array (xsd:Array)
$server= new nusoap_server();
$namespace = "http://localhost/webservice/";
// create a new soap server
$server = new nusoap_server();
// configure our WSDL
$server->configureWSDL("WebServices212");
// set our namespace
$server->wsdl->schemaTargetNamespace = $namespace;
$server->register(
// method name:
'test',
// parameter list:
array('id'=>'xsd:int'),
// return value(array()):
array('return'=>'xsd:Array'),
// namespace:
$namespace,
// soapaction: (use default)
false,
// style: rpc or document
'rpc',
// use: encoded or literal
'encoded',
// description: documentation for the method
'documentation');
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA'])
? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
// pass our posted data (or nothing) to the soap service
$server->service($POST_DATA);
Client
client=new nusoap_client("http://localhost/webservice /webservices.php?wsdl");
$client->setCredentials("webadmin","****");
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$result = $client->call('test', array('id' => '1'));
print_r($result);
if you consume the webservices from PHP no problem, but in other languages there are compatibility problems

Categories