NuSoap, XML was empty, couldn't parse - php

First, I have to say that I am totally new to WSDL-based Web Services using NuSOAP. I am trying to return an array of friends list from my soap server. Please find below my code listings as is:
Server:
//File includes omitted
function getFriendList($test = ''){
$results = array();
$results[] = array('name' => 'XXXXA1', 'surname' => 'XXXXA2');
$results[] = array('name' => 'XXXXXB1', 'surname' => 'XXXXB2');
$results[] = array('name' => 'XXXXXC1', 'surname' => 'XXXXC2');
return $results;
}
//Create server instance
$server = new soap_server();
//Configure our WSDL
$server->configureWSDL('server', 'urn:server');
//Add our Complex Type data type since we want to return an array
$server->wsdl->addComplexType(
'Friend',
'complexType',
'struct',
'all',
'',
array(
'name' => array('name' => 'name', 'type' => 'xsd:string'),
'surname' => array('name' => 'surname', 'type' => 'xsd:string')
)
);
//Register our array as a response
$server->wsdl->addComplexType(
'FriendArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:Friend[]')
),
'tns:Friend'
);
//Register the actual function that retuns the array but in the
//return n field specify the complex type of array we added onto the wsdl
$server->register('getFriendList',
array('test' => 'xsd:string'),
array('return' => 'tns:FriendArray'),
'urn:server',
'urn:server#getFriendList',
'document',
'encoded',
'Fetch a list of friends as an array. If you\'re not here sorry.'
);
//Serve the service
$server->service($HTTP_RAW_POST_DATA = (!isset($HTTP_RAW_POST_DATA)) ? $HTTP_RAW_POST_DATA : '');
With this, I hoped that I did everything correctly. I followed the standard procedure to make it work but in vein.
On the client side, I used the soap address url in wsdl and appended it with "?wsdl", so that it give me wsdl file dynamically.
example:
//Client call
$client = new nusoap_client("http://soapserver.dev/webroot/part_three/server.php?wsdl", true);
I have also taken labour of adding some whistles and bells on my client object as shown below:
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = false;
This doesn't seem to help at all. I had experienced an issue earlier since my function accepts no parameter, where my service died because I didnt pass any parameter that speaks of inputs in my $client->call($name, $in, $out). I ended up providing an empty array and I got this error.
Could this be related to the rpc/document parameter types of the register function?
Even using the wsdl file which I saved from my server url, I got the same error.
Can somebody please help me out here? Please!

Related

How to send multi response using nusoap with soapval?

I am stuck in a situation where I am unable to send multi-response not array type using soapval(nusoap). I looking for a solution to make struct which accepts multi-request and send multi-response in nusoap. I saw a lot of examples where I only saw the response as an array this is the main issue I think so.
Let me show you my code
$server->wsdl->addComplexType(
'InitiateHolidayDataTransferResult',
'complexType',
'struct',
'sequence',
'',
array( 'HOLIDAY_COMPLEX_TYPE_RES' => array(
'name' => 'HOLIDAY_COMPLEX_TYPE_RES', 'type' => 'tns:HOLIDAY_COMPLEX_TYPE_RES' ,'minOccurs' => '0', 'maxOccurs' => 'unbounded' )
)
);
$server->wsdl->addComplexType(
'HOLIDAY_COMPLEX_TYPE_RES',
'complexType',
'struct',
'all',
'',
array( 'STATUS' => array('name' => 'STATUS','type' => 'xsd:string'),
'STATUS_DESC' => array('name' => 'STATUS_DESC','type' => 'xsd:string')
));
// Register the method to expose
$server->register('HOLIDAY_INFORMATION_DATA', // method name
array('name' => 'tns:HOLIDAY_COMPLEX_TYPE_REQ'), // input parameters
array('return' => 'tns:HOLIDAY_COMPLEX_TYPE_RES'), // output parameters
'urn:HOLIDAY_SERVER1', // namespace
'urn:HOLIDAY_SERVER1#HOLIDAY_INFORMATION_DATA', // soapaction
'document', // style
'encoded', // use
'Holiday Information Get Method' // documentation
);
// Define the method as a PHP function
function HOLIDAY_INFORMATION_DATA($mycomplextype) {
$holiday_data_success='';
// trying to send multi reponse in many ways see below
foreach($mycomplextype as $key=>$val){
//one way
$parm = array();
$parm[] = array('STATUS'=>"Success", "STATUS_DESC"=>"-Holiday Added");
$parm[] = array('STATUS'=>"Success", "STATUS_DESC"=>"-Holiday Added");
$parm[] = array('STATUS'=>"Success", "STATUS_DESC"=>"-Holiday Added");
$holiday_data_success = new soapval('return', 'tns:HOLIDAYRES_COMPLEX_TYPE_RES', $parm);
//second way
$arr = array("STATUS"=>"12345", "STATUS_DESC"=>"Test heading",);
$arr2 = array("STATUS"=>"12346", "STATUS_DESC"=>"Test heading");
$holiday_data_success = array($arr, $arr2);
// third way
$holiday_data_success=[];
$holiday_data_success[] = new soapval('return', 'tns:InitiateHolidayRESTransferResult', array('STATUS'=>"Success", "STATUS_DESC"=>$successtr."-Holiday Added"));
} // end foreach
return $holiday_data_success;
}
// but nothing is working
I am unable to send multi-response for each record that I insert in db

