SOAP 请求使用 SOAP UI 但不使用代码

SOAP request working with SOAP UI but not with code

我正在尝试在 PHP 中执行以下 WSDL 请求。 SOAP api 没有任何身份验证。 当我 运行 此代码使用 SOAP UI 时,它工作正常。但是通过代码它不起作用。

这是我的代码:

 <?php 
 $soapUrl = "https://dimasys.plasticentre.be:8443/dimasys/prices/DimasysService.wsdl"; 
 // xml post structure
 $xml_post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins="http://www.infomat.eu/dimasys/insertorderrequest"><soapenv:Header/><soapenv:Body><ins:insertOrderRequest><ins:order><ins:order_no>TEST-DODE 8</ins:order_no><ins:customer><ins:customer_no></ins:customer_no><ins:besteladresnummer>1</ins:besteladresnummer><ins:customer_user_volgnr>0</ins:customer_user_volgnr></ins:customer><ins:email>helpdima@infomat.eu</ins:email><ins:created_dt>2021-02-05</ins:created_dt><ins:firma>PLC</ins:firma><ins:billingAddress><ins:address><ins:company>Test infomat</ins:company><ins:initials></ins:initials><ins:firstname></ins:firstname><ins:prefix></ins:prefix><ins:lastname></ins:lastname><ins:addressline1>Laarstraat</ins:addressline1><ins:addressline2></ins:addressline2><ins:house_number>16</ins:house_number><ins:house_number_addition></ins:house_number_addition><ins:zipcode>2610</ins:zipcode><ins:city>Wilrijk</ins:city><ins:state></ins:state><ins:country><ins:countrycode>BE</ins:countrycode><ins:name>België</ins:name></ins:country><ins:addressnumber></ins:addressnumber></ins:address></ins:billingAddress><ins:shippingAddress><ins:address><ins:company>Test infomat</ins:company><ins:initials></ins:initials><ins:firstname></ins:firstname><ins:prefix></ins:prefix><ins:lastname></ins:lastname><ins:addressline1>Laarstraat</ins:addressline1><ins:addressline2></ins:addressline2><ins:house_number>16</ins:house_number><ins:house_number_addition></ins:house_number_addition><ins:zipcode>2610</ins:zipcode><ins:city>Wilrijk</ins:city><ins:state></ins:state><ins:country><ins:countrycode>BE</ins:countrycode><ins:name>België</ins:name></ins:country><ins:addressnumber></ins:addressnumber></ins:address></ins:shippingAddress><ins:orderLines><ins:order_line><ins:line_id>10</ins:line_id><ins:sku>929740</ins:sku><ins:eancode></ins:eancode><ins:description></ins:description><ins:qty_ordered>2</ins:qty_ordered><ins:regular_price></ins:regular_price><ins:promo_price></ins:promo_price><ins:discount_percentage></ins:discount_percentage><ins:discount_amount></ins:discount_amount><ins:sales_price></ins:sales_price><ins:total_amount></ins:total_amount><ins:vat_rate></ins:vat_rate></ins:order_line></ins:orderLines><ins:shippingCosts>0</ins:shippingCosts><ins:subTotal></ins:subTotal><ins:shippingMethod></ins:shippingMethod><ins:paymentMethod></ins:paymentMethod><ins:paymentReference></ins:paymentReference></ins:order></ins:insertOrderRequest></soapenv:Body></soapenv:Envelope>';   // data from the form, e.g. some ID number

$webService = new SoapClient($soapUrl);
    $headers = array(
                 "Content-type: text/xml;charset=\"utf-8\"",
                 "Accept: text/xml",
                 "Cache-Control: no-cache",
                 "Pragma: no-cache",
                 "SOAPAction: https://dimasys.plasticentre.be:8443/dimasys/insertorders", 
                 "Content-length: ".strlen($xml_post_string),
             ); 

     $url = $soapUrl;

     // PHP cURL  for https connection with auth
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    
     curl_setopt($ch, CURLOPT_TIMEOUT, 10);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     $response = curl_exec($ch); 
     curl_close($ch);     
     echo "<pre>";var_Dump($response);exit;

 ?>

我在 return 中收到空白回复。请帮助我如何做。

我尝试了 SOAP 客户端以及 php CURL。

使用 SoapClient,我可以在设置位置参数时连接到 SOAPService。只要 SOAPService 位于代理后面并使用其本地 IP 地址进行应答,此参数就很有用。当省略这个参数时,我无法连接到服务器。

请注意,我正在向服务器发送虚拟数据,这会导致 SoapFault 服务器错误。

从 wsdl 创建的请求在参数数组中发送。 希望这是一个有用的起点。

<?php

try {
    $wsdlUrl = 'https://dimasys.plasticentre.be:8443/dimasys/prices/DimasysService.wsdl';
    $soapOptions = [
        'soap_version' => SOAP_1_2,
        'location' => 'https://dimasys.plasticentre.be:8443/dimasys/prices/DimasysService.wsdl',
        'encoding' => 'utf-8',
        'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
        'exceptions' => true,
        'cache_wsdl' => WSDL_CACHE_NONE
    ];

    $client = new SoapClient($wsdlUrl, $soapOptions);

    $return = $client->__soapCall('getPrijzen', [ 
        'parameters' => [
            'tarieflijst' => 'test',
            'factuuradresnummer' => 10,
            'leveradresnummer' => 10,
            'taal' => 'test',
            'muntcode' => 'test',
            'artikelen' => [
                'artikel' => [
                    'artikelcode' => '123',
                    'aantal' => 10
                ]
            ]
        ]
    ]);

    var_dump($return);
} catch(Exception $e) {
    var_dump($e);
}