php使用NuSoap产生webservice结合WSDL让asp.net调用(31)
来源:未知 责任编辑:责任编辑 发表时间:2014-01-20 07:53 点击:次
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:si="http://soapinterop.org/xsd">
<SOAP-ENV:Body>
<ns1:helloResponse xmlns:ns1="urn:hellowsdl">
<return xsi:type="xsd:string">Hello, Scott</return>
</helloResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Defining New Data Structures
WSDL 一个重要的方面是它封装了一个或多个 XML 结构,允许程序员通过 service 来描述数据结构,为了说明 NuSOAP 如何支持这个,我会在 Programming with NuSOAP Part 2 文章中的 SOAP struct 实例中加入 WSDL 代码。service 代码的改变已经显示在 Hello, World 实例中,但是它也包含了定义 Person 数据结构的代码:
<?php // Pull in the NuSOAP code require_once('nusoap.php'); // Create the server instance $server = new soap_server(); // Initialize WSDL support $server->configureWSDL('hellowsdl2', 'urn:hellowsdl2'); // Register the data structures used by the service $server->wsdl->addComplexType( 'Person', 'complexType', 'struct', 'all', '', array( 'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'), 'age' => array('name' => 'age', 'type' => 'xsd:int'), 'gender' => array('name' => 'gender', 'type' => 'xsd:string') ) ); $server->wsdl->addComplexType( 'SweepstakesGreeting', 'complexType', 'struct', 'all', '', array( 'greeting' => array('name' => 'greeting', 'type' => 'xsd:string'), 'winner' => array('name' => 'winner', 'type' => 'xsd:boolean') ) ); // Register the method to expose $server->register('hello', // method name array('person' => 'tns:Person'), // input parameters array('return' => 'tns:SweepstakesGreeting'), // output parameters 'urn:hellowsdl2', // namespace 'urn:hellowsdl2#hello', // soapaction 'rpc', // style 'encoded', // use 'Greet a person entering the sweepstakes' // documentation ); // Define the method as a PHP function function hello($person) { $greeting = 'Hello, ' . $person['firstname'] . '. It is nice to meet a ' . $person['age'] . ' year old ' . $person['gender'] . '.'; $winner = $person['firstname'] == 'Scott'; return array( 'greeting' => $greeting, 'winner' => $winner ); } // 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); ?> 除了支持 WSDL 的附加代码之外,service 方法的代码本身也有一点改变,使用 WSDL ,不再需要使用 soapval 对象来为返回值指定名称和数据类型。
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>