POST request in PHP is returning PHP code when file extension is used

I am sending post requests in PHP to get a boolean value from my API (so it should return wither true or false)
This is the code I am using in the file for my API. The file is called users.php
if ($_POST['type'] == "authenticateMinecraft"){
$p = new dibdibs\post(
array(
'url' => 'https://authserver.mojang.com/authenticate',
'data' => array(
'agent' => array(
'name' => 'Minecraft',
'version' => 1
),
'username' => $_POST['username'],
'password' => $_POST['password'],
'clientToken' => "33225A179D9A4E1BDA73C012C1C3CBAB8BD00326883BDBEB6FA682482E40F68D"
)
)
);
$res = $p->json();
if (isset($res["selectedProfile"])){
echo("true");
}
else{
echo("false");
}
}
This is the code I am using to reference it (I am using a class which I have put on Pastebin to actually send the request).
$params = array(
'data' => array(
'type' => 'authenticateMinecraft',
'username' => $mcuname,
'password' => $mcpasswd
),
'url' => "api/users.php"
);
$c = new dibdibs\post($params);
$r = $c->http();
var_dump($r);
Whenever I use the .php fule extension when defining url, the whole PHP code of the API page is returned, but when I remove the extension, only true or false is returned. Why is this and is it a problem that I should be aware of and I should fox?

.Net user can not connect to php Webservice

I have a php Webservice With this code :
require_once('nusoap.php');
require_once('gw.interface.php');
$namespace = 'www.mydomain.com';
$server = new soap_server();
$server->soap_defencoding = 'UTF-8';
$server->decode_utf8 = false;
$server->encode_utf8 = true;
$server->configureWSDL('smsserver', 'urn:smsserver');
$server->wsdl->addComplexType(
'ListArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]')
),
'xsd:string'
);
/**
* SendSMS
**/
$server->register('SendSMS',
array(
'fromNum' => 'xsd:string',
'toNum' => 'xsd:string',
'messageContent' => 'xsd:string',
'messageType' => 'xsd:string',
'user' => 'xsd:string',
'pass' => 'xsd:string'
), array('return' => 'xsd:string'),
$namespace, 'SendSMS', 'rpc', 'encoded', 'send your sms');
function SendSMS($fromNum, $toNum, $messageContent, $messageType, $user, $pass)
{
return gwi::sendsms($fromNum, $toNum, $messageContent, $messageType, $user, $pass);
}
/**
* GetCredit
**/
$server->register('GetCredit',
array(
'user' => 'xsd:string',
'pass' => 'xsd:string'
), array('return' => 'xsd:string'),
$namespace, 'GetCredit', 'rpc', 'encoded', 'check your credit');
function GetCredit($user, $pass)
{
return gwi::GetCredit($user, $pass);
}
/**
* GetStatus
**/
$server->register('GetStatus',
array(
'user' => 'xsd:string',
'pass' => 'xsd:string',
'batchid' => 'xsd:string',
'unique_ids' => 'tns:ListArray'
), array('return' => 'xsd:string'),
$namespace, 'GetStatus', 'rpc', 'encoded', 'get messages delivery status');
function GetStatus($user, $pass, $batchid, $uniqs)
{
return gwi::GetStatus($user, $pass, $batchid, $uniqs);
}
$server->service($HTTP_RAW_POST_DATA);
The Problem is this code worked before i change my webserver from apache to nginx.
i used this code on another server and was ok. the same Code same request.
So when a .Net client wants to connect to My webservice it can Detect My Webservice.
but When it wants to call of one of my methods
get this error in .net :
{"The remote server returned an error: (404) Not Found."}
and the client code For Example in Vb
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim x As ServiceReference2.
smsserverPortTypeClient = New ServiceReference2.smsserverPortTypeClient()
Dim result As String = "-"
result = x.GetCredit("test", "123456") + " ";
MsgBox(result)
End Sub
Have you tried adding the WS as a Web Reference on your .NET project, instead of a Service Reference? As far as I know, a PHP webservice has to be treated as a web service instead of a common one, as ASMX does.
To do so, follow these simple steps:
Right click on your project in the Solution Explorer.
Click on "Add Service Reference"
Click the "Advanced" button on the bottom-left of the dialog window (I'm sorry if the button has another name, I'm translating these steps from my spanish GUI)
Go again to the bottom-left corner and click the "Add web reference" button.
Add the webservice URL on the field on top, give it a name in the field to the right, and voilá!
The process, then, should be more simple: you use the methods of the WS using the name you gave to the service as a namespace.
I hope this suits you. Good luck!

NuSOAP + PHP , wsdl error: XML error parsing WSDL issue

