Register class methods with nusoap

2019-07-19 03:28发布

I've a php class and i want to use it with Nusoap. Can I register the class method's that already exists inside the nusoap with the register command?

Sample :

Here we register a function that we defined inside this script. But if we've a class that we maybe develop months ago and we want to use it as a webservice using the WSDL. Is there a way to register the methods of that class so that Nusoap creates a WSDL of it's stucture (methods inside)?

require_once("nuSOAP/lib/nusoap.php");

$server = new soap_server();

$namespace = "http://localhost/nusoapSCRIPT/index.php";

$server->wsdl->schemaTargetNamespace = $namespace;

$server->configureWSDL("SAMPLE");

$server->register('HelloWorld');

function HelloWorld()
{
return "Hello, World!";
}

标签: php nusoap
2条回答
乱世女痞
2楼-- · 2019-07-19 04:00

Well here's how i solve this... maybe someone can try an approach in another way.

[File : index.php]
require_once "nuSOAP/lib/nusoap.php";    
require_once "myClass.class.inc.php";

$namespace = "http://localhost/html/nusoap/index.php";

// create a new soap server
$server = new soap_server();

// configure our WSDL
$server->configureWSDL("Class Example");

// set our namespace
$server->wsdl->schemaTargetNamespace = $namespace;

// register the class method and the params of the method
$server->register("myClass.ShowString"                       
                 ,array('name'=>'xsd:string')
                 ,array('return'=>'xsd:string')
                 ,$namespace,false
                 ,'rpc'
                 ,'encoded'
                 ,'Sample of embedded classes...' 
                                );

//
// Get our posted data if the service is being consumed
// otherwise leave this data blank.                
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) 
                ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';

// pass our posted data (or nothing) to the soap service                    
$server->service($POST_DATA);                
exit();

and the class code.

[File 'myClass.class.inc.php']

class myClass{

     public function __construct(){

     }


     public function ShowString($mens){

        return "\n##Remote Class :".__CLASS__."\n##Remote Method : ".__METHOD__."\n## mSG :{$mens}";

     }

}

I also create a soap client in c# and it consumes correctly the soap service.

Hope this help!

查看更多
姐就是有狂的资本
3楼-- · 2019-07-19 04:03

You can call the method using getProxy()

$proxy->className__methodname
查看更多
登录 后发表回答