PHP Soapclient returns object has no property - php

When sending a request from my PHP soapclient as described below, I get:
[getInterestAndExchangeRates failed: Please check inparameters in Xxx].
I suspect that it is the [$response] line that has wrong syntax. More specific the [$searchRequestParameters]. I have checked that all the content in the array is in the correct order.
Question:
Is there something wrong with below code syntax?
I have followed following instructions:
https://swea.riksbank.se/sweaWS/docs/api/call/getInterestAndExchangeRates.htm
<?php
/**
* A soapclient request to Swedish Central bank, API.
*/
$client = new SoapClient("https://swea.riksbank.se/sweaWS/wsdl/sweaWS_ssl.wsdl");
$searchGroupSeries = array(
"groupid" => 2,
"seriesid" => "SECBREPOEFF"
);
$searchRequestParameters = array (
"aggregateMethod" => "W",
"avg" => true,
"datefrom" => "2018-01-01",
"dateto" => "2019-01-01",
"languageid" => "en",
"max" => true,
"min" => false,
"searchGroupSeries" => $searchGroupSeries,
"ultimo" => false
);
// Test 1 (pointing out above array, does not work):
$response = $client->__soapCall("getInterestAndExchangeRates", $searchRequestParameters);
// Test 2 (wrap in above array inside another array, does not work):
// $response = $client->__soapCall('getInterestAndExchangeRates', array('searchRequestParameters' => $searchRequestParameters));
var_dump($response);
Error:
PHP Fatal error: Uncaught SoapFault exception: [soap:Server] getInterestAndExchangeRates failed: Please check inparameters in [path]_(does_not_work).php:22
Stack trace:
#0 [path]_(does_not_work).php(22): SoapClient->__soapCall('getInterestAndE...', Array)
#1 {main}
thrown in [path]_(does_not_work).php on line 22

Related

First time using the PHP SOAP client

I've started writing some code to use SOAP within PHP.
Managed to get my code to login and authenticate, which is a start!
I initially had the following code :
$params = array(
"Parcels" => 1,
"RecipientAddress" => "123 Any Street, Any Town, Anywhere",
"RecipientName" => "Joe Bloggs",
"CollectionDate" => "2019-11-11",
);
// Invoke WS method (Function1) with the request params
$response = $client->__soapCall("GetAvailableServices", array($params));
// Print WS response
var_dump($response);
Which returned the following message :
Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Client] Missing Recipient Address Element 'RecipientName' in /home/thisone/public_html/despatchbayservices.php:17 Stack trace: #0 /home/thisone/public_html/despatchbayservices.php(17): SoapClient->__soapCall('GetAvailableSer...', Array) #1 {main} thrown in /home/thisone/public_html/despatchbayservices.php on line 17
I've tried changing the code to :
$params = array(
"Parcels" => 1,
"RecipientAddress" => array(
"RecipientName" => "Joe Bloggs",
),
"CollectionDate" => "2019-11-11",
);
// Invoke WS method (Function1) with the request params
$response = $client->__soapCall("GetAvailableServices", array($params));
// Print WS response
var_dump($response);
Which returned this :
Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object has no 'RecipientAddress' property in /home/thisone/public_html/despatchbayservices.php:18 Stack trace: #0 /home/thisone/public_html/despatchbayservices.php(18): SoapClient->__soapCall('GetAvailableSer...', Array) #1 {main} thrown in /home/thisone/public_html/despatchbayservices.php on line 18
I'm sure I'm doing something really stupid but I just cant see it - any help massively appreciated!
Sussed it - thanks to Don't Panic for pointing me toward the WDSL.
For reference the correct/working code is :
$params = array(
"Parcels" => array(
"ParcelType" => array(
"Weight" => 5,
"Length" => 5,
"Width" => 5,
"Height"=> 5,
)
),
"RecipientAddress" => array(
"RecipientName" => "Joe Bloggs",
"RecipientAddress" => array(
"CompanyName" => "My Company",
"Street" => "123 Any Street",
"Locality" => "Anywhere",
"TownCity" => "Any Town",
"County" => "Somewhere",
"PostalCode" => "TS23 4EA",
"CountryCode" => "GB",
)
),
"CollectionDate" => "2019-11-11",
);
// Invoke WS method (Function1) with the request params
$response = $client->__soapCall("GetAvailableServices", array($params));

Why did my SOAP request start returning error

