Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /home/admin/domains/blog.sunucupark.com/public_html/libraries/src/Filesystem/Folder.php on line 259

Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /home/admin/domains/blog.sunucupark.com/public_html/libraries/src/Filesystem/Folder.php on line 259

Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /home/admin/domains/blog.sunucupark.com/public_html/libraries/src/Filesystem/Folder.php on line 259

Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /home/admin/domains/blog.sunucupark.com/public_html/libraries/src/Filesystem/Folder.php on line 259

Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /home/admin/domains/blog.sunucupark.com/public_html/libraries/src/Filesystem/Folder.php on line 259

Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /home/admin/domains/blog.sunucupark.com/public_html/libraries/src/Filesystem/Folder.php on line 259

Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /home/admin/domains/blog.sunucupark.com/public_html/libraries/src/Filesystem/Folder.php on line 259

Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /home/admin/domains/blog.sunucupark.com/public_html/libraries/src/Filesystem/Folder.php on line 259
Soap Web servis bağlantısı nasıl kurulur?
Menu

Soap Web servis bağlantısı nasıl kurulur?

Php ile bir webservis bağlantısı kurmak ve web servisten bilgi alabilmek için aşağıdaki örneği inceleyebilirsiniz.

Örnek: Altınkaynak'tan anlık kur bilgilerini SOAP webservis ile çekme:

Önce php dosyamız içerisinde bir Soap Client oluşturuyoruz.Soap Client webservis adresimizi alacaktır.

$client = new SoapClient('http://data.altinkaynak.com/DataService.asmx?WSDL');

Web servis bağlantısı yapabilmemiz için kullanıcı adı ve şifre istenmektedir.Altınkaynak kullanıcı adı ve şifresini kendi websitesinde paylaşmaktadır.Biz de bu kullanıcı adı ve şifre ile erişim isteğinde bulunuyoruz.

$auth = new stdClass();
$auth->Username = 'AltinkaynakWebServis';
$auth->Password = 'AltinkaynakWebServis';

$header = new SoapHeader('http://data.altinkaynak.com/', 'AuthHeader', $auth, false);
$client->__setSoapHeaders($header);

Altınkaynak'ın web sitesinde erişebileceğimiz fonksiyon grupları açıklanmıştır.Bunlardan birisi GetCurrency() 'dir.Bizde GetCurrency() fonksiyonundan cevap alıyoruz.

$response = $client->GetCurrency();

Gelen cevabı php dosyamızın içerisinde simlexl load string fonksiyonu ile bir değişkene aktarıyoruz.

$xml = simplexml_load_string($response->GetCurrencyResult);

Bu değişkenin içerisindeki stringlerimizi de vardump() fonksiyonu ile ekrana basabiliriz.

echo "<pre>";
var_dump($xml);
echo "</pre>";

Parça parça anlattığımız kodları birleştirip derlediğinizde altınkaynaktan anlık verileri almış olacaksınız.

Faydalı olması dileğiyle...