Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

soap - Sending Raw XML via PHP SoapClient request

I am trying to simply send RAW xml to a webservice via PHP and SoapClient. The problem is when I encode my XML it changes the order of elements in the XML that is converted to an associative array.

// Initialize the Soap Client:
$this->_transactionServicesClient = new SoapClient($soapWSDLUrl);

How or what would be the best way to send the following XML as a string to my SoapClient?

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.micros.com/pos/les/TransactionServices">
    <SOAP-ENV:Body>
        <ns1:PostTransaction>
            <ns1:REQ>
                <ns1:RequestHeader>
                    <ns1:InterfaceVersion>3.0.7</ns1:InterfaceVersion>
                    <ns1:ClientName>TRANS_SERVICES</ns1:ClientName>
                </ns1:RequestHeader>    
                <ns1:CheckDetailEntries>
                    <ns1:MenuItem>
                        <ns1:ReferenceEntry>Pizza4</ns1:ReferenceEntry>
                        <ns1:Count>1</ns1:Count>
                        <ns1:Price>10.00</ns1:Price>
                        <ns1:ItemNumber>112001</ns1:ItemNumber>
                        <ns1:PriceLevel>1</ns1:PriceLevel>
                        <ns1:Seat xsi:nil="true"/>
                    </ns1:MenuItem>
                </ns1:CheckDetailEntries>
                <ns1:CheckHeaderRequest>
                    <ns1:CheckId>03:21:05.050505</ns1:CheckId>
                    <ns1:GuestCount>1</ns1:GuestCount>
                    <ns1:GuestInformation>
                    <ns1:ID>001</ns1:ID>
                    <ns1:FirstName>xxx</ns1:FirstName>
                    <ns1:LastName>xxx</ns1:LastName>
                    <ns1:Address1>xxx Rd</ns1:Address1>
                    <ns1:Address2>xx</ns1:Address2>
                    <ns1:Address3>xx</ns1:Address3>
                    <ns1:PhoneNum>xx</ns1:PhoneNum>
                    <ns1:UserText1>None</ns1:UserText1>
                    <ns1:UserText2>None</ns1:UserText2>
                    <ns1:UserText3>None</ns1:UserText3>
                    <ns1:GUID></ns1:GUID></ns1:GuestInformation>
                </ns1:CheckHeaderRequest>
                <ns1:OrderTypeNumber>1</ns1:OrderTypeNumber>
            </ns1:REQ>
        </ns1:PostTransaction>
    </SOAP-ENV:Body>        
</SOAP-ENV:Envelope>

Update/Resolution: Here is the code I used to extend the SOAP Client and send my raw Soap Envelope: My answer below

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Update/Resolution: Here is the code I used to extend the SOAP Client and send my raw Soap Envelope

Here is how I extended SoapClient:

<?php
class MySoapClient extends SoapClient {

    function __construct($wsdl, $options) {
        parent::__construct($wsdl, $options);
        $this->server = new SoapServer($wsdl, $options);
    }
    public function __doRequest($request, $location, $action, $version) 
    { 
        $result = parent::__doRequest($request, $location, $action, $version); 
        return $result; 
    } 
    function __myDoRequest($array,$op) { 
        $request = $array;
        $location = 'http://xxxxx:xxxx/TransactionServices/TransactionServices6.asmx';
        $action = 'http://www.micros.com/pos/les/TransactionServices/'.$op;
        $version = '1';
        $result =$this->__doRequest($request, $location, $action, $version);
        return $result;
    } 
}

// To invoke my new custom method with my Soap Envelope already prepared.
$soapClient = new MySoapClient("http://xxxx:xxxx/TransactionServices/TransactionServices6.asmx?WSDL", array("trace" => 1)); 
$PostTransaction = $soapClient->__myDoRequest($orderRequest,$op); 
?>

Also posted on pastie.org: http://pastie.org/3687935 before I turned this into the answer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...