I'm trying to make a SOAP request with TNT's webservice, but I'm getting an error and I don't know what to do.
There is my code:
$client = new SoapClient('http://ws.tntbrasil.com.br:81/tntws/CalculoFrete?wsdl');
$function = 'calculaFrete';
$parameters = array('calculaFrete' => array('in0' => array(
'cdDivisaoCliente' => 1,
'cepDestino' => '36213000',
'cepOrigem' => '36213000',
'login' => 'gerencia#uaiartesanatos.com.br',
'nrIdentifClienteDest' => '00000000000',
'nrIdentifClienteRem' => '29026107000190',
'nrInscricaoEstadualDestinatario' => '0000000000000',
'nrInscricaoEstadualRemetente' => '0030746110022',
'psReal' => 15,
'senha' => '',
'tpFrete' => 'C',
'tpPessoaDestinatario' => 'F',
'tpPessoaRemetente' => 'J',
'tpServico' => 'RNC',
'tpSituacaoTributariaDestinatario' => 'CO',
'tpSituacaoTributariaRemetente' => 'CO',
'vlMercadoria' => 650.17,
)));
$result = null;
$result = $client->__soapCall($function, $parameters);
and i'm getting this error
Fatal error: Uncaught SoapFault exception: [ns0:Server] java.lang.NullPointerException in C:\xampp\htdocs\tnt\index.php:27 Stack trace: #0 C:\xampp\htdocs\tnt\index.php(27): SoapClient->__soapCall('calculaFrete', Array) #1 {main} thrown in C:\xampp\htdocs\tnt\index.php on line 27
I've been using it since 2018, but in recent weeks this error has started to occur, does anyone know what is going on ??
I thank you all for your help
The error is coming from the webservice.
java.lang.NullPointerException is a exception thrown by Java.
It may be some update that broke the webservice, some new parameter that you are not sending or some wrong parameter.
I suggest you to get in touch with the webservice owners.

Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object hasn't 'source' property in

I am trying to connect osticket support system with opencart.
I tried to integrate with this SOAP
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$osticket = new SoapClient('http://www.website.com/osticket/api/soap/index.php?wsdl');
// Set up the parameters
$args = array(
'username' => 'WebService',
'password' => 'MySecr3tp#ssword',
'origin' => 'Web',
'alertUser' => true,
'alertStaff' => true,
'ticketData' => array(
'name' => utf8_encode('sir Test'),
'email' => utf8_encode('some#email.com'),
'subject' => utf8_encode('testing'),
'message' => utf8_encode('this is a message'),
'topicId' => 3, //topic Website Support
'deptId' => 2, //department Sales
'staffId' => null,
'duedate' => null,
'time' => null,
'pri' => 2, // default priority
'phone' => null,
)
);
try {
// Send the request and receive the ticketID
$result = $osticket->__call('ostTicket.open',$args);
}
catch (SoapFault $e) {
throw $e;
}
?>
The error I get is
Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object hasn't 'source' property in /home/website/website.com/catalog/view/theme/testtheme/template/information/contact.tpl:60
Stack trace:
#0 /home/website/website.com/catalog/view/theme/testtheme/template/information/contact.tpl(60): SoapClient->__call('ostTicket.open', Array)
#1 /home/website/website.com/vqmod/vqcache/vq2-system_engine_controller.php(67): require('/home/website/tu...')
#2 /home/website/website.com/catalog/controller/information/contact.php(127): Controller->render()
#3 /home/website/website.com/vqmod/vqcache/vq2-system_engine_front.php(43): ControllerInformationContact->index()
#4 /home/website/website.com/vqmod/vqcache/vq2-system_engine_front.php(29): Front->execute(Array, Array)
#5 /home/website/website.com/index.php(238): Front->dispatch(Object(Action))
#6 {main} thrown in/home/website/website.com/catalog/view/theme/testtheme/template/information/contact.tpl on line 60
Here is the line 60 (/template/information/contact.tpl):
$result = $osticket->__call('ostTicket.open',$args);
I'd be grateful if anyone kindly help me in this issue.
SOAP Info
This is from phpinfo
Soap Client enabled
Soap Server enabled
Directive Local Value Master Value
soap.wsdl_cache 1 1
soap.wsdl_cache_dir /tmp /tmp
soap.wsdl_cache_enabled 1 1
soap.wsdl_cache_limit 5 5
soap.wsdl_cache_ttl 86400 86400
I'm also having same problem, and I've been searching the web and found no answer. So, I traced it myself. And I loved to share how I fixed it.
As you can see on the http://www.website.com/osticket/api/soap/index.php?wsdl (change it to your URL)
under the ( xsd:complexType name="TicketData" ),which parameters needed for ostTicket.open
you can see that there's an element (xsd:element name="source" type="xsd:string") named source, so that's what is missing on the ticketData array. Just add that inside your ticketData array, can be assigned w/ null.
ex. 'source' => null,
This solved my problem. Hope it helps.

