Forum

PHP ile Webservis &...
 
Bildirimler
Hepsini Temizle

PHP ile Webservis çağırma (Çözüldü)

4 Yazılar
2 Üyeler
0 Likes
3,955 Görüntüleme
(@OnurOksuzgil)
Gönderiler: 22
Eminent Member
Konu başlatıcı
 

Hazırladığımız bir proje için web servis oluşturulmuş durumda. Basit bir web arayüzü ve php ile webservise bağlanmam gerekiyor. İlk defa webservisle uğraştığım için her ne kadar yazı döküman örnek kod baksamda işin içinden çıkamadım. Ayrıca header'da AuthHeader bulunmakta.

Konu hakkında bilgisi olan ve yardımcı olabilecek var mı acaba ?

 
Gönderildi : 21/04/2016 17:01

(@eravse)
Gönderiler: 1753
Üye
 

merhaba aşağıdaki gibi bir bağlantı ile parametre gönderip sonucu alabilirsiniz

 

$client = new SoapClient("http://testurl/Test.asmx?WSDL");
$params->Param1 = 'Hello';
$params->Param2 = 'World!';    
$result = $client->TestMethod($params)->TestMethodResult;

ProfectSoft Yazılım ve Danışmanlık Hizmetleri
LogPusher & Bifyou E-Commerce System
www.profectsoft.com

 
Gönderildi : 21/04/2016 17:05

(@OnurOksuzgil)
Gönderiler: 22
Eminent Member
Konu başlatıcı
 
XML yapısı bu şekilde, sadece bu parametre için örnek yazabilir misiniz? Header olmayan servisler için deneme yanılma ile olayı çözdüm. Ancak header olunca ne yaptıysam başarılı olamadım. Örnek kodlarla header'a Username-Password gönderdiğimde doğru yada yanlış her seferinde

"Sunucu isteği işleyemedi. ---> Nesne başvurusu bir nesnenin örneğine ayarlanmadı." hatası alıyorum. SoapUI ile kullanıcı hatasına düşebiliyorum.

http://xxx.xxx.xxx.xxx/ABCService.asmx?wsdl

<wsdl:definitions xmlns:s=" http://www.w3.org/2001/XMLSchema " xmlns:soap12=" http://schemas.xmlsoap.org/wsdl/soap12/ " xmlns:http=" http://schemas.xmlsoap.org/wsdl/http/ " xmlns:mime=" http://schemas.xmlsoap.org/wsdl/mime/ " xmlns:tns=" http://tempuri.org/ "xmlns:soap=" http://schemas.xmlsoap.org/wsdl/soap/ " xmlns:tm=" http://microsoft.com/wsdl/mime/textMatching/ " xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/ " xmlns:wsdl=" http://schemas.xmlsoap.org/wsdl/ " targetNamespace=" http://tempuri.org/ ">

<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace=" http://tempuri.org/ ">
<s:element name="ABCGetir">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Karekod" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Sorgulayan" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="KullaniciId" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="UyeGuid" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="ABCGetirResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="ABCGetirResult" type="tns:ABCSonuc"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="AuthHeader" type="tns:AuthHeader"/>
<s:complexType name="AuthHeader">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Username" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string"/>
</s:sequence>
<s:anyAttribute/>
</s:complexType>
...
...
 
 

 
Sorun Çözüldü. Örnek Kod

<?php

ini_set("soap.wsdl_cache_enabled", "0");

$wsdl = "http://xxx.xxx.xxx.xxx/ABCService.asmx?wsdl";
$ns = 'http://tempuri.org/';

$client = new SoapClient($wsdl, array(
"trace" => 1,
"exceptions" => 0
));

$username = 'Username';
$password = 'Password';

$headerBody = array(
'Username' => $username,
'Password' => $password
);
$header = new SoapHeader($ns, 'AuthHeader', $headerBody,false);

$client->__setSoapHeaders($header);
$result = $client->ABCGetir(array('Karekod'=>'ABCD1234'));

$sonuc=$result->ABCGetirResult->Sonuc;
$adi=$result->ABCGetirResult->Adi;
$ozellikler=$result->ABCGetirResult->Ozellikler;
$email=$result->ABCGetirResult->Email;
$web=$result->ABCGetirResult->Web;

...
...
...

?>

 
Gönderildi : 21/04/2016 17:43

(@eravse)
Gönderiler: 1753
Üye
 

postman uzerınden bır request atın servıse header olarakda user pass gonderın muhtemel basıc auth ıle baglanıyordur postmandan aldıgınız auth key ıle bır denermısınız eger dogrulama tamamlanırsa bunun ıcın user name pass ıcın basıc auth ıle kodunuzda request atmanız gereklı 

 

saygılar

 

ProfectSoft Yazılım ve Danışmanlık Hizmetleri
LogPusher & Bifyou E-Commerce System
www.profectsoft.com

 
Gönderildi : 02/05/2016 15:20

Paylaş: