简体   繁体   中英

Passing data to SOAP Function with PHP

SOAP Resource - Test

Hey, I am trying to send some XML through to this Soap Web service but not having any luck, I am hitting the Test() function because I can see the output coming back, but the info I pass through to that function should be returned inside, please refer to the link above.

The code I am using is below - any guidance would be appreciated.

try {

        $soap_headers = new \SoapHeader(
            'POST /qslwebservice/QSLWebBooking.asmx HTTP/1.1',
            'Host: qslwebsrv',
            'Content-Type: text/xml; charset=utf-8',
            'SOAPAction: "http://www.resv5.com/webservices/Test"'
        );

        $xml = '<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.resv5.com/webservices"><soapenv:Header/><soapenv:Body><web:Test><web:xmldata>mike test</web:xmldata></web:Test></soapenv:Body></soapenv:Envelope>';

        $_test_xml = new \SimpleXMLElement($xml);
        $test_xml = $_test_xml->asXML();


        $url = esc_url('http://www.quadranet.co.uk/qsldemowebservice/QSLWebBooking.asmx?wsdl');

        $client = new \SoapClient($url); //create new Soap instance

        $types = $client->__getTypes(); //list types found at resource
        $functions = $client->__getFunctions(); //list functions found at resource

        $test = $client->Test($test_xml); //call Test() at resource


        echo '<br><hr>';
        var_dump($test);

    } catch(\Exception $e) {
        print_r($e);
    }

You should definitively use a WSDL to php generator so you won't wonder how to send the request and you'll wuickly see if you have any error in your request.

In my optinion you're misunderstanding what you have to send as the envlopped is auto-generated by the SoapClient class. The Test method is waiting for a single simplier string parameter.

Try the PackageGenerator project.

Wanted to say thanks to @sven + @mikael , took me a while to figure it out but your comments about what is generated by the soap client helped me to figure out the answer. if you look at the $xml variable in my question and compare it to the below

$xml = '<Test xmlns="http://www.resv5.com/webservices"><xmldata>TESTING</xmldata></Test>';

you'll notice that I didnt need to pass through as much xml data as I thought, once I knew exactly what had to be passed through it was simple.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM