Can't connect to MS web service via PHP's SoapClient - php

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?

Related

Error SOAP (SoapClient) in PHP 8.1 failed to load external entity

I have a script in php that connect to a SOAP webservice. The problem is that in PHP 7.4 it works great (Tested in 3 different PC's with php 7.4), but when I try in a system with php 8.1 get this error:
SOAP-ERROR: Parsing WSDL: Couldn't load from
'https://myurl.wsdl' : failed to
load external entity
"https://myurl.wsdl"
My script:
<?php
$wsdl = "https://myurl.wsdl";
$context = stream_context_create(array('ssl' => array('verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
)
)
);
$header = array('local_cert' => 'file.pem',
'exceptions' => 1,
'trace' => true,
'stream_context' => $context
);
ini_set("soap.wsdl_cache_enabled", "0");
try {
$client = new SoapClient($wsdl, $header);
$result = $client->function();
}
catch(Exception $e)
{
$message = $e->getMessage();
echo $message;
die();
}
var_dump($result);
?>
Any suggestion?
Thanks!
UPDATE 1:
I did more text and maybe the problem is in Openssl 3 in Ubuntu 22.04 but not sure, because I have other enviroment with Openssl 1.1.1f and not working on php 8.1 but yes on 7.4
Waiting for some help.
I had the same problem after updating to Ubuntu 22.04 LTS.
I tried to access the site / document via Curl and it gave me a clue as the server is in DMZ it does not have access to internal DNS so after entring target site in /etc/hosts everything works as intended.
I solved downgrading the security level on OpenSSL.conf

SoapFault exception: [VersionMismatch] Wrong Version

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.

Using soap-client over HTTPS in PHP

i have problem with using soapclient in php. I have this code
$url = 'https://example.com?wsdl';
$soap = new SoapClient($url, array('trace' => true));
print_r($soap->__getFunctions());
$requestHeader = array(..);
$requestObject = array(..);
$request = array(
"Header" => $requestHeader,
"RequestObject" => $requestObject,
);
$createResponse = $soap->ServiceList(array('Request' => $request));
Which returns this error
Uncaught SoapFault exception: [HTTP] HTTP to HTTPS communication - Please reconfigure Your client to use HTTPS secured communication on port 443
Calling __getFuncitons is ok, it prints aviable functions, but when i call some of that functions, i get that error. I was searching for some tutorial or advice, but unsuccessfully. Do you have any advice for me ?

API resulting in Parsing WSDL: Couldn't load from

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.

SOAP request with header data

I'm trying to connect to a WCF service from PHP using the SoapClient class. I can successfully connect and traverse the API using WCFStorm however cannot seem to construct the header data correctly in order to authenticate from SoapClient. A working WCF request would be as follows:
<MyMethod>
<OutgoingHeaders attr0="MsgHeaderArray" isNull="false">
<MsgHeaderArray0>
<Name>ApiKey</Name>
<Namespace>http://www.service.com/namespace</Namespace>
<ItemType>System.String</ItemType>
<Value>ABC123</Value>
<Direction>Outgoing</Direction>
</MsgHeaderArray0>
</OutgoingHeaders>
<MethodParameters>
<colour>Red</colour>
<size>Large</size>
</MethodParameters>
</MyMethod>
The code I'm using to connect to the api and call the method is:
$params = array(
'colour' => 'Red',
'size' => 'Large'
);
$service = new SoapClient('http://www.service.com/service.svc?wsdl');
$header = new SoapHeader('http://www.service.com/namespace', 'ApiKey', 'ABC123', FALSE);
$service->__setSoapHeaders(array($header));
$service->MyMethod($params);
However I'm getting an access denied error, I'm guessing because SoapHeader isn't corrently formatted?
SoapFault: Access is denied. in SoapClient->__call()
Thank you for any help you can provide.

Categories