I'm trying to use nuSOAP to send a array with some data that will be use it on DB, but every time i get this "wsdl error: XML error parsing WSDL issue ... not well-formed (invalid token)" on my client.php
Here is my a little of my code on the server :
$server->register('cadastrar',
array('dados'=>'tns:cadastro'),
array('return'=>'xsd:string'),
$namespace,
$namespace.'#cadastrar',
'rpc',
'encoded',
''
);
$server->wsdl->addComplexType('cadastrar', 'complexType', 'struct', 'all','',
array(
'empresa' =>array ('name'=>'empresa','type'=>'xsd:string')
,'nome' =>array ('name'=>'nome','type'=>'xsd:string')
,'email' =>array ('name'=>'email','type'=>'xsd:string')
,'ddd' =>array ('name'=>'ddd','type'=>'xsd:string')
,'tel' =>array ('name'=>'tel','type'=>'xsd:string')
,'msg' =>array ('name'=>'msg','type'=>'xsd:string')
)
);
function cadastrar($dados){
//$objCliente = new Cliente();
//if($objCliente)
//$id = $objCliente->cadastroWebService($dados);
return $dados['empresa'];
}
and this is my code on the client :
$dados = array(
'empresa' => $_POST['empresa'],
'nome' => $_POST['nome'],
'email' => $_POST['email'],
'ddd' => $_POST['ddd'],
'tel' => $_POST['tel'],
'msg' => $_POST['msg']
);
//Chama o metodo call do SOAP
$result = $client->call('cadastrar', array('cadastro'=> $dados));
Anybody got any idea why isn't working ?
Thanks
I found what i was doing wrong when i was iniciating the client i was missing some arguments...
$client = new nusoap_client('http://www.domain.com/server.php?wsdl&debug=1', 'wsdl');
I just put the wsdl&debug=1', 'wsdl' and it work it

Fedex Web Services: ERROR 9040 - Can't pull up tracking

I'm having issues attempting to pull up tracking info using Fedex's Web Services. I am using a valid tracking number and I'm able to view the details on Fedex's site. However, I get an error 9040 "No information for the following shipments has been received by our system yet. Please try again or contact Customer Service at 1.800.Go.FedEx(R) 800.463.3339." Am I leaving something out?
My code:
<?php
$path_to_wsdl = "URL_TO_WSDL";
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($path_to_wsdl, array('trace' => 1));
$request['WebAuthenticationDetail'] = array(
'UserCredential' =>array(
'Key' => 'MY_KEY',
'Password' => 'MY_PASSWORD'
)
);
$request['ClientDetail'] = array(
'AccountNumber' => 'MY_ACCT',
'MeterNumber' => 'MY_METER'
);
$request['TransactionDetail'] = array('CustomerTransactionId' => 'ActiveShipping');
$request['Version'] = array(
'ServiceId' => 'trck',
'Major' => '5',
'Intermediate' => '0',
'Minor' => '0'
);
$request['PackageIdentifier'] = array(
'Value' => 'TRACKING#',
'Type' => 'TRACKING_NUMBER_OR_DOORTAG');
$response = $client->track($request);
var_dump($response);
?>
Got it!
Call the web services departement and they told me to remove 'beta' from the wsdl file. This appears to be a different address than what I found in responses to this problem before. On line 1507 of the wsdl file, make the following change:
From:
<s1:address location="https://wsbeta.fedex.com:443/web-services/track"/>
To
<s1:address location="https://ws.fedex.com:443/web-services/track"/>
I changed the rest of my code slightly, but that shouldn't have made the difference. To be on the safe side, here it is:
<?php
$path_to_wsdl = "PATH_TO_WSDL_FILE";
$client = new SoapClient($path_to_wsdl, array('trace' => 1));
$trackRequest = array(
'WebAuthenticationDetail' => array(
'UserCredential' => array(
'Key' => 'MY_KEY',
'Password' => 'MY_PASSWORD'
)
),
'ClientDetail' => array(
'AccountNumber' => 'MY_ACCT_#',
'MeterNumber' => 'MY_METER_#'
),
'Version' => array(
'ServiceId' => 'trck',
'Major' => '5',
'Intermediate' => '0',
'Minor' => '0'
),
'PackageIdentifier' => array(
'Type' => 'TRACKING_NUMBER_OR_DOORTAG',
'Value' => 'THE_TRACKING_#',
),
'CustomerTrasactionId',
'IncludeDetailedScans' => 1
);
$response = $client->track($trackRequest);
var_dump($response);
?>
I'm also working on this same problem. I'm trying several things and you can see if anything works for you. Try including ShipDateRangeBegin and End elements, your test account/payer numbers or destination info. I've found here that switching to xml and ssl post requests supposedly solve the problem, but it's not an option for me. Maybe it will help you?
I have same problem when use xml-request. I solved the problem this way:
$endpointurl = "https://gatewaybeta.fedex.com:443/xml"; // remove word "beta"
$endpointurl = "https://gateway.fedex.com:443/xml";
...
$request = stream_context_create($form);
$browser = fopen($endpointurl , 'rb' , false , $request);
$response = stream_get_contents($browser);
...

Categories