Asked  7 Months ago    Answers:  5   Viewed   55 times

This works fine on my WAMP server, but doesn't work on the linux master server!?

try{
    $client = new SoapClient('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl', ['trace' => true]);
    $result = $client->checkVat([
        'countryCode' => 'DK',
        'vatNumber' => '47458714'
    ]);
    print_r($result);
}
catch(Exception $e){
    echo $e->getMessage();
}

What am I missing here?! :(

SOAP is enabled

Error

SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl' : failed to load external entity "http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl"/taxation_customs/vies/checkVatService.wsdl"

Call the URL from PHP

Calling the URL from PHP returns error

$wsdl = file_get_contents('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl');
echo $wsdl;

Error

Warning:  file_get_contents(http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl): failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable

Call the URL from command line

Calling the URL from the linux command line HTTP 200 is returned with a XML response

curl http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl

 Answers

90

For some versions of php, the SoapClient does not send http user agent information. What php versions do you have on the server vs your local WAMP?

Try to set the user agent explicitly, using a context stream as follows:

try {
    $opts = array(
        'http' => array(
            'user_agent' => 'PHPSoapClient'
        )
    );
    $context = stream_context_create($opts);

    $wsdlUrl = 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';
    $soapClientOptions = array(
        'stream_context' => $context,
        'cache_wsdl' => WSDL_CACHE_NONE
    );

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

    $checkVatParameters = array(
        'countryCode' => 'DK',
        'vatNumber' => '47458714'
    );

    $result = $client->checkVat($checkVatParameters);
    print_r($result);
}
catch(Exception $e) {
    echo $e->getMessage();
}

Edit

It actually seems to be some issues with the web service you are using. The combination of HTTP over IPv6, and missing HTTP User Agent string, seems to give the web service problems.

To verify this, try the following on your linux host:

curl  -A ''  -6 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl

this IPv6 request fails.

curl  -A 'cURL User Agent'  -6 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl

this IPv6 request succeeds.

curl  -A ''  -4 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
curl  -A 'cURL User Agent'  -4 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl

both these IPv4 request succeeds.

Interesting case :) I guess your linux host resolves ec.europa.eu to its IPv6 address, and that your version of SoapClient did not add a user agent string by default.

Wednesday, March 31, 2021
 
freeMagee
answered 7 Months ago
86

You're probably right about the header being the cause, or at least part of it. I am not currently within easy reach of a soap server, but I hope the below can at least give some pointers.

There are two possibilities here: either the header should be included as a SoapHeader object, or you need to build your parameters array differently. I'll list both versions.

Either way, you can probably skip the __soapCall() method and use the magic method instead, since you appear to be using wsdl.

Parameters version (try this first)

If you're lucky, you just need to reformat the body in order to suit the given schema. It honestly kinda looks like that. Something like this:

$params = array(
    'request' => array(
        'Header' => array(
            'Token' => 'hello'
        ),
        'Parameters' => array(
            'DeviceID' => 12345,
            'SourceScreen' => 12345,
            'Language' => 'E',
            'LocalDateTime' => '2015-05-20T11:59:29.910Z',  
            'TicketID' => 12345,
            'PayScreenAttributeID' => 12345,
            'InputValue' => '123456789',
            'PaymentAmount' => 0,
            'POSReceiptCustomer' => '?',
            'POSReceiptMerchant' => '?'
        )
    )
);

$wsdl_path = "http://192.168.1.1/TestSite/TestService.asmx?wsdl";
$soapClient = new SoapClient($wsdl_path, array('trace' => 1));
$response = $soapClient->ProcessTransaction($params);

SoapHeader version

What you need to do if you actually do need a proper header is to create an header object and attach it to the client you've instantiated. Then, you can call the endpoint.

In order to do so you need to know the namespace, which should be called targetNameSpace in your schema. You'll also need to know the name, which you can see in e.g. SoapUI.

Finally, it should be enough to just supply the parameters straight away - no need to put them in a single-element array. So you end up with something like the below. With any luck, that may at least put you in the right direction. :)

// instantiate soap client
$wsdl_path = "http://192.168.1.1/TestSite/TestService.asmx?wsdl";
$soapClient = new SoapClient($wsdl_path, array('trace' => 1));

// create and attach a header
$header = new SoapHeader($namespace, $name, array('Token' => 'hello'));
$soapClient->__setSoapHeaders($header);

// call the endpoint
$response = $soapClient->ProcessTransaction($inputParams);
var_dump($response); // hopefully you get something back...
Wednesday, March 31, 2021
 
EnTee
answered 7 Months ago
13

The WSDL you are trying to make a client for is an abstract WSDL document. An abstract WSDL could be used for analyzing purposes but it does not contain all the necessary information to call a service.

The technical information about calling a service for example via SOAP is stored in the binding element of a WSDL. In case of your WSDL there is no binding information available.

Saturday, May 29, 2021
 
BlueNile
answered 5 Months ago
50

Couldn't find any straightforward way to create a header with params as attributes of one node. In the end this works, though not very pretty:

$client = new SoapClient(NULL, 
                         array('location' => $loc, 'uri' => $ns, 
                               'soap_version' => SOAP_1_2, 
                               'style' => SOAP_DOCUMENT));
$headerVar = new SoapVar('<ns1:RequestParams Size="Large" Color="Blue" Brand="xyz"/>',
                          XSD_ANYXML);                   
$header = new SoapHeader($ns, 'RequestParams', $headerVar);
$client->__setSoapHeaders($header);
$result = $client->__soapCall('SomeFunc', array(...));

Thanks to Feroz for suggesting an answer, whitch btw works if you are sending parameters in __soapCall, just didn't work when creating a header.

Thanks also to cb for the solution: http://www.php.net/manual/en/soapvar.soapvar.php#91961

Saturday, May 29, 2021
 
Nickool
answered 5 Months ago
33

The trouble was solved. In fact when I had so errors using WAMP(orange icon) I decided to set it up again.

So I installed the newest version of WAMP but there was no the same php.ini as I used previously and in fact the trouble was that on the php.ini I had to make active the line ;extension=php_openssl.dll

so I just removed the ;character and this line has become like extension=php_openssl.dll

Now it works fine.

Friday, August 13, 2021
 
Shurmajee
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :