如何在PHP中生成所需的SOAP请求

时间:2011-04-28 09:23:30

标签: php web-services soap wsdl

我在php中运行以下代码:

<?php
$client  = new SoapClient('http://devapi.stellatravelgateway.stellatravelservices.co.uk/DirectoryService.svc?wsdl', array('trace' => 1));
$result = $client -> Authenticate(  array( 
                        'authenticateRequest' => array('BranchCode' => '6937', 
                        'UserName' => 'xxxx', 
                        'Password' => 'xxxx', 
                        'Application' => 'ExternalAPI',
                        'BranchID' => '1')));
echo $client->__getLastRequest();
?>

这导致了这个SOAP请求

  <?xml version="1.0" encoding="UTF-8" ?> 
- <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://stellatravelgateway.stellatravelservices.co.uk/DirectoryService">
- <SOAP-ENV:Body>
- <ns1:Authenticate>
- <ns1:authenticateRequest BranchCode="6937" UserName="xxxx" Password="xxxx" Application="ExternalAPI">
  <ns1:BranchID>1</ns1:BranchID> 
  </ns1:authenticateRequest>
  </ns1:Authenticate>
  </SOAP-ENV:Body>
  </SOAP-ENV:Envelope>

但我想要这个输出......

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://stellatravelgateway.stellatravelservices.co.uk/DirectoryService/IDirectoryService/Authenticate</Action>
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Authenticate xmlns="http://stellatravelgateway.stellatravelservices.co.uk/DirectoryService">
      <authenticateRequest Password="BREEZE2" Application="ExternalAPI" BranchCode="xxxx" UserName="xxxx">
        <BranchID>1</BranchID>
      </authenticateRequest>
    </Authenticate>
  </s:Body>
</s:Envelope>

1 个答案:

答案 0 :(得分:1)

如果您返回的内容类型是XML,则UI将取决于您的浏览器。 在IE9和Firefox中,我按照你想要的方式得到它,包括+和 - 来扩展/折叠标签。

如果要在具有自己格式的网页中显示此内容,则必须自行解析。 您可以使用XML阅读器。

PHP.net上有几个XML阅读器,您可以选择最适合您的XML阅读器:http://us.php.net/xml