Reputation: 131
I'm trying to use SOAPClient in PHP to get some values from a function. I've created the code, however, I'm getting the error "UnSupported Media Type".
I've tried researching this issue and found the SOAP version or Content-type in the header could be the issue.
What I'd like to know, is how can I set the SOAP version and the Content-type in the header using the code below.
<?php
error_reporting(E_ALL);
try {
header("Content-type: application/soap+xml; charset=utf-8");
$client = new SoapClient(
"https://www1.gsis.gr/wsaade/RgWsPublic2/RgWsPublic2?WSDL",
array("trace" => true, 'exceptions' => 1));
// $client->__getTypes();
// $client->__getFunctions();
// $result = $client->functionName();
$params = new SoapVar('
<?xml version="1.0" encoding="utf-8"?><env:Envelope
xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns
:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-
secext-1.0.xsd" xmlns:ns2="http://rgwspublic2/RgWsPublic2Service"
xmlns:ns3="http://rgwspublic2/RgWsPublic2">
<env:Header>
<ns1:Security>
<ns1:UsernameToken>
<ns1:Username>******</ns1:Username>
<ns1:Password>******</ns1:Password>
</ns1:UsernameToken>
</ns1:Security>
</env:Header>
<env:Body>
<ns2:rgWsPublic2AfmMethod>
<ns2:INPUT_REC>
<ns3:afm_called_by/>
<ns3:afm_called_for>******</ns3:afm_called_for>
</ns2:INPUT_REC>
</ns2:rgWsPublic2AfmMethod>
</env:Body>
</env:Envelope>', XSD_ANYXML);
$result = $client->__soapCall('rgWsPublic2AfmMethod', array($params));
highlight_string($client->__getLastRequest());
}
catch (SoapFault $fault) {
die("SOAP Fault:<br />fault code: {$fault->faultcode}, fault string:
{$fault->faultstring}");
}
Upvotes: 1
Views: 1373
Reputation: 131
We can use the soap_version
option to ensure the request uses SOAP version 1.2:
new SoapClient(
"https://www1.gsis.gr/wsaade/RgWsPublic2/RgWsPublic2?WSDL",
[
"soap_version" => SOAP_1_2,
"trace" => true,
"exceptions" => 1,
]
)
Upvotes: 3
Reputation: 2131
I'm late to answer, but here's how to consume this service. It's a service that returns info about a business from the greek tax authority. $AFMcalledby is the vat number of the caller, $AFMcalledfor the VAT number of interest, and username/password you get by registering with the service.
function checkVATGR($username,$password,$AFMcalledby="",$AFMcalledfor)
{
$client = new SoapClient( "https://www1.gsis.gr/wsaade/RgWsPublic2/RgWsPublic2?WSDL",array('trace' => true, 'soap_version'=>SOAP_1_2) );
$authHeader = new stdClass();
$authHeader->UsernameToken=new stdClass();
$authHeader->UsernameToken->Username = "$username";
$authHeader->UsernameToken->Password = "$password";
$Headers[] = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'Security', $authHeader,TRUE);
$client->__setSoapHeaders($Headers);
$result = $client->rgWsPublic2AfmMethod(
array("INPUT_REC" => array(
'afm_called_by'=>"$AFMcalledby",
'afm_called_for'=>"$AFMcalledfor"
))
);
return $result;
}
Upvotes: 6