使用nusoap注册类方法

Ton*_*ony 2 php nusoap

我有一个php类,我想和Nusoap一起使用它.我可以使用register命令注册nusoap中已经存在的类方法吗?

样品:

这里我们注册一个我们在这个脚本中定义的函数.但是,如果我们可以在几个月前开发一个类,并且我们希望使用它作为使用WSDL的Web服务.有没有办法注册该类的方法,以便Nusoap创建它的结构的WSDL(内部方法)?

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!";
}
Run Code Online (Sandbox Code Playgroud)

Ton*_*ony 6

那么这就是我如何解决这个问题......也许有人可以用另一种方式尝试一种方法.

[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();
Run Code Online (Sandbox Code Playgroud)

和类代码.

[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}";

     }

}
Run Code Online (Sandbox Code Playgroud)

我还在c#中创建了一个soap客户端,它正确地使用了soap服务.

希望这有帮助!

  • nusoap代理中似乎存在一个错误,它阻止它使用类封装的函数.如果使用`$ client-> call('ImplClass.myfunc');`它运行良好.未解决的问题是,您无法通过继承实现类来迭代扩展SOAP接口. (2认同)