SOAP - failed to load external entity - php

I have a wsdl file that is automatically generated by the nusoap. The server side code is
require_once('lib/nusoap.php'); //include required class for build nusoap web service server
require_once('conf.php');
// Create server object
$server = new soap_server();
// configure WSDL
$server->configureWSDL('Upload Files');//, $namespace);
// Register the method to expose
$server->register('upload_files', // method
array('files' => 'xsd:string'), // input parameters
array('return' => 'xsd:string'), // output parameters
'', // namespace
'', // soapaction
'', // style
'', // use
'Uploads files to the server' // documentation
);
// Define the method as a PHP function
function upload_files($files) {
//code here
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
WSDL seems to be generated properly and is located here: http://dannyphantom.zg5.ru/server.php?wsdl
The client side code fails almost immediatly, right when I try to create a SoapClient:
require_once('lib/nusoap.php');
$wsdl="http://dannyphantom.zg5.ru/server.php?wsdl"; // SOAP Server
try {
$client=new SoapClient($wsdl, array('trace'=>true, "cache_wsdl" => WSDL_CACHE_NONE)); // Connect the SOAP server
//code
} catch(SoapFault $e) {
//...
} catch (Exception $e) {
//...
}
Now, no matter what I try to do - every time I get an error:
"SOAP-ERROR: Parsing WSDL: Couldn't load from
'http://dannyphantom.zg5.ru/server.php?wsdl' : failed to load external
entity "http://dannyphantom.zg5.ru/server.php?wsdl"
I feel like I've searched to whole Google and tried numerous fixes - nothing works. The url_allow_fopen is set to 1. I can open the link as a file manually. I have tried setting
libxml_disable_entity_loader(false);
before creating the new instance. cURL and openSSL extensions are loaded (even though they are not required for HTTP connection). None of this helped. I am totally out of any ideas. Would appreciate any help.
PHP version is 5.2.
Client code is run from Drupal 5 (Don't think that makes any difference)

Related

WSDL-SOAP Webservice on PHP

I have created php file. It contains details about to access (wsdl)xml file and function. I need to call a function with paramaters but i can't able to call a function. So, I have been given a WSDL file and I need to create a SOAP service for it in PHP. Could any one tell me what the correct way of doing it is?
Here is link of the WSDL: http://178.211.55.56/se/ws/wf_ws.php?wsdl
and
Here is my php code:
require_once 'lib/nusoap.php';
ini_set("soap.wsdl_cache_enabled", "0");
$soapclient = new nusoap_client("http://178.211.55.56/se/ws/wf_ws.php?wsdl",'wsdl');
$soapclient->setHTTPProxy("soap:address_location",8080,"usr_name","pwd");
when run above the php code return this error:
wsdl error: Getting "WSDL link" - HTTP ERROR: Couldn't open socket
connection to server "WSDL link" prior to connect(). This is often a
problem looking up the host name.
Try to use http://php.net/manual/en/class.soapclient.php
All you need is:
Create SOAP client:
$client = new SoapClient("http://178.211.55.56/se/ws/wf_ws.php?wsdl");
You can pass many options to the constructor, such as proxy, cache settings, etc.
Some examples for you:
$client = new SoapClient("some.wsdl", array('soap_version' => SOAP_1_2));
$client = new SoapClient("some.wsdl", ['login' => "some_name", 'password'=> "some_password"]);
$client = new SoapClient("some.wsdl", ['proxy_host' => "localhost", 'proxy_port' => 8080]);
If ssl certificate is wrong you can ignore it. Example is here: https://gist.github.com/akalongman/56484900eaf19b18cfbd
Call one of the service defined functions:
$result = $client->getResult(['param_name' => 'param_value']);
Pay attention that your service function may have required parameters. Usually it can be found in the result message.

Zend SOAP server, non-wsdl mode: what will the location and uri be

I am trying to make a webservice controller for a Zend framework in PHP. I'm using non-WSDL mode (though I suppose if it comes down to it, I can build a WSDL file).
class WebserviceController extends Zend_Controller_Action
{
public function soapAction()
{
$this->getHelper('viewRenderer')->setNoRender(true);
$soap_options = array('uri'=>$_SERVER['DOCUMENT_ROOT'] . 'webservice/soap/');
echo $soap_options;
$server = new Zend_Soap_Server( null, $soap_options );
$server->setClass('WebserviceAPI');
$server->handle();
}
}
WebserviceAPI is a plain-old object:
class WebserviceAPI
{
public function returnblah($one, $two)
{
return $one . ", " . $two . ": blah!";
}
}
I'm attempting to test this just to see if I can make it connect:
$options = array('login' => '***',
'password' => '********',
'location' => 'https://localhost:8888/webservice/soap',
'uri' => 'https://localhost:8888/',
'trace' => 1);
$soap = new SoapClient(null, $options);
echo $soap->returnblah("a-one", "a-two");
It's not connecting. Fact is, I'm not sure what the correct location and uri for a Zend SOAP server should be, when it's built in non-WSDL mode. The documentation isn't clear on how to connect to a Zend SOAP server built this way.
ETA: I've included login and password in case authentication is the reason it's not connecting (though I suspect it's not even getting that far).
ETA2: Here's the actual error message:
Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /Users/sabrina/Documents/testws2.php:28
where line 28 is the actual call to $soap->returnblah(). (My code posted here omits a lot of crap I've commented out in trying to solve this.)
I'm beginning to suspect my actual connection problem may be that the SOAP client is trying to send an https request over http, so I'm trying to work that out, but it would still be helpful to know if I am using the right location and uri parameters.
Thanks in advance!
According to the Zend documentation for Zend_Soap_Server and the SoapClient documentation, the 'uri' option specifies the SOAP uri namespace in both cases.
Make sure that both 'uri' options are set to the same value in your server and client, which is not the case in your example.
The 'location' option in SoapClient should be set to the URL on which your php application is configured in your web server.

Nusoap, return array of data as XML in web service

I have a PHP soap server (Using nuSoap), and a Java client (using Axis2). Which works pretty good, until it doesn't.
The gist of what I'm trying to do is send a code to the service, and return a XML list of file names.
<filename>20120413.zip</filename>
Here's the SSCE
<?
require_once('nusoap/lib/nusoap.php');
$server = new soap_server();
$server->configureWSDL('Download Database Backup', 'urn:downloadDatabase');
$server->register('getBackupFileNames', // method
array('herdCode' => 'xsd:string'), // input parameters
array('fileList' => 'xsd:string'), // output parameters
'urn:uploadDatabase', // namespace
'urn:uploadDatabase#uploadDatabase', // soapaction
'rpc', // style
'encoded', // use
'uploadDatabase' // documentation
);
function getBackupFileNames($herdCode)
{
$location = "/home/rhythms/backups/" . $herdCode;
$fileList = scandir($location);
return $fileList;
}//end function
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
In a pinch, I know I could do a foreach and manually create the XML as a string. However it gets XMLEncoded then. Is there a better way? I would like to publish it by default in the WSDL. I've also tried the complexType but I had trouble handling that on the Axis2 side.
Thank you!
This isn't a direct answer. What I've come to is you can send a SOAP array using the SOAP-ARRAY complex data type. But it's not a very good method. Instead I'm going to investigate the native SOAP implementation that PHP provides.
Axis2 doesn't handle the SOAP-ARRAY complex datatype well, so I think it will be easier to adjust my implementation to PHP's native types.
This is left as a footnote so hopefully someone else won't fall down the same well I did as I was trying to find a good SOAP implementation.

WCF - "Incomplete" WSDL with reference to another WSDL

I am using SoapClient to send some data from a PHP site to a .Net WCF service.
This is my (shortened for clarity) code:
$wsdl = '/var/www/libraries/MyWsdl.xml';
$myClient = new SoapClient($wsdl);
and later, the actual call:
try {
$res = $myClient->Foo($someParameter);
}
catch(SoapFault $e){
//...
}
catch(Exception $e){
//...
}
This works great when everything is online, and the error handling works if the destination server is down on the time Foo is called.
Problem is that the SoapClient constructor fails, if the destination server is down, even though i've provided it with a static XML file with the WSDL (in oppose to a URL like "http://www.destination.com/MyService?wsdl").
I believe this is happening because the WSDL contains a reference to another WSDL:
<wsdl:import namespace="http://MyCompany.Services" location="http://www.destination.com/MyService?wsdl=wsdl0"/>
This other WSDL contains the definitions of the call parameters.
So, how can I "Inline" the second "sub-WSDL" inside the original one?
Will this allow me to create a SoapClient without initiating a connection to the destination server?
This is my service definition:
[ServiceContract(Namespace = "http://MyCompany.Services")]
public interface IMyService
{
[OperationContract]
[XmlSerializerFormat(Style = OperationFormatStyle.Rpc, Use = OperationFormatUse.Literal)]
string Foo(string myParameter);
}
You can use the single WSDL-file extension from here: http://wcfextras.codeplex.com/
Note that when using .net4.5 there should be no need for it, as the default metadata endpoint now also generates single WSDL-files in addition to the linked versions.
To do that simply add "?singleWSDL” to the URI (source: http://msdn.microsoft.com/en-us/library/dd456789(v=vs.110).aspx)

Help with NuSoap - Creation of web service

I have been helplessly trying to create a web service in PHP using NuSoap for the past 2 days. However, after endlessly sifting through various tutorials and guides, i am still stuck with 10 lines of code that refuse to work.
Server :
// Pull in the NuSOAP code
require_once('./lib/nusoap.php');
// Create the server instance
$server = new soap_server;
// Initialize WSDL support
$server->configureWSDL('hellowsdl','http://mysite.com');
// Register the method to expose
$server->register('hello',
array("params"=>"xsd:string"),
array("result"=>"xsd:string"),
'http://mysite.com'
);
// Define the method as a PHP function
function hello($name) {
return 'Hello, ' . $name;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
And the Client :
// Pull in the NuSOAP code
require_once('./lib/nusoap.php');
// Create the client instance
$client = new nusoap_client('http://localhost/nusoap/server.php?wsdl',true);
// Call the SOAP method
$result = $client->call('hello',array("name"=>"Scott"));
var_dump($result);
Gives me a bool(false)
Where am i going wrong ???
When you register the method, you are calling the parameter 'params' not 'name', the code should be:
$server->register('hello',
array("name"=>"xsd:string"),
array("result"=>"xsd:string"),
'http://mysite.com'
);
You shouldn't be getting false though, when I ran the code with the bug in it i still got
string(12) "Hello, "
(empty $name variable). Go to http://localhost/nusoap/server.php?wsdl and make sure you can see the WSDL from the same machine you are executing the client on.

Categories