Skip to content

Instantly share code, notes, and snippets.

@akalongman
Created April 1, 2015 08:44
Show Gist options
  • Star 40 You must be signed in to star a gist
  • Fork 16 You must be signed in to fork a gist
  • Save akalongman/56484900eaf19b18cfbd to your computer and use it in GitHub Desktop.
Save akalongman/56484900eaf19b18cfbd to your computer and use it in GitHub Desktop.
PHP soap client example
ini_set('soap.wsdl_cache_enabled', 0);
ini_set('soap.wsdl_cache_ttl', 900);
ini_set('default_socket_timeout', 15);
$params = array('param1'=>$param1);
$wsdl = 'http://service_url/method?WSDL';
$options = array(
'uri'=>'http://schemas.xmlsoap.org/soap/envelope/',
'style'=>SOAP_RPC,
'use'=>SOAP_ENCODED,
'soap_version'=>SOAP_1_1,
'cache_wsdl'=>WSDL_CACHE_NONE,
'connection_timeout'=>15,
'trace'=>true,
'encoding'=>'UTF-8',
'exceptions'=>true,
);
try {
$soap = new SoapClient($wsdl, $options);
$data = $soap->method($params);
}
catch(Exception $e) {
die($e->getMessage());
}
var_dump($data);
die;
@NazmusShakib
Copy link

Where you declare the param1 variable? It through an exception.

@DonSYS91
Copy link

The method($params) is just an example of a soap operation, you decalre the method name according to the soap operation on the soap server.

@burakkaraoglu
Copy link

Hi, i try and i got this error
An error occurred when verifying security for the message.
Can you help me?

My code:
$wsdl='https://asansordenetim.sanayi.gov.tr/IBstbAsansorDenetimServis.svc?wsdl';

ini_set('soap.wsdl_cache_enabled', 0);
ini_set('soap.wsdl_cache_ttl', 900);
ini_set('default_socket_timeout', 15);

$options = array(
'uri'=>'http://schemas.xmlsoap.org/wsdl/soap/',
'style'=>SOAP_RPC,
'use'=>SOAP_ENCODED,
'soap_version'=>SOAP_1_1,
'cache_wsdl'=>WSDL_CACHE_NONE,
'connection_timeout'=>15,
'trace'=>true,
'encoding'=>'UTF-8',
'exceptions'=>true,
'username'=>'**********',
'password'=>'***********',
);
try {
$soap = new SoapClient($wsdl, $options);
$data = $soap->TumIlleriSorgulama();
}
catch(Exception $e) {
die($e->getMessage());
}

var_dump($data);
die;

@Dwipraj
Copy link

Dwipraj commented Feb 10, 2018

I am facing some problems with php soap client programming. If you have some spare time can you do review my problem in the following link https://stackoverflow.com/questions/48621226/how-can-i-break-the-web-services-returned-message-into-array. Thank you.

@GastonM10
Copy link

@burakkaraoglu what is the error? explain, please

maybe, $optiosn array finish comma ','

"'password'=>'***********',
);"

Regards.

@heberfomin
Copy link

Hello,
Culd you tell how can I send back a xml to wsdl?
I used this "PHP soap client example" above to get records from a wsdl and work well, but now I have to send back to ws a xml to mark each record as processed in order to avoid a new receivings from the same record.
The documentation of wsdl says:
method: AlterarSituacaoControleFluxoAbastecimentoAuth
request parameters:
user: string
password: string
xml : xml

The xml has to be like this:
image

How can I send this? Could you post a simple example, please?
Thanks in advance.

@amitjoc
Copy link

amitjoc commented Jan 17, 2019

Server was unable to process request. ---> The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

i am having above error. any idea what is the wrong. if you want i can send you code also

@zkenstein
Copy link

Can you please share how to update a value over soap and php?

@vladmir224
Copy link

Voici un exemple avec php

try {

         $urlexemple = 'http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL';
        $arrContextOptions=array("ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false,'crypto_method' => STREAM_CRYPTO_METHOD_TLS_CLIENT));
        $options = array('soap_version'=>SOAP_1_2,'exceptions'=>true,'trace'=>1,'cache_wsdl'=>WSDL_CACHE_NONE,'stream_context' => stream_context_create($arrContextOptions));
        $soapclient = new SoapClient($urlEdg, $options);
        // parametre
      $paramexemple=array('sCountryISOCode'=>$request->devise);
      $response =$soapclient->FullCountryInfo($paramexemple);
        $array = json_decode(json_encode($response), true);

        return $array;

    } catch (Throwable $e) {
        return $e->getMessage();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment