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



我正在尝试用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;
?>

我得到的是空白的回复。请帮我怎么做。

我尝试了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);
}

最新更新