如何使用SOAP和PHP发送此XML文件

时间:2013-04-22 07:21:15

标签: php soap-client

我已经花了几个小时,我知道我理解的东西:-)。 我有一个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);

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

阿德

2 个答案:

答案 0 :(得分:2)

当我调用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: 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"));

答案 1 :(得分:1)

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);
相关问题