如何将自定义类型传递给NuSoap服务

时间:2013-09-20 15:21:54

标签: php soap nusoap

我有一个php nusoap服务定义如下:

$server->wsdl->addComplexType( 
    'OrderType', 
    'complexType', 
    'struct', 
    'all', 
    '', 
    array( 
        'OrderId' => array('name' => 'OrderId', 'type' => 'xsd:string'), 
        'CustomerNumber' => array('name' => 'CustomerNumber', 'type' => 'xsd:string'), 
    ) 
); 



$server->register("testService",
    array("OrderData" => "tns:OrderType"),
    array("return" => "tns:OrderType"), //array("return" => "xsd:string"),
    "urn:aaa",
    "urn:aaa#testService",
    "rpc",
    "encoded",
    "");

如果我传递信封如下:

<soapenv:Body>
    <sch:Request xmlns:sch="http://aaa.com//Schema.xsd">
        <sch:OrderId>OA1236</sch:OrderId>
        <sch:CustomerNumber>PIN555</sch:CustomerNumber>            
    </sch:Request>
</soapenv:Body>

如何处理参数$ OrderData?我希望它能够如下工作,但这不起作用

function testService($OrderData) {                    
    $result['OrderId'] = $OrderData['OrderData'];
    $result['CusomterNumber'] = $OrderData['CustomerNumber'];
    return $result;        
}

1 个答案:

答案 0 :(得分:0)

试试这段代码:

function testService($OrderData) {                    
    $result['OrderId'] = $OrderData['OrderId']; // OrderId instead of OrderData
    $result['CustomerNumber'] = $OrderData['CustomerNumber'];
    return $result;        
}