WSDL-SOAP Webservice on PHP - 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.

Related

Execute a SoapClient __soapCall without WSDL page

I'm working with a SOAP API, and they've disabled the WSDL document that's normally located in the base .asmx URL for SOAP APIs. The page is instead a 404 page when viewed without an XML request. Right now, simply instantiating a SoapClient fails ($soap = new SoapClient($url);, the error is Premature end of data in tag html line 1). I'm assuming here that a new instance of SoapClient tries to retrieve the WSDL from the server. Is there a way of turning this off? Of saying 'I want to use SoapClient, but don't do any calls until I tell you the XML call that you'll be using (along with all required data)'?
EDIT: I've tried setting cache_wsdl to WSDL_CACHE_NONE but I still get that error.
You have to run SoapClient in non-wsdl mode therefore you must set the wsdl parameter of the SoapClient c'tor to null
public SoapClient::SoapClient ( mixed $wsdl [, array $options ] )
Initialize it the following way
$client = new SoapClient(null, array('location' => http://your_domain/your_webservice",
'uri' => "http://namespace_of_the_webservice/"));
location...The location of the webservice
uri...The namespace of the target webservice

SOAP - failed to load external entity

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)

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.

WCF callback service to php client

I have created a WCF Service with callback and using wsDualHttp Binding.
I want to connect to this service using PHP client.
In PHP , SoapClient is used to call the WCF service like below:
$wsdl = "http://pathto/file.svc?wsdl"
$client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' => $exceptions));
$response = $client->somefunction();
Please guide in getting for callback in PHP.
I am sorry, but IMO its impossible to have callback from wcf to php (for exaple, this post also say so:
http://wso2.org/forum/thread/24111).
Probably you can check for some websocket solution to receive behavior you ste looking for.
Take a look on node.js, for ecample: http://bergie.iki.fi/blog/dnode-make_php_and_node-js_talk_to_each_other/

PHP error when try execute .net webservice method

I need communicate with web-service construct in .net(i think), but when i try call a method, return this error:
The SOAP action specified on the message, '', does not match the HTTP SOAP Action, 'http://tempuri.org/TripointWebservicesVersionedGeneral/Ping'.
Code to connect to web-service and execute method:
$client = new SoapClient(
'...?wsdl',
array(
'trace' => 1,
'soap_version' => SOAP_1_2
)
);
//$test = $client->__soapCall('Ping',array(''));
$test = $client->Ping();
What is the reason of this error? or what i need to do to call a method?
I have already read this PHP Fatal error: "The SOAP action specified on the message, '', does not match the HTTP SOAP Action", and put in option of soap connection this "'action' => '.../Ping'" but don't help me.
i've found the reason why i can't call the method's, its because of this:
One of the problems:
The PHP returns "Caught exception: Cannot process the message because the content type ‘text/xml; charset=utf-8′ was not the expected type ‘application/soap+xml; charset=utf-8′."
The reason:
WCF is running a new version of web services than expected by the PHP.
The solution:
Change the binding type of the WCF service from binding="wsHttpBinding" to binding="basicHttpBinding".
This insures that your .NET web service would support clients and other services that conform to the WS-I standards.
url source:
http://spacebug.com/php-calling-wcf-part-1-html
Not a full answer, but I just wanted to highlight that you're probably facing this problem because you're using SoapClient to try and consume a web service that uses WS-Addressing. You should try to track down what others do in this situation:
http://www.cdatazone.org/index.php?/archives/15-WS-Addressing-for-extsoap.html
https://github.com/wso2/wsf

Categories