Posted September 24th, 2004 by winstanley_john
When you open VS.NET and try to create an application using ASP.NET theres a few different types of application that you can choose from.
- ASP.NET Mobile Web Application
- ASP.NET Web Service
- Empty Web Project
There are a couple in the PHP Projects section but maybe you could add
- PHP Web Service.
Say you use NuSoap or PEAR, Its quite tedious to create a web service using them at the moment I'm sure you could make it really easy to create a PHP web service if you automated some of the tasks.
juanc says:
Probably it would be PEAR. It probably fit better in the add new item menu but a custom project can be created as well.
What are the steps you would like to see in the wizard for creating the web service?
winstanley_john says:
I know you said PEAR Heres a simple Web Service taken from the NuSoap site.
[code]
<?php// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the server instance
$server = new soap_server();
// Initialize WSDL support
$server->configureWSDL('hellowsdl', 'urn:hellowsdl');
// Put the WSDL schema types in the namespace with the tns prefix
$server->wsdl->schemaTargetNamespace = 'urn:hellowsdl';
// Register the method to expose
$server->register('hello', // method name
array('name' => 'xsd:string'), // input parameters
array('return' => 'xsd:string'), // output parameters
'urn:hellowsdl', // namespace
'urn:hellowsdl#hello', // soapaction
'rpc', // style
'encoded', // use
'Says hello to the caller' // documentation
);
// 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);
?>
[/code]
Heres a simple consumption also taken from the NuSoap site
[code]
<?php// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the client instance
$client = new soapclient('http://localhost/phphack/hellowsdl2.php?wsdl', true);
// Check for an error
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
// At this point, you know the call that follows will fail
}
// Create the proxy
$proxy = $client->getProxy();
// Call the SOAP method
$person = array('firstname' => 'Willi', 'age' => 22, 'gender' => 'male');
$result = $proxy->hello($person);
// Check for a fault
if ($proxy->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $proxy->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
// Display the request and response
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($proxy->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($proxy->response, ENT_QUOTES) . '</pre>';
// Display the debug messages
echo '<h2>Debug</h2>';
echo '<pre>' . htmlspecialchars($proxy->debug_str, ENT_QUOTES) . '</pre>';
?>
[/code]
winstanley_john says:
So from this I need to have few things abstracted from me, so that I can make things really easily.
I need to be able to...
- create a web service.
- add (or edit) methods to a web service
- consume a web service.
[b]Wizard: Creating a web Service shell .[/b]Just one step to define a namespace, and any other configuration details. This would give me a page for which I just need to add methods.
[b]Wizard: Adding a function to the webservice.[/b]
You'd need to ask for
function name,
return type,
parameters,
namespace,
soapaction
etc
Then insert a section of code (You could hide it in a region) that described the web service function, and insert a shell for the function.
[b]Wizard: Consume a web service.[/b]
In Visual Studio 2003 for ASP.NET you get a proxy object by just adding a referce to the project. Maybe you could do something similar? - Setting up a PHP page configured to look at a webservice with the proxy created...
Does any one with more experience of Web Services have any thoughts?
winstanley_john says:
It would be useful if you could skip between the web service description page and the WSDL description easily when you run the web service from VS.PHP.
juanc says:
Are you refering to the code editor or the browser. I'm not sure what do you mean.
juanc says:
This is good stuff. Some ideas that come to my mind:
The web service shell could be just like the add class wizard.
Regarding adding methods to a class, once I get the class browser working you will be able to easily add methods to any class in your project including web services.
I can use the VS.Net webservice browser to browse for a wsdl. Once found, I can create a proxy class and include it in the project.
Good stuff, thanks
jjhii says:
I installed nusoap and used the sample server above in the .web site that siliverlight was to consume. I then attempted to add a service reference which was all but impossible, it would be nice if it could be found as part of the solution with the discover button.
As a work around I pointed my IIS to the .Web directory and then used that path to get the service reference. At that point siliverlight could consume the soap object. (still working on the details)
Since I normally do this on a IIS server using C# on both end is soap the best way to to this or should I be using another technology with PHP on the server?
regards,
john
juanc says:
Are you sure you want to use SOAP and not REST?
I believe Zend framework provides both.
jjhii says:
I am not sure that was why I was asking for suggestions :)
Is REST easier to use or more secure?
I will look at the ZEND framework again.
Thanks