Error using SoapClient in PHP and AMPPS on OS X - php

I have installed AMPPS on OS X Mavericks and I am getting the error below when I try to access a WSDL over HTTPS in PHP by using the SoapClient class.
SOAP-ERROR: Parsing WSDL: Couldn't load from
'https://www.some-domain.com/Webservice.asmx?WSDL' : failed to load
external entity
"https://www.some-domain.com/secure/api/Webservice.asmx?WSDL"
OpenSSL, SOAP and cURL is enabled in when I run phpinfo(). I can retrieve the WSDL contents just fine by using file_get_contents(). There is no firewall blocking the connection. Other computers on the same network can connect just fine. Below is my code. It works on the production server as well as several other computers that I have used it on.
$this->wsdlUrl = 'https://www.some-domain.com/Webservice.asmx?WSDL';
$this->client = new SoapClient($this->wsdlUrl);
$this->client->Connect(array(
/* Login credentials */
));
I have also tried to use a stream context with verify_peer set to false, but with the same result. Increasing the default_socket_timeout option also does not work as some people have suggested.
I understand that there are several other questions concerning this error, but none of the proposed solutions that I could find work for me.
Any ideas? Thanks in advance!

I'm sure this will point you to the right direction:
try {
$sc= new SoapClient('https://www.some-domain.com/Webservice.asmx?WSDL');
$sc->Connect(/* Login credentials */);
} catch (SoapFault $fault) {
print_r($fault->faultstring);
}

Related

SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://10.31.1.106:8080/gss-0.1/FileUtilities?wsdl'

I hope someone can help me because I am looking for the solution since 2 working days...
I have a php website which need to request a distant webservice.
When I try it on my computer (Win7 + WAMP), it works well.
When I try it on the webserver (CentOs6), it return me the following error :
SOAP-ERROR: Parsing WSDL: Couldn't load from
'http://ip_address:8080/gss-0.1/FileUtilities?wsdl' : failed to load
external entity "http://ip_address:8080/gss-0.1/FileUtilities?wsdl"
NB: the webservice is on the same network of my webserver (I do not use the same IP/port).
I know that the WSDL is accessible from the webserver because it is accessible using curl linux function.
curl http://ip_address:8080
My php code is:
<?php
$wsdl = "http://ip_address:8080/gss-0.1/FileUtilities?wsdl";
try{
$client = new SoapClient($wsdl ,array('trace' => 1,
'exceptions'=> 1,
'cache_wsdl' => WSDL_CACHE_NONE
));
}
catch(Exception $e) {
echo $e->getMessage();
}?>
OK I found a solution but I don't understand the problem...
So I execute this Linux command
setsebool -P httpd_can_network_connect on
And now all is running !
Response here: Thanks to user2533111
If its not firewalled there at your web server and its working in your local but not at your webserver(CentOS). its might be a case of different PHP version and php.ini settings.
Can you compare your PHP version and those below extensions in your CentOs server with your WAMP at local.
S0AP,
php_openssI,
openssI,
curI;

SoapClient: faultcode WSDL

