How do I send this XML file with SOAP and PHP

安稳与你 提交于 2019-12-12 21:12:51

问题


I've been hours with something which I thougt I understood :-). I have a SOAP xml file to a Web service offered. I think I understand the theory;-), but not so as it keeps going wrong.

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soapenv:Body>
    <exec xmlns="CBWSCallEngine"
        soapenv:encodingStyle="http://xml.apache.org/xml-soap/literalxml">
        <arguments>
            <CbOrderProduct xmlns="http://www.cbonline.nl/xsd">
                <Header>
                    <EndpointNm>xxxxxxx</EndpointNm>
                    <Certificaat>xxxxxxxx</Certificaat>
                </Header>
                <Detail>
                    <EAN>9789084999912</EAN>
                    <OrderReference>1988763767</OrderReference>
                    <ClientId>K Koning</ClientId>
                    <ReadingMethods>CR</ReadingMethods>
                    <RetailerId>xxxxxx</RetailerId>
                </Detail>
            </CbOrderProduct >
        </arguments>
    </exec>
</soapenv:Body>

I put this file with a known function to an array. Then I start the service, but you hear no response.

$url = "https://tst.eboekhuis.nl/cbwebs/CBWSCallEngine?WSDL";
$client = new SoapClient($url);
$message = xml2array(file_get_contents('vraag.xml'));
echo $result = $client->exec($message);

Who can help me out? Fixed thank you very much.

Aad


回答1:


When i call new SoapClient("https://tst.eboekhuis.nl/cbwebs/CBWSCallEngine?WSDL"); i got: Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://tst.eboekhuis.nl/cbwebs/CBWSCallEngine?WSDL' : failed to load external entity "https://tst.eboekhuis.nl/cbwebs/CBWSCallEngine?WSDL" i didn't found a solution for this on: SOAP-ERROR: Parsing WSDL: Couldn't load from <URL>

Maybe you should try: https://github.com/mikaelcom/WsdlToPhp. I think your code should like:

error_reporting(E_ALL);
ini_set('display_errors', 1);
class CbOrderProduct
{
    var $header;
    var $detail;

    function __construct()
    {
                $this->header = new stdClass();
                $this->detail = new stdClass();
    }
    function setheader($endpoint,$Certificaat)
    {
        $this->header->EndpointNm = $endpoint;
        $this->header->Certificaat = $Certificaat;
    }   

    function setdetail($ean,$orderreference,$clienid,$readingmethods,$retailerid)
    {
                    $this->detail->EAN =$ean;
                    $this->detail->OrderReference = $orderreference;
                    $this->detail->ClientId = $clienid;
                    $this->detail->ReadingMethods = $readingmethods;
                    $this->detail->RetailerId = $retailerid;
    }   
}

class exec0Request {

    var $arguments;

    function __construct($arguments) 
    {
        $this->arguments = $arguments;
    }
}


$order = new CbOrderProduct();
$order->setheader('123','123abc');
$order->setdetail('9789084999912','1988763767','K Koning','CR','12345');
$request = new exec0Request($order);
$client = new SoapClient("https://tst.eboekhuis.nl/cbwebs/CBWSCallEngine?WSDL");
$result = $client->exec(new SoapParam($request, "exec0Request"));



回答2:


Finally I have solved this issue.. :)
Below code will definitely work.

$xml = '<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soapenv:Body>
<exec xmlns="CBWSCallEngine"
soapenv:encodingStyle="http://xml.apache.org/xml-soap/literalxml">
<arguments>
<CbOrderProduct xmlns="http://www.cbonline.nl/xsd">
<Header>
<EndpointNm>*********</EndpointNm>
<Certificaat>***********</Certificaat>
</Header>
<Detail>
<EAN>9789084999967</EAN>
<OrderReference>1988763767</OrderReference>
<ReadingMethods>D</ReadingMethods>
<RetailerId>12345</RetailerId>
</Detail>
</CbOrderProduct>
</arguments>
</exec>
</soapenv:Body>
</soapenv:Envelope>';

$sUrl = 'https://tst.eboekhuis.nl/cbwebs/CBWSCallEngine?WSDL';

// set parameters

 $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,$sUrl);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
    $sOutput = curl_exec($ch);
    curl_close($ch);
    echo "<pre>";
    print_r($sOutput);


来源:https://stackoverflow.com/questions/16141498/how-do-i-send-this-xml-file-with-soap-and-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!