简体   繁体   English

使用PHP将数据传递给SOAP函数

[英]Passing data to SOAP Function with PHP

SOAP Resource - Test SOAP资源-测试

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. 嘿,我试图将一些XML发送到此Soap Web服务,但是没有任何运气,我点击了Test()函数,因为我可以看到输出返回,但是应该返回传递给该函数的信息里面,请参考上面的链接。

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. 您应该明确地使用WSDL来生成PHP,这样您就不会怀疑如何发送请求,并且会仔细查看请求中是否有错误。

In my optinion you're misunderstanding what you have to send as the envlopped is auto-generated by the SoapClient class. 在我看来,您误解了您必须发送的内容,因为信封是由SoapClient类自动生成的。 The Test method is waiting for a single simplier string parameter. Test方法正在等待单个更简单的字符串参数。

Try the PackageGenerator project. 尝试PackageGenerator项目。

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. 想对@sven + @mikael表示感谢,花了我一段时间才弄清楚,但是您对soap客户生成的内容的评论帮助我找出了答案。 if you look at the $xml variable in my question and compare it to the below 如果您查看我的问题中的$ xml变量并将其与以下内容进行比较

$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. 您会注意到,一旦我确切知道必须传递的内容就很简单,就不需要传递我想的那么多的xml数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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