After build server function (web services). Now we try to read the web service from VB.NET. It will give idea how to we develop multiplatform application.
For this tutorial, I use Microsoft Visual Studio 2003. For this tool, it can accept web services standar using WSDL (Web Services Describe Language). So we must create wsdl before.
Create "server_wsdl.php" within test/nusoap. Enter following code:
<?php
// call library
require_once ( 'lib/nusoap.php' );
// create instance
$server = new soap_server();
// initialize WSDL support
$server->configureWSDL( 'hellowsdl' , 'urn:hellowsdl' );
// place schema at namespace with prefix tns
$server->wsdl->schemaTargetNamespace = 'urn:hellowsdl';
// register methode
$server->register('hello', // method name
array('name'=>'xsd:string'),
// input parameter
array('return'=>'xsd:string'),// output
'urn:hellowsdl' ,// namespace
'urn:hellowsdl#hello',// soapaction
'rpc',// style
'encoded',// use
'Say hello to the caller'// documentation
);
// define method as function
function hello($name)
{
return "Hello, ".$name;
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
Ok, now we try to open at VB.NET.
- Open your Microsoft Visual Studio 2003.
- File > New > Project. You will get dialog box. Choose visual basic projects at Project Types and Windows Application at Templates. Choose name and location where your application saved. Click OK button.
- Right click at Reference in Solution Explorer. Choose add web references.
You will get dialog box.
- Put http://localhost:8048/test/nusoap/server_wsdl.php?wsdl at URL. You should get like this:
Click Add Reference button. Your Solution explorer should like this:
- Put label, textbox, and button. Place like following screen.
- Double click botton. Add following code:
Dim name As String
name = TextBox1.Text
Dim ws As New localhost.hellowsdl
MsgBox(ws.hello(name))
- Press F5 for run.
Put a name at textbox, then click button. You will get message box like following screen:
It is simple, isn't it?