Help defining a wsdl - php

I'm trying to use NuSOAP to create a web service, this only has one method that returns true or false, I need help to define the wsdl and the SOAP, there isn't documentation to use SOAP in php and I only have 2 days to finish :S
function Transfer($account, $Transactiondate, $amount, $bankID)
{
//function code
return $isValidTransfer
}

PHP has excellent documentation and examples on using SOAP:
http://php.net/manual/en/soapclient.soapclient.php
IBM also has SOAP tutorials:
http://www.ibm.com/developerworks/webservices/tutorials/ws-soa-callsecurephp/index.html
http://www.ibm.com/developerworks/opensource/library/os-phpws/

Related

NuSOAP using laravel 4

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.

How to generate wsdl

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

PHP: SOAP webservice client to ASP.NET webservice server

I was trying to connect to asp.net webservice from PHP,
I dont want to use nuSOAP
I have created SOAP client using default SoapClient()
$options = array('style'=>SOAP_DOCUMENT,
'use'=>SOAP_LITERAL,
'soap_version'=>SOAP_1_1,
'exceptions'=>1,
'trace'=>1
);
$clnt = new SoapClient('webserviceURL?wsdl', $options);
$clnt ->__Call('method', array('param'=>'val'));
Now, Webservice server is not recogising my Parameter that I am passing to the webservice method.
Can Anyone help me ?
If the webservice expects document/literal wrapped calling convention then you should put method parameters inside additional array:
$clnt ->__Call('method', array(array('param'=>'val')));
Yes, I got the Answer
$params = array('param'=>'val');
$resp = $clnt->method(array('param'=>$params));
'method' is webservice method you want to call
Method mentioned by Furgas will also work

Generating WSDL when using PHP's native SOAP class?

I'm using the native SOAP class in PHP 5, having changed from NuSOAP as the native class is faster (and NuSOAP development seems to have ceased). However the PHP 5 SOAP lacks the ability to generate WSDL.
Has anyone experience of generating WSDL in PHP? If so, please recommend your preferred method.
Thanks.
Stuart,
If you or anyone else is looking for a solution to this problem here's what I did.
First get this script: http://www.phpclasses.org/browse/download/zip/package/3509/name/php2wsdl-2009-05-15.zip
Then look at its example files. After that I just sliced it the way I needed because I'm using codeigniter:
function wsdl(){
error_reporting(0);
require_once(APPPATH."/libraries/WSDLCreator.php"); //Path to the library
$test = new WSDLCreator("Webservice", $this->site."/wsdl");
//$test->includeMethodsDocumentation(false);
$test->addFile(APPPATH."/controllers/gds.php");
$test->addURLToClass("GDS", $this->site);
$test->ignoreMethod(array("GDS"=>"GDS"));
$test->ignoreMethod(array("GDS"=>"accessCheck"));
$test->createWSDL();
$test->printWSDL(true); // print with headers
}
That it, your all done.
Btw, I'm using SoapServer and SoapClient in php5+
You can try these options:
- https://code.google.com/p/php-wsdl-creator/ (GPLv3)
- https://github.com/piotrooo/wsdl-creator/ (GPLv3)
- http://www.phpclasses.org/package/3509-PHP-Generate-WSDL-from-PHP-classes-code.html (BSD like)
The first one might be your best option if the licence fits your project.
Generating a WSDL on the fly is not something that happens very often - it would tend to raise a few questions about the stability of your service!
Zend Studio can generate a WSDL from a PHP class, and there are a few other similar tools.
If you do need to generate the WSDL dynamically, take a look at Zend Framework library: Zend_Soap_AutoDiscover
Zend_Soap_AutoDiscover is a good alternative to NuSOAP. But, you can also create the WSDL file from scratch which can be very complicated and error prone. To ease this process, you can use an IDE to generate the WSDL file for your PHP functions and pass it as a parameter to your PHP SoapServer class. Check out the complete tutorial on How to generate wsdl for php native soap class

How to easily consume a web service from PHP

Is there available any tool for PHP which can be used to generate code for consuming a web service based on its WSDL? Something comparable to clicking "Add Web Reference" in Visual Studio or the Eclipse plugin which does the same thing for Java.
In PHP 5 you can use SoapClient on the WSDL to call the web service functions. For example:
$client = new SoapClient("some.wsdl");
and $client is now an object which has class methods as defined in some.wsdl. So if there was a method called getTime in the WSDL then you would just call:
$result = $client->getTime();
And the result of that would (obviously) be in the $result variable. You can use the __getFunctions method to return a list of all the available methods.
I've had great success with wsdl2php. It will automatically create wrapper classes for all objects and methods used in your web service.
I have used NuSOAP in the past. I liked it because it is just a set of PHP files that you can include. There is nothing to install on the web server and no config options to change. It has WSDL support as well which is a bonus.
This article explains how you can use PHP SoapClient to call a api web service.
Say you were provided the following:
<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://thesite.com/">
<x:Header/>
<x:Body>
<int:authenticateLogin>
<int:LoginId>12345</int:LoginId>
</int:authenticateLogin>
</x:Body>
</x:Envelope>
and
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<authenticateLoginResponse xmlns="http://thesite.com/">
<authenticateLoginResult>
<RequestStatus>true</RequestStatus>
<UserName>003p0000006XKX3AAO</UserName>
<BearerToken>Abcdef1234567890</BearerToken>
</authenticateLoginResult>
</authenticateLoginResponse>
</s:Body>
</s:Envelope>
Let's say that accessing http://thesite.com/ said that the WSDL address is:
http://thesite.com/PortalIntegratorService.svc?wsdl
$client = new SoapClient('http://thesite.com/PortalIntegratorService.svc?wsdl');
$result = $client->authenticateLogin(array('LoginId' => 12345));
if (!empty($result->authenticateLoginResult->RequestStatus)
&& !empty($result->authenticateLoginResult->UserName)) {
echo 'The username is: '.$result->authenticateLoginResult->UserName;
}
As you can see, the items specified in the XML are used in the PHP code though the LoginId value can be changed.
Well, those features are specific to a tool that you are using for development in those languages.
You wouldn't have those tools if (for example) you were using notepad to write code. So, maybe you should ask the question for the tool you are using.
For PHP: http://webservices.xml.com/pub/a/ws/2004/03/24/phpws.html
HI I got this from this site : http://forums.asp.net/t/887892.aspx?Consume+an+ASP+NET+Web+Service+with+PHP
The web service has method Add which takes two params:
<?php
$client = new SoapClient("http://localhost/csharp/web_service.asmx?wsdl");
print_r( $client->Add(array("a" => "5", "b" =>"2")));
?>

Categories