How to change the namespace sent with a SOAP request?

Related to this question: How to request an answer from a SOAP XML API?
I have this PHP script sending the request with the required fields:
$client = new SoapClient('https://live.domainbox.net/?WSDL');
$params = array(
'AuthenticationParameters' => array(
'Reseller' => 'resellername',
'Username' => 'myusername',
'Password' => 'mypassword'
),
'CommandParameters' => array(
'DomainName' => 'mydomain.com',
'LaunchPhase' => 'GA'
)
);
$result = $client->CheckDomainAvailability($params);
print_r($result);
I get the following error message:
Fatal error: Uncaught SoapFault exception: [soap:VersionMismatch]
Possible SOAP version mismatch: Envelope namespace
http://schemas.xmlsoap.org/soap/envelope/ was unexpected.
Expecting http://www.w3.org/2003/05/soap-envelope. in
/home/nosa/public_html/dev/check-domain-availability.php:20 Stack
trace: #0
/home/nosa/public_html/dev/check-domain-availability.php(20):
SoapClient->__call('CheckDomainAvai...', Array) #1
/home/nosa/public_html/dev/check-domain-availability.php(20):
SoapClient->CheckDomainAvailability(Array) #2 {main} thrown in
/home/nosa/public_html/dev/check-domain-availability.php on line 20
I removed and recompiled apache to include the latest SOAP version available using WHM/cPanel.
My question is:
How do I send the correct envelope namespace?
When building your soap_client object, you can pass an option's array, by default, the version will be 1.1 as per php documentation.
The error you have seems to point out that the service might be SOAP 1.2 so you need to set it to 1.2...
$client = new SoapClient('https://live.domainbox.net/?WSDL', array('soap_version' => SOAP_1_2));
Try that out!

Consume ASP.NET WebService In php and return soap error

i am trying to calling .net webservice in php
below is my code.
<?php
$client = new SoapClient("http://test.etech.net/PanelIntegration/PanelIntegration.asmx?wsdl");
<?php
$sh_param = array(
'Username' => 'IntegratorLPI',
'Password' => 'password531');
$headers = new SoapHeader('http://wms.etech.net/', 'UserCredentials', $sh_param);
$client->__setSoapHeaders($headers);
$params = array('CustomerName' => 'Mr Smith','ContactMobileNo' => '01237 376347',
'AddressLine1' => '33 Amblecote Road',
'AddressTown' => 'Cambridgeshire',
'AddressPostCode' => 'NW23 6TR',
'VendorAddressLine1' => '80 Norton Road',
'VendorAddressTown' => 'Hickley ',
'VendorAddressCounty' => 'Cambridgeshire',
'VendorAddressPostCode' => 'NW23 2AQ',
'RegionalOfficeID' => '3',
'ExternalNotes' => 'Case Accepted',
'UPRN' => '',
'InstructionTypeID' => '2',
'PropertyTypeID' => '11',
'PropertyTenure' => '2',
'SurveyorID' => '23',
'RRN' => '0240-9002-0391-3520-0020',
'NewInstruction'=> 'true',
'StatusID' => '1'
);
$result = $client->__soapCall("UpdateInstruction", $params );
print_r( $result);
?>
i have got this error
Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in C:\xampp\htdocs\test2.php:33 Stack trace: #0 C:\xampp\htdocs\test2.php(33): SoapClient->__soapCall('UpdateInstructi...', Array) #1 {main} thrown in C:\xampp\htdocs\test2.php on line 33
You probably need to send something like:
$result = $client->__soapCall("UpdateInstruction", array('Instruction' => $params );
Where Instruction is the name of the object that you are passing.
It looks like a NullReferenceException was thrown on the server side. So, it's a matter of the parameters to whatever function is occurring on the server side generating that error.
Regardless of why, per best practices, this is an error in the .NET service. The NullReferenceException should really be replaced with something more specific.
Can you get in touch with whomever wrote the service to get more information to troubleshoot? It's quite possible that you have a parameter misnamed in your $params array, but you're probably going to need some help from the service writer.

Categories