【问题标题】:How do I send this XML file with SOAP and PHP如何使用 SOAP 和 PHP 发送此 XML 文件
【发布时间】:2013-04-22 07:21:15
【问题描述】:

我已经花了几个小时做一些我认为我理解的事情:-)。 我有一个用于提供 Web 服务的 SOAP 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);

谁能帮帮我?已修复,非常感谢。

Aad

【问题讨论】:

  • 欢迎来到 StackOverflow。您必须编辑您的问题以更好地解释“出错”的含义?这和 Delphi 有什么关系?
  • exec 有输入 exec0Request(带参数)你发送的东西名称为 exec 和参数
  • 只是一个空白屏幕。没有错误,屏幕上出现一个简单的回声。
  • 只是一个空白屏幕。没有错误,屏幕上出现一个简单的回声。 @Bass:我尝试了 exec0Request,但我不知道如何使用这些参数。 de 标头中有 2 个参数:EndpointNm 和 Certificaat,节详细信息中有 5 个参数,位于标头下方。我试过这个 $result = $client->exec0Request(array('EndpointNm' => 'xxxxx', 'Certificaat' => 'xxxxx', 'EAN' => '9789084999912', 'OrderReference'=>'1988763767', 'ClientId' => 'K Koning', 'ReadingMethods' => 'CR', 'RetailerId' => '6202877'));回声 $result->exec0Request 。 "\n";我哪里错了

标签: php soap-client


【解决方案1】:

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

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

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

【讨论】:

  • 非常感谢您,我一直在努力解决我的问题,而您的回答解决了所有问题。非常感谢:D。
【解决方案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"));

【讨论】:

    猜你喜欢
    • 2011-03-01
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    • 2011-11-13
    • 2020-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多