Rohit Raj Verma
Rohit Raj Verma

Reputation: 138

SOAP request working with SOAP UI but not with code

I am trying to execute following WSDL request in PHP. SOAP api does not have any authentication. When i am running this code using SOAP UI it is working fine. But through code it is not working.

Here is my code:

 <?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>[email protected]</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;

 ?>

I am getting blank response in return. Please help me how i can do it.

I tried SOAP Client as well as php CURL.

Upvotes: 1

Views: 553

Answers (1)

Chris
Chris

Reputation: 71

Using SoapClient I'm able to connect to the SOAPService when I'm setting the location parameter. This parameter is useful whenever the SOAPService sits behind a proxy and answers with its local IP address. When omitting this parameter I cant connect to the server.

Note that I'm sending dummy data to the Server which results in a SoapFault Server Error.

The created request from the wsdl is sent inside the parameters array. Hope this is useful as a starting point.

<?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);
}

Upvotes: 2

Related Questions