I made one of SOAP web service on local machine. I call with a SOAP client via the some.wsdl file, work fine. But I try to use full host-URL http://flow.local/soap/some.wsdl
The index.php (with SOAP) client:
<?php
//Here change the client to 'some wsdl' / 'http://flow.local/soap/some.wsdl'
$client = new SoapClient("http://flow.local/soap/some.wsdl",
array('soap_version' => SOAP_1_2,'trace' => 1 ));
var_dump($client->__getFunctions());
$return = $client->__soapCall("hello",array("World"));
echo("\nReturning value: ".$return);
Here is the soap.php
<?php
function hello($someone)
{
return "Hello " . $someone . "! - With WSDL";
}
ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer("http://flow.local/soap/some.wsdl",
array('soap_version' => SOAP_1_2));
$server->addFunction("hello");
$server->handle();
And of course I have a wsdl schema file.
When I use full URL http://flow.local/soap/some.wsdl returns with:
"Fatal error: Uncaught SoapFault exception: [VersionMismatch] Wrong Version!"
Else work fine.
Win10Pro, WAMP server, PHP version 7.2.18.
Related
i have a problem with soap class in php. i have write a code to send sms via a sms panel. these codes run correctly on localhost (when run codes by xampp on my pc) but this code don't work when i run them on server. the php versions are same on both of them (localhost and xampp)
<?php
$FORM="30005966371";
$USERNAME="xxxx";
$PASSWORD="12345";
$DOMAIN="0098";
//---- variables ----
$TO="0935xxxxxxx";
$TEXT="test msg";
//-------------------
ini_set("soap.wsdl_cache_enabled", "0");
$sms_client = new SoapClient('http://webservice.0098sms.com/service.asmx?wsdl',array('encoding'=>'UTF-8'));
$parameters['username'] = $USERNAME;
$parameters['password'] = $PASSWORD;
$parameters['mobileno'] = $TO;
$parameters['pnlno'] = $FORM;
$parameters['text']=$TEXT;
$parameters['isflash'] =false;
echo $sms_client->SendSMS($parameters)->SendSMSResult;
?>
when i run above codes on localhost the message sends correctly but when run this code on server the following error returns:
bimehco.ir is currently unable to handle this request.
HTTP ERROR 500
i enabled soap extension in php.ini file on server but it still dont work correctly.
The initialization of the SoapClient class should look as follows when searching for errors.
$wsdl = 'http://webservice.0098sms.com/service.asmx?wsdl';
$options = [
'cache_wsdl' => WSDL_CACHE_NONE,
'exceptions' => true,
'trace' => true,
];
try {
$client = new SoapClient($wsdl, $options);
// do your request stuff here
} catch (SoapFault $fault) {
echo $fault->getMessage();
if ($client instanceof SoapClient) {
echo $client->__getLastRequest();
echo $client->__getLastResponse();
}
}
my soap codes were true and don't have any problem. it was a problem on host.
you can use above codes for soap.
or you can use curve function instead.
I am trying to access the methods of a class that are present on a different server on my current server , so that i can share their methods , so that dont have to write the same methods again
So i configured and installed the PHP SOAP extension on my system..
After that i created a SOAPService.php file on my server side which has the following code.
<?php
// *** The SOAP class wrapper: myClassSoapServer.php ***
require_once('bc_seller_classes/Vendor/Vendor.php');
$options = array('uri' => 'http://merchants.bookchor.local/bc_seller_classes/Vendor/');
$SOAPServer = new SoapServer(null, $options);
$SOAPServer->setClass('Vendor');
$SOAPServer->handle();
?>
Here as you can see i wanted to access the Vendor class .
And on the client side i made soap.php with the following code , so that i could access the get_module() method of the Vendor class.
<html>
<head></head>
<body>
<?php
// *** The SOAP way: using a class remotely ***
$options = array(
'location' => 'http://merchants.bookchor.local/VendorSoapService.php',
'uri' => 'http://merchants.bookchor.local/'
);
$hdl = new SoapClient(null, $options);
var_dump($hdl);
$data = $hdl->get_module();
echo "hi";
var_dump($data);
?>
</body>
</html>
But when i execute soap.php on the client side it gives the following error
Uncaught SoapFault exception: [Client] looks like we got no XML document
So where am i going wrong .
PS: the get_module() function returns an array which i would like to use here.
and Both the SOAPService.php and soap.php are placed in the root folder of the project .
its works by hit url but in cronjob script not workes.Cannot instantiate non-existent class: soapclient in command prompt.
$wsdl ='********/InvoicingService?wsdl';
$client = new SoapClient($wsdl, array("trace"=> 1,"exceptions" => 0));
$invoicecheck = array("username" => "*****","password" => "*****","invoiceNo" =>"****");
$proxy = $client->getProxy();
$value2 = $client ->checkInvStatus($invoicecheck);
$statusInvoice=$value2->return->responseMessage;
if($statusInvoice=='Paid'){
mail('mahtab46#gmail.com','wsdl check cron mail','paid');
echo 'working';
} else {
echo 'not worked';
}
The cronjob executes the PHP CLI handler. This probably uses a different php.ini that doesn't load the soap extension. Try to have php run a php -i > /tmp/test.txt or something and see if the Soap functionality is in there?
I'm having some problems connecting to MS web service hosted at appharbor.com
Here's the php code:
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
$options = array(
'soap_version'=>SOAP_1_2,
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE
);
try {
$client = new SoapClient("http://ppjparsanje.apphb.com/Prazniki.asmx?wsdl", $options);
print_r($client->__call("get_praznike", array("json")));
print_r($client->get_praznike("json"));
print_r($client->__soapCall("get_praznike", array("json"), array('soapaction' => 'http://ppjparsanje.apphb.com/get_praznike')));
} catch(Excteption $e) {
echo $e->getMessage()."<br />";
}
The error is:
Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host
Which is strange because service seems to work fine. I have also tried to add port 14275, but no luck. Any suggestions?
Thanks in advance!
you have made a mistake the soap has version 1 na your are passing 1.2 in options then how will it connect
$soapClient = new SoapClient('http://ppjparsanje.apphb.com/Prazniki.asmx?wsdl', array('cache_wsdl' => WSDL_CACHE_NONE) );
print_r($soapClient);
i get output:- hence due to bad code you are getting error
SoapClient Object ( [_soap_version] => 1 [sdl] => Resource id #3 )
well here i have acceses uk mail api
take a look at how i have called a method its bit diffrent
but u will get an idea
php soap client for uk mail webservice api?
I've been at this for the better part of 12 hours now. I keep getting connection issues. This is a non https request, though I have tried enabling the open_ssl.dll and other suggestions.
I can view the WSDL just fine in a browser
http://www.soapclient.com/interop/interopTest.html also returns values for me.
my code:
<?php
function doWebService()
{
########################################################################
# Do some SOAP / Call a Web Service
$soap_url = 'http://WEBSITE/WebServices/PublicAPI.asmx?WSDL';
//$soap_url = 'x.x.x.x/WebServices/PublicAPI.asmx?WSDL';
$sh_param = array(
'username' => 'admin_username',
'password' => 'admin_password');
$soap_client = new SoapClient($soap_url);
$test = $soap_client->Authenticate($sh_param);
echo $test . "\nDone";
/*
try
{
$soap_url = 'http://WEBSITE/WebServices/PublicAPI.asmx?WSDL';
//$soap_url = 'x.x.x.x/WebServices/PublicAPI.asmx?WSDL';
$sh_param = array(
'username' => 'admin_username',
'password' => 'admin_password');
$soap_client = new SoapClient($soap_url);
$test = $soap_client->Authenticate($sh_param);
echo $test . "\nDone";
}
catch (Exception $e)
{
echo "<pre>";
print_r($e);
echo "</pre>";
exit;
}
*/
}
doWebService();
?>
It fails on the $soap_client = new SoapClient($soap_url) line.
I've tried changing between PHP 4.0, 5.2, 5.3. 5.4 and 6.0. None help.
I've tried enabling
extension=php_curl.dll
extension=php_openssl.dll
extension=php_soap.dll
This is on my website using the host:
ntchosting.com
trying to access the API on another.
Actual error code
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://WEBSITE.com/WebServices/PublicAPI.asmx?WSDL' : failed to load external entity "http://WEBSITE.com/WebServices/PublicAPI.asmx?WSDL" in /home/www/MY_WEBSITE.com/main_php/_test_public_api.php:13 Stack trace: #0 /home/www/MY_WEBSITE.com/main_php/_test_public_api.php(13): SoapClient->SoapClient('http://WEBSITE...') #1 /home/www/MY_WEBSITE.com/main_php/_test_public_api.php(50): doWebService() #2 {main} thrown in /home/www/MY_WEBSITE.com/main_php/_test_public_api.php on line 13
All I want to do is be able to use the API to retrieve data and provide a sync between what I've got and another established software. Just does not seem to be remotely easy whenever I try and get my hands wet.
thanks,
jc
I managed to find out that the outbound connections were being blocked. Forced the IP to an allow list and things are working a bit better.