so I have a WSDL I've been giving as documentation for a soap service. I need to implement this service exactly as defined and I don't want to rewrite the wsdl using nusoap. Is there a way to tell the object nusoap_server = new soap_server(); to use an existing wsdl and then implement the functions from the existing wsdl?
thanks
$WSDL = '/path/to/wsdl/file';
$nusoap_server = new soap_server($WSDL);
The only problem with this is that nusoap may not create the response correctly, but it will host the wsdl file.
I had to customize my xml responses.
Which you can tell nusoap to do but you will need to modify the library.
<?PHP
function serialize_return() {
//$this->fuze_debug(array('test',$this->fuze_print_s($this->methodreturn)),'soap_server_debug.log');
$this->debug('Entering serialize_return methodname: ' . $this->methodname . ' methodURI: ' . $this->methodURI);
// if fault
if (isset($this->methodreturn) && is_object($this->methodreturn) && ((get_class($this->methodreturn) == 'soap_fault') || (get_class($this->methodreturn) == 'nusoap_fault'))) {
$this->debug('got a fault object from method');
$this->fault = $this->methodreturn;
return;
// for some reason with code ignitor this doesnot get set correctly
} elseif ($this->methodreturnisliteralxml) {
//$this->fuze_debug(array('literal xml is : ',$this->fuze_print_s($this->methodreturnisliteralxml)),'soap_server_debug.log');
$return_val = $this->methodreturn;
// returned value(s)
} else {
This above code is in the nusoap library as you can see $this->methodreturnisliteralxml
If you set that to true then you can customize the xml you return from the function you define for nusoap to handle the soap request.
To me nusoap seams to be out of date.
I do not think I would use nusoap again for new projects.
Related
I use external libraries to communicate with external systems. Communication is via Soap.
I provide the library with a set of data in a simple way. She checks the data, sends the request, and receives the reply. Converts the response to its object and returns.
How can I access the SoapClient object without making changes to the external library?
For this object, I need the original data. Request, response, headers.
Is it possible to do?
EDIT:
A simple example of using one of the many external libraries:
class fedex {
public function trackShipment($number)
{
$trackRequest = new TrackServiceTrackRequest();
$trackRequest->WebAuthenticationDetail->UserCredential->Key = $this->getAccessNumber();
$trackRequest->WebAuthenticationDetail->UserCredential->Password = $this->getAccountPassword();
$trackRequest->ClientDetail->AccountNumber = $this->getAccountNumber();
$trackRequest->ClientDetail->MeterNumber = $this->getMeterNumber();
$trackRequest->SelectionDetails[0]->PackageIdentifier->Value = $number;
$request = new TrackServiceRequest();
return $request->getTrackReply($trackRequest);
}
}
$fedex = new fedex();
$result = $fedex->trackShipment('123456789');
How to get original xml with request and header that was sent by library without modifying it?
The TrackServiceRequest() object does not access the SoapClient() object.
I want to use nusoap library in applications using laravel 4.
I have an update on the composer with NoiselabsNuSOAP :
NuSOAP Library with composer
And I have followed the user manual
My code :
public function CallSOAP()
{
$client = new \nusoap_client('http://mywebsite/services/VcareServices.php', true);
$response = $client->call('validateLogin', array('EMAIL'=>'bertho_joris#yahoo.co.id', 'PASSWORD'=>'3b774f5aae6b97a060864f8310hg6785'));
return $response;
}
But I get an error message :
UnexpectedValueException The Response content must be a string or
object implementing __toString(), "boolean" given.
My question:
Is this library I can use for my laravel application?
How do I use to use it?
it's true maybe your SOAP response it's not the right one, but first of all try adding:
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = false;
and check what is your service returning, maybe you have to specify the element of the response object like:
return $response['MyValue'];
or
return $response['key']['value'];
It looks to me like the nusoap library is being loaded correctly, otherwise you would get an error about \nusoap_client not being a recognised function.
It is more likely that the endpoint you are working with (http://mywebsite/services/VcareServices.php) is not providing a valid SOAP response.
Check that your endpoint complies with the SOAP protocol, or test your client against an existing SOAP server that you know works. That should help you diagnose the problem.
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.
I am working for the first time on SOAP. After going through various tutorials I have been able to create a small and simple soap server which offers two functions. Although I have been able to create the SOAP service and test it with a client I am not being able to understand WSDL even after going through the tutorials e.g. at http://www.w3schools.com/wsdl/wsdl_binding.asp .
So how can I make this SOAP "wsdl soap" ?? Is there anyway way to autogenerate it in PHP? I don't mind writting it down manually provided I know what to write. Where do I put what code to make it "wsdl" ??
function geolocate(double $lat, double $lng)
{
$contents = file_get_contents('http://api.geonames.org/findNearby?lat='.$lat.'&lng='.$lng.'&username=imranomar');
return $contents;
}
function describe(long $geonameid)
{
return file_get_contents('http://ws.geonames.org/get?geonameId='.$geonameid.'&style=full');
}
$server = new SoapServer(null, array('uri' => "urn://localhost/firstmobile?wsdl"));
$server->addFunction('geolocate');
$server->addFunction('describe');
$server->handle();
Note: I cannot be using any framwork
I suggest you use Zend_Soap_Server as it simplify webservices developpement in PHP.
It is possible to auto generate SOAP WSDL using Zend AutoDiscovery
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.