Convert old NuSoap code into PHP core soap functions - php

I've been testing nuSoap with codeIgniter (PHP Framework) but seems nuSoap isn't prepared to work with latest php 5.3, even if I download a patched nusoap version for php 5.3
I have the following code:
require_once(APPPATH.'libraries/NuSOAP/lib/nusoap'.EXT); //includes nusoap
$n_params = array('CityName' => 'San Juan', 'CountryName' => 'Argentina');
$client = new nusoap_client('http://www.webservicex.net/globalweather.asmx?WSDL');
$client->setHTTPProxy("10.2.0.1",6588,"","");
$result = $client->call('GetWeather', $n_params);
Can you help me to convert these functions into PHP soap functions? Including proxy function?

require_once(APPPATH.'libraries/NuSOAP/lib/nusoap'.EXT); //includes nusoap
$n_params = array('CityName' => 'San Juan', 'CountryName' => 'Argentina');
$client = new nusoap_client('http://www.webservicex.net/globalweather.asmx?WSDL');
$client->setHTTPProxy("10.2.0.1",6588,"","");
$result = $client->call('GetWeather', $n_params);
becomes
$url = 'http://www.webservicex.net/globalweather.asmx?WSDL';
$params = array(
'proxy_host' => '10.2.0.1',
'proxy_port' => '6588'
);
$client = new SoapClient($url, $params);
$client->__soapCall('GetWeather', $n_params);

The following code was the correct way of calling the above webservice. I've just only modified the $ser_params array. Now it has a sub array
$url = 'http://www.webservicex.net/globalweather.asmx?WSDL';
$conn_params = array(
'proxy_host' => '10.2.0.1',
'proxy_port' => '6588'
);
$ser_params = array (
'GetWeather' => array (
"CityName" => "San Juan",
"CountryName" => "Argentina"
)
);
$client = new SoapClient($url, $conn_params);
$result = $client->__soapCall('GetWeather', $ser_params);
print_r ($result);

Related

Object reference not set to an instance of an object

It tells me that Object reference not set to an instance of an object, when trying to call this SOAP API.
I am doing this way
$client = new SoapClient("http://gateway.XXXXXXX/gateway/api/creditcards/creditcardAPI.asmx?wsdl");
$params = array("clsCreditCardAPIBE" => (Object) array(
"Username" => 'blabla',
"Password" => "Barrel of Oil",
"ProviderPIN" => 500,
"AccountID" => 1234
.......
));
$response = $client->__soapCall("Initiate_Deposit", $params);
What am i doing wrong?
You have to generate the client first, and then start using it
$client = new SoapClient("http://yourdomain.com?wsdl");

How to use php soap instead of nusoap

I've got an specification web app that uses nusoap extension. But on our server runs php 5.5.
I tried to rewrite this example below but its beyond my capabilities...
Here is the script i want to rewrite to use soap in php without nusoap:
<?php
require_once('lib/nusoap.php');
$Client = new nusoap_client( 'https://letsgo-test.org', array( 'encoding'=>'UTF-8' ) );
$Client -> soap_defencoding = 'utf-8';
$Client -> decode_utf8 = FALSE;
$CMsg = array( 'user_name' => 'letsgo', 'user_password' => '123' );
$bClient = $Client->call( 'Login', $CMsg );
$szSession = $bClient[ 'session' ];
$bCPrep = array(
'rname1' => 'Lets',
'rname2' => 'Go',
'rcountry' => 'ORG',
'rzipcode' => '00-770',
);
$CMsg = array( 'session' => $szSession, 'consign_prep_data' => $bCPrep );
$bClient = $Client->call( 'adePreparingBox_Insert', $CMsg );
print_r( $bClient );
$CMsg = array( 'session' => $szSession );
$bClient = $Client->call( 'Logout', $CMsg );
?>
I will be gratefull for any help!!!.
Yep! I found solution!
Its not that hard as i thought,
Some of declarations looks diffrent:
$szSession = $bClient[ 'session' ];
changed to
$szSession = $bClient->session;
instead of "call" you need to use "__soapCall"
So thats what you need to do to free from nusoap.php
I guess there are more things to change but its enought for me.
Best Regards!

NuSoap doesn't work

