我如何用SOAP和PHP发送这个XML文件


How do I send this XML file with SOAP and PHP

我已经用了几个小时的东西,我以为我明白了:-)。我有一个SOAP xml文件提供给Web服务。我想我理解这个理论;-),但不理解,因为它总是出错。

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

我把这个带有已知函数的文件放到一个数组中。然后我启动服务,但是你没有听到任何响应。

$url = "https://tst.eboekhuis.nl/cbwebs/CBWSCallEngine?WSDL";
$client = new SoapClient($url);
$message = xml2array(file_get_contents('vraag.xml'));
echo $result = $client->exec($message);
谁能帮我一下?修复了,非常感谢。

Aad

我终于解决了这个问题。:)

下面的代码肯定可以工作。

$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);

当我调用new SoapClient("https://tst.eboekhuis.nl/cbwebs/CBWSCallEngine?WSDL");时,我得到:致命错误:未捕获的SoapFault异常:[WSDL] SOAP-ERROR:解析WSDL:无法从'https://tst.eboekhuis.nl/cbwebs/CBWSCallEngine加载?WSDL":加载外部实体失败"https://tst.eboekhuis.nl/cbwebs/CBWSCallEngine?WSDL"我没有找到此问题的解决方案:SOAP-ERROR:正在解析WSDL:无法't从加载

也许你应该试试:https://github.com/mikaelcom/WsdlToPhp。我认为你的代码应该像:

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"));