开发者

Basic SOAP/PHP example

开发者 https://www.devze.com 2023-04-13 09:37 出处:网络
I would like to get a working example in PHP that parses a SOAP file. I am following an example from here: http://www.php.net/manual/en/soapclient.dorequest.php .

I would like to get a working example in PHP that parses a SOAP file.

I am following an example from here: http://www.php.net/manual/en/soapclient.dorequest.php . It does not need to use this script (copied below) in particular, but it should be fairly simple to understand for learning purposes. I was using this url (just a random link that I Googled):https://www.paypalobjects.com/wsdl/PayPalSvc.wsdl , I tried plugging it into both 'location' and 'uri' near the bottom, but in both cases it did not work.

Essentially, I am looking for a simple short script to learn from for the purposes of parsing SOAP files.

<?php
function Add($x,$y) {
  return $x+$y;
}

class LocalSoapClient extends SoapClient {

  function __construct($wsdl, $options开发者_如何学JAVA) {
    parent::__construct($wsdl, $options);
    $this->server = new SoapServer($wsdl, $options);
    $this->server->addFunction('Add');
  }

  function __doRequest($request, $location, $action, $version, $one_way = 0) {
    ob_start();
    $this->server->handle($request);
    $response = ob_get_contents();
    ob_end_clean();
    return $response;
  }

}

$x = new LocalSoapClient(NULL,array('location'=>'test://', 
                                   'uri'=>'http://testuri.org')); 
var_dump($x->Add(3,4));
?>


This is very advanced example, it is definitely not good as an tutorial.

First of all, make your server and client in separate scripts. You know, SOAP is about communication between two endpoints. Also, do not subclass PHP SoapClient nor SoapServer, just use them.

Update: I have just Googled some tutorials: server and client. Cannot find any English tutorial for client and server. Just take care when googling, that the found page is for PHP SOAP. There are also nusoap, PHP Zend SOAP (very similar to PHP SOAP) and maybe some more implementations. Also good source are PHP test http://svn.php.net/viewvc/php/php-src/trunk/ext/soap/tests/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号