When I try to use SoapClient:
try {
$client = new SoapClient('http://someurl/somefile.wsdl');
} catch (SoapFault $e) {
var_dump($e);
}
I have catch error with:
["faultstring"] => "SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://someurl/somefile.wsdl' : failed to load external entity "http://someurl/somefile.wsdl"
["faultcode"] => "WSDL"
I can manually download http://someurl/somefile.wsdl and can file_get_contents for this file. I try to use it before on different computer and it worked. Possible problem with php or apache settings..
ArchLinux with last updates for php and apache. I tried to enable all php extensions.
Were you able to get wsdl using file_get_contents() in browser?
I had similar issue recently in Archlinux with same faultstring, no matter what wsdl file was used. The same code was working without any problem on other Archlinux machine and Windows XP box.
After some research, it came out that problem arose only when I tried to access the page in browser - script accessed from command line worked as expected. Then I changed the script to download the wsdl file directly, using aforementioned file_get_contents() - it gave me a warning "php_network_getaddresses: getaddrinfo failed: Name or service not known".
Few tutorials (on SO, or this one: http://albertech.net/2011/05/fix-php_network_getaddresses-getaddrinfo-failed-name-or-service-not-known/ ) later I haven't fought off the problem yet. But then I discovered what introduced the issues: I had been running NetworkManager since the installation of Arch (to better handle wireless), and few weeks later I've added mysqld and httpd as last to DAEMONS section in rc.conf - it seems this broke DNS resolution for apache.
Having two solutions (go back to starting servers manually or try other network manager) I've switched to wicd and haven't run into the issue again.

PHP SoapClient using WCF service hosted in Windows application on Windows 2008 Server

This question relates to the requirement to utilize a WCF service hosted in a Windows application on Windows 2008 Server, from PHP scripts which are hosted in IIS 7 on the same server, and from other applications hosted elsewhere.
The application has been developed and tested thoroughly on a Windows 7 machine using Visual Studio 2010, .NET Framework 4, IIS 7, and various versions of PHP.
On the Windows 7 machine, netsh was used as follows.
netsh http add urlacl url=http://localhost:8000/WCFService/ user=machinename\user
Various other ports were also successfully added and used during testing.
When the application was copied to the Windows 2008 Server, the essential parts of the application were successfully tested.
The same netsh command was used on Windows 2008 Server, yet localhost was replaced with the server IP and machinename with domain as follows:
netsh http add urlacl url=http://serveripaddress:8000/WCFService/ user=domain\user
During attempts to get the PHP SoapClient working, various user="..." options were attempted, including "everyone".
The initial PHP SoapClient script is as follows:
try {
$client = new SoapClient("http://serveripaddress:8000/WCFService/?wsdl");
} catch (Exception $e) {
echo $e->getMessage(), "\n";
exit();
}
During initial testing, the following errors were encountered:
Warning:
SoapClient::SoapClient(http://serveripaddress:8000/WCFService/?wsdl)
[soapclient.soapclient]: failed to open stream: HTTP request failed!
in C:\inetpub\wwwroot\Sites\www.myurl.com\WCF-Test.php on line 7
Warning: SoapClient::SoapClient() [soapclient.soapclient]: I/O
warning : failed to load external entity
"http://serveripaddress:8000/WCFService/?wsdl" in
C:\inetpub\wwwroot\Sites\www.myurl.com\WCF-Test.php on line 7
SOAP-ERROR: Parsing WSDL: Couldn't load from
'http://serveripaddress:8000/WCFService/?wsdl' : failed to load
external entity "http://serveripaddress:8000/WCFService/?wsdl"
After some fiddling around the error reduced to the following:
SOAP-ERROR: Parsing WSDL: Couldn't load from
'http://serveripaddress:8000/WCFService/?wsdl' : failed to load
external entity "http://serveripaddress:8000/WCFService/?wsdl"
I then extracted the wsdl into a file and used the following PHP script:
try {
$client = new SoapClient("wsdl\wcf-wsdl.wsdl");
} catch (Exception $e) {
echo $e->getMessage(), "\n";
exit();
}
The error then changed slightly to the following:
SOAP-ERROR: Parsing Schema: can't import schema from
'http://serveripaddress:8000/WCFService/?xsd=xsd0'
I am of the opinion that the issue at hand relates to the "visibility" of the service, to the client, and possibly permissions.
After reading dozens of posts, I still have not been able to find a solution to this issue.
Any assistance will be greatly appreciated.
Many thanks in advance.
If the WCF Service is something you are hosting for it to be accessed by php clients you need to have a flat wsdl. On how to generate Flat Wsdl follow the below link:
How to flatten your wsdl
The same feature would be avaiable in the framework as part of .NET 4.5. Hope that helps you out.
If you know you are working with a .NET WCF service you can just change the location you download the wsdl from .svc?wsdl to .svc?singleWsdl and the WCF server will take care of the recursion / linking work for you.
This may the answer,.net has the default config make this error.
https://bugs.php.net/bug.php?id=47761

PHP SoapClient not working - no error

I have some code that connects to a newsletter service via SOAP. It works with no problem on our dev server, but on our live server it doesn't work at all. It's not returning any errors; just a blank white page. I've put some error_logs into the code and found exactly where it stops working - on the line creating the new SoapClient. Is there some kind of server config that needs to be set? Our code is identical between dev and prod, so the only thing I can figure is a server issue. (Note that the first chunk of code below was provided by the newsletter service, not written by me.)
# bronto API session/connection setup
ini_set("soap.wsdl_cache_enabled", "0");
date_default_timezone_set('America/Chicago');
$wsdl = "https://api.bronto.com/v4?wsdl";
$url = "https://api.bronto.com/v4";
/*error log statements up to this point return what is expected;
an error log after the following line (starting with $client = new SoapClient)
does not get triggered at all. */
$client = new SoapClient($wsdl, array('trace' => 1, 'encoding' => 'UTF-8'));
$client->__setLocation($url);
$token = "XXX";
$sessionId = $client->login(array("apiToken" => $token))->return;
$client->__setSoapHeaders(array(new SoapHeader("http://api.bronto.com/v4",
'sessionHeader',
array('sessionId' => $sessionId))));
I've also tried something like this to explicitly see any errors, but no luck - still nothing in the error log.
try {
$client = #new SoapClient($wsdl, array('trace' => 1, 'encoding' => 'UTF-8'));
}
catch (SoapFault $E) {
error_log($E->faultstring) ;
}
error_log("ok");
I would check the installed PHP packages on the dev server and compare to the Prod server. fr2.php.net/manual/en/soap.setup.php
This will more than likly be a config setup for php on the live server, but here are the common problems i have had with SOAP on php,
First thing is check the allowed memory for php on live comparable with dev (SOAP is big and bad for memory)
Is the php on the live server the same version as the dev server,
Is the live server authorized to access the SOAP server (if auth is used on an IP Level)
as one of the SOAP packages i have used did this to me i found out there was a version mismatch, last but not least could you tell us what SOAP Library if any other then php default your using so we can help as your code looks good :)
thinking about it have you install soap i don't think php natively supports it i think its a pear or pecl package and if your using XAMPP or easyPHP on dev these have all of both all ready included in php.

Zend_Soap - Error parsing WSDL: Start tag expected, '<' not found

For the same WSDL, which is totally valid, I am able to access it properly using PEAR SOAP like this:
$WSDL = new SOAP_WSDL($this->wsdlUrl);
$proxy = $WSDL->getProxy();
But not able to make it work through Zend_Soap, when used like this:
$soapclient = new Zend_Soap_Client($this->wsdlUrl);
I get the following error when accessed through Zend_Soap_Client:
Error: SOAP-ERROR: Parsing WSDL: Couldn't load
from 'https://abc.xyz.com/agent/TestService.php?wsdl' : Start tag expected, '<' not found
Openssl is also enabled in my php.ini
Does anybody know why it doesn't work? and how I can fix it to use Zend_Soap properly?
You should check if the ssl-Certificate is valid. This Error Message is also thrown if ssl-certificate verification fails.
Check to make sure that no Ports are blocked in your hosting situation.
I've had the same error, though with different code just plain php, and was struggling with it for several days.
It turned out that my webhotel had blocked the port I needed to access the web service.
Or it could some proxy-related issue giving the same blocked result.
Are you using HTTP Authentication? Auth works with SOAP Client, however you cannot access password protected WSDL files
See https://bugs.php.net/bug.php?id=27777

Categories