2013-04-22 45 views
1

我一直在工作几个小时,我认为:-)。 我有一个提供的Web服务SOAP xml文件。 我想我理解这个理论;-),但不是那样,因为它总是出错。如何用SOAP和PHP发送这个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>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); 

谁能帮助我?非常感谢你。

阿德

+0

欢迎StackOverflow上。你必须编辑你的问题来更好地解释“出错”是什么意思?和Delphi有什么关系? – jachguate 2013-04-22 07:47:18

+0

exec已经输入exec0Request(带参数),你用name exec和arguments发送一些东西 – 2013-04-22 07:58:47

+0

只是一个空白的屏幕。没有错误,屏幕上出现简单的回显。 – Aadv 2013-04-22 10:26:28

回答

2

当我打电话new SoapClient("https://tst.eboekhuis.nl/cbwebs/CBWSCallEngine?WSDL");我得到:致命错误:未捕获的SOAPFault异常:[WSDL] SOAP的错误:解析WSDL:无法从 'https://tst.eboekhuis.nl/cbwebs/CBWSCallEngine?WSDL' 中加载:未能加载外部实体 “https://tst.eboekhuis.nl/cbwebs/CBWSCallEngine?WSDL”我没有找到这个解决方案:SOAP-ERROR: Parsing WSDL: Couldn't load from <URL>

也许你应该试试: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")); 
0
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);