i'm trying to connect my page to a webservice soap. My hosting doesn't support soap so SoapClient isn't recognized. I have a working example to connect to that ws but uses SoapClient. This is:
$params = array('location'=>"www.wssite.com/test.php",
'trace'=>1,
'exceptions'=>1);
$client = new SoapClient("url_of_wsdl",$params);
var_dump($client->__getFunctions());
var_dump($client->__getTypes());
$pars = array('ipcInvocationName' => 'wsinvokeservice',
'ipcMethodNamespace' => 'svcmsgxml.bldximsgin',
'ttIn' => array(
'ttInRow' => array( array('ParPos' => '0','ParNam' => 'MethodName',
'ParVal' => POST),
array('ParPos' => '1','ParNam' => 'XMLDocumentIn',
'ParVal' => 'LoginXmlValue'))),
'ttOut' => array('ttOutRow' => array(array('ParPos' => '0',
'ParNam' => 'ContentType','ParVal' => ''),array('ParPos' => '1',
'ParNam' => 'Result','ParVal' => ''),
array('ParPos' => '2','ParNam' => 'XMLDocumentOut','ParVal' => '')));
$return = $client->wssigateway($pars);
It works good!
I used NuSoap in this way:
require_once 'soap/nusoap.php';
$wsdl = 'url_of_wsdl';
$client = new soapclient($wsdl,true);
$err = $client -> getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
exit();
}
$pars = array()//the same as above
$result = $client -> call('wssigateway',$pars);
The script works for too much time and does get me nothing.. why? can someone help me?
Try $client = new nusoap_client($wsdl,true);
instead of $client = new soapclient($wsdl,true);

SOAP to XML conversion in PHP

I need to generate the following XML with SOAP:
...
<InternationalShippingServiceOption>
<ShippingService>StandardInternational</ShippingService>
<ShippingServiceCost currencyID="USD">39.99</ShippingServiceCost>
<ShippingServicePriority>1</ShippingServicePriority>
<ShipToLocation>CA</ShipToLocation>
</InternationalShippingServiceOption>
...
So I have the following SOAP array in PHP to do this:
$params = array(
'InternationalShippingServiceOption' => array(
'ShippingService'=>'StandardInternational',
'ShippingServiceCost'=>39.99,
'ShippingServicePriority'=>1,
'ShipToLocation'=>'CA',
)
)
$client = new eBaySOAP($session); //eBaySOAP extends SoapClient
$results = $client->AddItem($params);
Everything works great, except I am not generating the currencyID="USD" attribute in the ShippingServiceCost tag in the XML. How do I do this?
You don't need to use SoapVar. This works (for me at least):
$params = array(
'InternationalShippingServiceOption' => array(
'ShippingService'=>'StandardInternational',
'ShippingServiceCost' => array('_' => 39.99, 'currencyID' => 'USD')
'ShippingServicePriority'=>1,
'ShipToLocation'=>'CA',
)
)
I'm using this technique with the PayPal SOAP API.
Why, I am glad you asked. I just solved this today.
$shippingsvccostwithid = new SoapVar(array('currencyID' => $whatever),SOAP_ENC_OBJECT, 'ShippingServiceCost', 'https://your.namespace.here.com/');
$params = array("InternationalShippingServiceOption" => array(
"ShippingService" => "StandardInternational",
"ShippingServiceCost" => $shippingsvccostwithid,
"ShippingServicePriority" => 1,
"ShipToLocation" => "CA"
);
And then continue as normal.
Please let me know if you need any more help.

PHP Soap non-WSDL call: how do you pass parameters?

I'm trying to make a non-WSDL call in PHP (5.2.5) like this. I'm sure I'm missing something simple. This call has one parameter, a string, called "timezone":
$URL = 'http://www.nanonull.com/TimeService/TimeService.asmx';
$client = new SoapClient(null, array(
'location' => $URL,
'uri' => "http://www.Nanonull.com/TimeService/",
'trace' => 1,
));
// First attempt:
// FAILS: SoapFault: Object reference not set to an instance of an object
$return = $client->__soapCall("getTimeZoneTime",
array(new SoapParam('ZULU', 'timezone')),
array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
);
// Second attempt:
// FAILS: Generated soap Request uses "param0" instead of "timezone"
$return = $client->__soapCall("getTimeZoneTime",
array('timezone'=>'ZULU' ),
array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
);
Thanks for any suggestions
-Dave
Thanks. Here's the complete example which now works:
$URL = 'http://www.nanonull.com/TimeService/TimeService.asmx';
$client = new SoapClient(null, array(
'location' => $URL,
'uri' => "http://www.Nanonull.com/TimeService/",
'trace' => 1,
));
$return = $client->__soapCall("getTimeZoneTime",
array(new SoapParam('ZULU', 'ns1:timezone')),
array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
);
#Dave C's solution didn't work for me. Looking around I came up with another solution:
$URL = 'http://www.nanonull.com/TimeService/TimeService.asmx';
$client = new SoapClient(null, array(
'location' => $URL,
'uri' => "http://www.Nanonull.com/TimeService/",
'trace' => 1,
));
$return = $client->__soapCall("getTimeZoneTime",
array(new SoapParam(new SoapVar('ZULU', XSD_DATETIME), 'timezone')),
array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
);
Hope this can help somebody.
The problem lies somewhere in the lack of namespace information in the parameter. I used the first case of your example since it was closest to what I came up with.
If you change the line:
array(new SoapParam('ZULU', 'timezone')),
to:
array(new SoapParam('ZULU', 'ns1:timezone')),
it should give you the result you expected.
You could try to add another array() call around your params like this:
$params = array('timezone'=>'ZULU' );
$return = $client->__soapCall("getTimeZoneTime",
array($params),
array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
);
I can't test this, but you could.

Categories