From one host, cannot hit an HTTP url with SoapClient - php

I have one problem in ONE host: I cannot access an HTTP url (say, http://foo-bar.com:9999/Path/To/My/Soap.svc?wsdl).
Hitting such URL from my localhost (running PHP 5.4) works fine. However, hitting such url from my target server (running PHP 5.5) brings me this SoapFault:
Parsing WSDL: Couldn't load from 'http://foo-bar.com:9999/Path/To/My/Soap.svc?wsdl' : failed to load external entity "http://foo-bar.com:9999/Path/To/My/Soap.svc?wsdl"
(I did not disclose the URL due to contract policies)
What can I check? (Since the url is not in HTTPS but just HTTP, openssl should be discarded)
Code:
new SoapClient(
'http://foo-bar.com:9999/Path/To/My/Soap.svc?wsdl',
array('uri' => 'http://foo-bar.com/wsdl/schema/')
);

Found it: There's nothing wrong in the SOAP client between PHP versions. They remain compatible between -at least- 5.2 and 5.5. So there's nothing weird to test here, but just simple connection tests.
Issues like this should be tested with: file_get_contents('http://foo-bar.com:9999/Path/To/My/Soap.svc?wsdl') (modern PHP versions have fopen_wrappers active by default).
The answer? Connections are refused. That's why I get such error.

Related

Any way to force PHP SOAP to call HTTPS instead of HTTP?

I have a VERY simple PHP code:
<?php
$soap = new SoapClient('https://rev-int.api.us.fleetmatics.com/Vehicle/SageQuest/VehicleService.svc?wsdl', array());
var_dump($soap);
When I copy that URL into my browser it loads just fine, with no redirects or anything:
$soap = new SoapClient('https://rev-int.api.us.fleetmatics.com/Vehicle/SageQuest/VehicleService.svc?wsdl
But when I execute that PHP script I get the following error after a PHP timeout:
Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://rev-int.api.us.fleetmatics.com/Vehicle/SageQuest/VehicleService.svc?wsdl=wsdl0' : failed to load external entity "http://rev-int.api.us.fleetmatics.com/Vehicle/SageQuest/VehicleService.svc?wsdl=wsdl0"
Notice the response URL is http://rev-int.api.us.fleetmatics.com/Vehicle/SageQuest/VehicleService.svc?wsdl=wsdl0 which is very similar but not quite accurate. If I search the working WSDL for that given URL I find it at the top:
That said, every URI points to HTTP instead of HTTPS, but if we simply change this in our browser the page loads just fine.
So the question becomes: when we create a PHP SoapClient, can we force all URIs to follow HTTPS regardless of the protocol specified in the WSDL?
The WSDL can stand by itself and contain everything inside, or it can use imports to bring in content from other locations (it usually happens with XSD schemas).
If it imports things, those imports need to be resolved by the client. If they can't be resolved, either because the location is wrong, or the protocol is wrong, or whatever, then the client bails out, because it needs a complete WSDL to understand the service's contract and how to call it, not just the parts it could load.
So you have two options:
Contact the provider of the service and ask them to fix it so all imports can be resolved.
If you can download the WSDL and all the resources it tries to import, by opening in browser and changing the protocol to https, you can save them all locally on disk in the same folder. Assuming you end up with a file named VehicleService.wsdl for the WSDL itself, and VehicleService.xml for the file you got from http://rev-int.api.us.fleetmatics.com/Vehicle/SageQuest/VehicleService.svc?wsdl=wsdl0 somehow, you can then change the WSDL to import this local file with <wsdl:import .... location="VehicleService.xml" /> instead of what it does right now. Then you can feed this local WSDL to your client, and because now everything is in the same folder, it should work.

Magento 1.9.1.0 : Unable to load WSDL using soap cleint

I have tried all the answers given in the following threads.
[1] Magento SOAP API - PHP Exception thrown for login method call: "looks like we got no XML document"
[2] Magento SOAP API - PHP Exception error “looks like we got no XML document”
I am able to load the WSDL in the browser and the WSDL URL is in this format
http://www.foo.com/api/v2_soap/?wsdl
This is the error am getting in the console:
looks like we got no XML document .
This error is usually related to Magento setting up a SoapServer, and not to your SoapClient call, which in turn means that it's usually a problem of your server not being able to fetch the WSDL. Connect toyour server via ssh and issue the following command (with your URL)
$ curl -i 'http://www.foo.com/api/v2_soap/?wsdl'
This will output the HTTP headers, and the response. My guess is the response isn't valid XML (includes debugging, or whitespace), curl couldn't connect to the server (because your host's networking is wrong) or your WSDL points to other WSDLs that can't be connected to.
Solve that problem, and you'll be good to go.

SoapClient fails to load WSDL where SoapUI has no issue

At my office I can connect directly to the relevant soap servers and my code works as it should.
However - because of security - it is not allowed that VPN connections (from home) access the SOAP servers. So I have to resort to using an SSH tunnel over a jump-station.
Because the WSDL files contain absolute urls I can't use the "location" to change this, it won't load the WSDL. Therefor I've resolved to adding entries to the hosts files mapping that server name to 127.0.0.1 and and SSH tunnel to our jumpstation forwarding the correct ports.
This allows me to use the original WSDL without modification. I just have to comment out the hosts entries when at the office.
Via SoapUI everything works. I can load the WSDL, it fully parses it (it has a lot of includes - big corporate soap service) and I can launch SOAP requests that get answered correctly.
However, if I do the same via the php SoapClient (running against an apache on localhost) it throws an exception:
SOAP-ERROR: Parsing Schema: can't import schema from 'http://wsdl.service.addres:port/wsdlUri?SCHEMA%2Fsoa.osb.model%2Fsrc%...'
(I've replaced the server and the rest of the request because its not relevant.)
If I take that entire URL and paste it into my browser it results in an WSDL-XML.
The PHP code to load create the SoapClient is as simple as this:
$options =
[
'trace' => 1,
'exception' => 1,
];
$wsdl = '/path/to/local/wsdlfile.xml';
$client = new \SoapClient($wsdl, $options);
Anyone have a clue where to look? I can't think of anything to try anymore.
I know for sure that my PHP is setup correctly (as the code has been working for months at the office and nothing was changed here). Is PHP doing DNS resolving differently and somehow getting another (or no) IP for that corporate server perhaps?

php soap server cannot reach localhost

I have a php Soap webservice and a perl script that needs to call it.
But it returns the error
Parsing WSDL: Couldn't load from 'http://xxxxxx:8888/index.php/backup/index' :
failed to load external entity "http://xxxxxx:888/index.php/backup/index"
xxxxx is the dynamic hostname of my server.
IF i call the webservice from localhost with
$client=new SoapClient('http://localhost:8888/index.php/backup/index',array('trace' => 1));
If works fine, but if i try
$client=new SoapClient('http://xxxx:8888/index.php/backup/index',array('trace' => 1));
It gives me that error.
So the problem is that the remote script call the webservice with his hostname, and the webservice cannot resolve that.... how can I solve this?
Found the problem. It's inside the yii class CWebService.
It seems that is unable to resolve the name of the local host...it will always fail if called from an external host.
I resolved it forcing the name to the ip of the server in /etc/host, like
127.0.0.1 www.website.com

Why can't I use SoapClient::multiCall on my server?

I am writing some php code for interfacing with a magento server and am trying to group my soap calls.
The magento wiki suggests the use of SoapClient::multiCall and I am able to get that to work fine on my home machine.
But If I try the exact same code on my server it tells me:
SoapFault exception: [Client] Function ("multiCall") is not a valid method for this service
The php manual for SoapClient doesn't even list multiCall as a method.
My home machine is running php version: PHP 5.3.3While the server is running version: PHP 5.2.14
I'm at a loss for what's happening here any help would be appreciated.
Here is the code I'm running:
$client = new SoapClient($wsdl_location);
$session = $client->login($user, $pass);
$client->multiCall($session, array(
array(catalog_category.currentStore),
array(catalog_category.currentStore)
)
);
Well I feel like a fool, it was a problem with the WSDL.
I was using different WSDLs on my home machine and server.
When I changed the URL from:
http://yourmagentohost/api/v2_soap?wsdl=1
to:
http://yourmagentohost/magento/api/?wsdl
You'll notice that I didn't have the /magento/ in my original URL.

Categories