开发者

How To Generating Required SOAP Request in PHP

I am running following code in 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();
?>

It is resulting this SOAP request

  <?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>

But I want this output...

<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开发者_如何学Python">
    <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>


If you return a content-type that is XML, the UI will depend on your browser. In IE9 and Firefox, I get it the way you want including the + and - to expand/collapse the tags.

If you want to display this in a webpage with your own format, you will have to parse it yourself. You can use XML readers.

There are a couple of XML readers on PHP.net, you can pick the one that is the most appropriate for you: http://us.php.net/xml

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