Php üzerinde SoapClient yapmak nasıl

1 Cevap php

Ben SoapClient yeniyim, çevrimiçi bazı çalışma yapmaya çalıştım ve de sabun üzerine kodlama çalıştı, ama bu yine sadece burada herkes işaret ve belki de bana ben aslında nasıl kullanabileceğiniz bazı örnek verebilirim dolaşıp, bana çalışmıyor görünüyorlar aşağıdaki web sunucusundan geri bildirim almak için soapclint?

POST /webservices/tempconvert.asmx HTTP/1.1
Host: www.w3schools.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/CelsiusToFahrenheit"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <CelsiusToFahrenheit xmlns="http://tempuri.org/">
      <Celsius>string</Celsius>
    </CelsiusToFahrenheit>
  </soap:Body>
</soap:Envelope>

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <CelsiusToFahrenheitResponse xmlns="http://tempuri.org/">
      <CelsiusToFahrenheitResult>string</CelsiusToFahrenheitResult>
    </CelsiusToFahrenheitResponse>
  </soap:Body>
</soap:Envelope>



<?php
$url = "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL";
$client = new SoapClient($url);


?>

Ben cevap almak böylece ben sonraki adımlar için ne yapmalıyım?

1 Cevap

Yaptığın gibi ilk, instanciate the SoapClient class var:

$url = "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL";
$client = new SoapClient($url);


Then, you have to call the method you want to use -- the methods names can be found in the WSDL.

Örneğin, biz olabilir call a method called CelsiusToFahrenheit , bu WebService içinde:

$result = $client->CelsiusToFahrenheit( /* PARAMETERS HERE */ );


Now, the problem is to know which paramaters should be passed ; and how...

Eğer WSDL bakarsanız, bu bölümü göreceksiniz:

<s:element name="CelsiusToFahrenheit">
  <s:complexType>
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="Celsius" type="s:string" />
    </s:sequence>
  </s:complexType>
</s:element>

Bu yöntemler anahtar ve değer olarak dönüştürmek için değer olarak "Celsius" olurdu 1 öğe içeren bir dizi geçti gerektiğini gösterir.

Hangi PHP kodu bu bölümünü kullanmak zorunda anlamına gelir:

$result = $client->CelsiusToFahrenheit(array('Celsius' => '10'));


Executing this call, and dumping the result :

var_dump($result);

Çıktı bu türlü alır:

object(stdClass)#2 (1) {
  ["CelsiusToFahrenheitResult"]=>
  string(2) "50"
}


Which means you have to use this :

echo $result->CelsiusToFahrenheitResult . "\n";

Almak için resulting value:

50


Note : the structure of this result can be found in the WSDL file too, of course -- see the CelsiusToFahrenheitResponse portion.