PHP SOAP Server ve Client

2 Cevap php

I am trying to develop a very simple SOAP server and Client in PHP. The goal is to receive content from a remote XML-document as the source.

This is what I have done so far, I need help how to extract data from an XML file instead, as it is now, from an ordinary array. This is the function found in inventory_functions.php that is fetching from an array, how can it be changed to fetch from the XML file instead? Am I on the right track, is this a SOAP setup?

  function getItemCount($upc) {

    // In reality, this data would be coming from a database

    $items = array('12345'=>5,'19283'=>100,'23489'=>'234');

    // Return the requested value

    return $items[$upc];

}

Bu sunucu için kodu:

  // Load the database

  require 'inventory_functions.php';

  // Turn off WSDL cache

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

  // Create a new SoapServer object with inventory.wsdl

  $server = new SoapServer("inventory.wsdl");

  // Register the getItemCount function

  $server->addFunction("getItemCount");

  // Start the handle

  $server->handle();

Bu müşteri için kodu:

// Turn off WSDL cache

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

// Create a new SOAPClient object

$client = new SoapClient("inventory.wsdl");

// Get the value for the function getItemCount with the ID of 12345

$getItemCount = $client->getItemCount('12345');

// Print the result

echo ($getItemCount);

Lütfen yardım edin!

2 Cevap

Sorun, XML erişim hakkında, bir SOAP sunucusu sorun değil

XML varsayarsak Exemple alıntı dizi olarak aynı verileri içerir ve size sunucu üzerinde simpleXML alabilirsiniz

//load your xml file into $xmlStr, with file_get_contents() or whatever.
$xmlObj = simplexml_load_string($xmlStr);
$items = objectsIntoArray($xmlObj);

Ayrıca DomDocument yerine, bir DOM API var kullanabilirsiniz, böylece HTML DOM aşina iseniz daha kolay olacaktır.

Örnekte bu büyük bir avantaja sahiptir, yerine dizi kullanarak, doğrudan XPath kullanarak XML içinde sonucu arama yapabilirsiniz.

daha iyi kullanmak için daha iyi esneklik için http://sourceforge.net/projects/nusoap/ gibi sabun müşteri deneyebilirsiniz.