最近工作的內容使用到了接口!
對於系統接口:
現下接觸的有兩種!
1、URL類型的接口
URL路由帶參數式的接口!這個很好做!只要有過Web開發經驗的人都能完成!
這種接口數據不夠隱蔽性,可以直接在瀏覽其中看到,
如支付寶的交易請求URL。需要加一個MD5簽名,和服務器端的再次向支付寶服務器發送驗證!
雖然soap方式傳遞的數據隱蔽性很好!但為了數據安全,難免也需要進行數據簽名。
2、SOAP類型的接口
無關編程語言、無關平台、擴展性很好
要實現一個SOAP 型的接口,有兩種方式:一種有WSDL文件方式、一中無WSDL文件方式!
對於熱愛研究型的人來說,使用第一種方式可以讓你清楚的了解PHP是怎么創建了一個Web Service!
但第一種對於新手來說,創建一個XML格式的WSDL文件,是比較難的,這你的先了解熟悉什么是XML!
學會XML語法!
但對於一個急於解決問題的人來說!沒有這么多的時間去熟悉!所以這是件煩惱的事!
不過不急,上面說了,還有一種無需WSDL文件的方式!而且,本講解還提供了一個自動生成WSDL文件的類!
講解前,先配置下PHP的soap環境支持:
找到php.ini文件
;extension=php_soap.dll
刪除掉";" ,重啟apache服務器
一、有WSDL文件方式
在這里先介紹標准的webservice。
那么如何創建wsdl呢?對於PHP來說這確實是件很不容易的事情,有人說用zend studio創建很方便,這是一種方法。但對於那些不喜歡用zend studio的人來說,會覺得創建一個web service還要安裝zend studio,太強人所難了。
在這里介紹一個簡單的方法,到網上下載SoapDiscovery.class.php類,里面有個公用方法:getWSDL,這個方法末尾是用的return,那么,你修改一下這個方法:
//return sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '</definitions>');
//生成wsdl文件,將上面的return注釋
$fso = fopen($this->class_name . ".wsdl" , "w");
fwrite($fso, sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '</definitions>'));
現在生成wsdl的類有了,SoapDiscovery.class.php(源碼在最末尾)。
再准備一個提供服務的Service.php類文件或者函數就可以創建wsdl了!
<?php class Service { public function HelloWorld() { return "Hello"; } public function Add($a, $b) { return $a + $b; } } ?>
創建wsdl文件的creat_wsdl.php
<?php include("Service.php"); include("SoapDiscovery.class.php"); $disco = new SoapDiscovery('Service', 'soap'); //第一個參數是類名(生成的wsdl文件就是以它來命名的),即Service類,第二個參數是服務的名字(這個可以隨便寫)。 $disco->getWSDL();
運行create_wsdl.php文件,此時會生成一個Service.wsdl的文件
再在Service.php文件中添加一些代碼
<?php class Service { public function HelloWorld() { return "Hello"; } public function Add($a, $b) { return $a + $b; } } $server = new SoapServer('Service.wsdl', array('soap_version' => SOAP_1_2)); $server->setClass("Service"); //注冊Service類的所有方法 $server->handle(); //處理請求 ?>
創建webservice客戶端程序,測試webservice是否有效,文件名是:client.php
將以下內容拷貝進去:
<?php ini_set('soap.wsdl_cache_enabled', "0"); //關閉wsdl緩存 $soap = new SoapClient('http://localhost/Dragon/soap/Service.php?wsdl');
echo $soap->Add(28, 2);
echo $soap->__soapCall('Add',array(28,2))//或這樣調用
OK!測試通過!
二、無WSDL文件方式
服務器端
<?php class Service { public function HelloWorld() { return "Hello"; } public function Add($a,$b) { return $a+$b; } } $server=new SoapServer(null,array('uri' => "abcd")); $server->setClass("Service"); $server->handle();
客戶端
<?php try { $soap = new SoapClient(null, array( "location" => "http://localhost/Dragon/soap/Service.php", "uri" => "abcd", //資源描述符服務器和客戶端必須對應 "style" => SOAP_RPC, "use" => SOAP_ENCODED )); echo $soap->Add(12, 2); } catch (Exction $e) { echo print_r($e->getMessage(), true); }
三.出現的問題。
1.在方法中對屬性的賦值在其他方法中不起作用。
比如在客戶端調用服務端某個方法對某個屬性賦值。
在其他方法里就不能用。但在 __construct 方法中對屬性的賦值是可以個在其他方法中使用的。
2. 提示 Client] looks like we got no XML document錯誤。
服務器端文件在<?php ?> 標簽前后都不要有任何數據包括空格,空行。
3. Warning: SoapClient::SoapClient(): I/O warning : failed to load external entity
原因如下:PHP程序作為 SOAP客戶端 采用 WSDL 模式訪問遠端服務器的時候,PHP是通過調用 libcurl 實現的。至少在 PHP5.2.X 是這樣的。如果采用 non-WSDL 模式,就不需要 libcurl。除了 了ibcurl以外,至少還關聯的庫包括:libidn,ibgcc,libiconv,libintl,openssl
現在,你已經解決你了系統接口的問題了!剩下的空余時間,就有必要去了解什么是SOAP、http協議、XML了!
SoapDiscovery.class.php 文件

<?php /** * Copyright (c) 2005, Braulio Jos?Solano Rojas * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of * conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * Neither the name of the Solsoft de Costa Rica S.A. nor the names of its contributors may * be used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * * @version $Id$ * @copyright 2005 */ /** * SoapDiscovery Class that provides Web Service Definition Language (WSDL). * * @package SoapDiscovery * @author Braulio Jos?Solano Rojas * @copyright Copyright (c) 2005 Braulio Jos?Solano Rojas * @version $Id$ * @access public * */ class SoapDiscovery { private $class_name = ''; private $service_name = ''; /** * SoapDiscovery::__construct() SoapDiscovery class Constructor. * * @param string $class_name * @param string $service_name * */ public function __construct($class_name = '', $service_name = '') { $this->class_name = $class_name; $this->service_name = $service_name; } /** * SoapDiscovery::getWSDL() Returns the WSDL of a class if the class is instantiable. * * @return string * */ public function getWSDL() { if (empty($this->service_name)) { throw new Exception('No service name.'); } $headerWSDL = "<?xml version=\"1.0\" ?>\n"; $headerWSDL.= "<definitions name=\"$this->service_name\" targetNamespace=\"urn:$this->service_name\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:tns=\"urn:$this->service_name\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns=\"http://schemas.xmlsoap.org/wsdl/\">\n"; $headerWSDL.= "<types xmlns=\"http://schemas.xmlsoap.org/wsdl/\" />\n"; if (empty($this->class_name)) { throw new Exception('No class name.'); } $class = new ReflectionClass($this->class_name); if (!$class->isInstantiable()) { throw new Exception('Class is not instantiable.'); } $methods = $class->getMethods(); $portTypeWSDL = '<portType name="' . $this->service_name . 'Port">'; $bindingWSDL = '<binding name="' . $this->service_name . 'Binding" type="tns:' . $this->service_name . "Port\">\n<soap:binding style=\"rpc\" transport=\"http://schemas.xmlsoap.org/soap/http\" />\n"; $serviceWSDL = '<service name="' . $this->service_name . "\">\n<documentation />\n<port name=\"" . $this->service_name . 'Port" binding="tns:' . $this->service_name . "Binding\"><soap:address location=\"http://" . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['PHP_SELF'] . "\" />\n</port>\n</service>\n"; $messageWSDL = ''; foreach ($methods as $method) { if ($method->isPublic() && !$method->isConstructor()) { $portTypeWSDL.= '<operation name="' . $method->getName() . "\">\n" . '<input message="tns:' . $method->getName() . "Request\" />\n<output message=\"tns:" . $method->getName() . "Response\" />\n</operation>\n"; $bindingWSDL.= '<operation name="' . $method->getName() . "\">\n" . '<soap:operation soapAction="urn:' . $this->service_name . '#' . $this->class_name . '#' . $method->getName() . "\" />\n<input><soap:body use=\"encoded\" namespace=\"urn:$this->service_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n</input>\n<output>\n<soap:body use=\"encoded\" namespace=\"urn:$this->service_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n</output>\n</operation>\n"; $messageWSDL.= '<message name="' . $method->getName() . "Request\">\n"; $parameters = $method->getParameters(); foreach ($parameters as $parameter) { $messageWSDL.= '<part name="' . $parameter->getName() . "\" type=\"xsd:string\" />\n"; } $messageWSDL.= "</message>\n"; $messageWSDL.= '<message name="' . $method->getName() . "Response\">\n"; $messageWSDL.= '<part name="' . $method->getName() . "\" type=\"xsd:string\" />\n"; $messageWSDL.= "</message>\n"; } } $portTypeWSDL.= "</portType>\n"; $bindingWSDL.= "</binding>\n"; //return sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '</definitions>'); //生成wsdl文件,將上面的return注釋 $fso = fopen($this->class_name . ".wsdl", "w"); fwrite($fso, sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '</definitions>')); } /** * SoapDiscovery::getDiscovery() Returns discovery of WSDL. * * @return string * */ public function getDiscovery() { return "<?xml version=\"1.0\" ?>\n<disco:discovery xmlns:disco=\"http://schemas.xmlsoap.org/disco/\" xmlns:scl=\"http://schemas.xmlsoap.org/disco/scl/\">\n<scl:contractRef ref=\"http://" . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['PHP_SELF'] . "?wsdl\" />\n</disco:discovery>"; } } ?>
=================================================================================
修正版:
根據YII 的CWsdlGenerator改變而來,
增加了接口參數的類型識別;
使用前需使用IDE對方法名進行注釋,方可自動生成有效的WSDL文件。(具體原因可查看代碼processMethod方法中的115行)
調用方法:
<?php
include(dirname(__FILE__) . './Service.class.php');
include(dirname(__FILE__) . './SoapDiscovery.class.php');
$disco = new SoapDiscovery();
$disco->getWSDL('service', 'http://www.xxx.com/service.php');
?>

<?php /** * CWsdlGenerator class file. * * @author Qiang Xue <qiang.xue@gmail.com> * @link http://www.yiiframework.com/ * @copyright Copyright © 2008-2011 Yii Software LLC * @license http://www.yiiframework.com/license/ */ /** * CWsdlGenerator generates the WSDL for a given service class. * * The WSDL generation is based on the doc comments found in the service class file. * In particular, it recognizes the '@soap' tag in the comment and extracts * API method and type definitions. * * In a service class, a remote invokable method must be a public method with a doc * comment block containing the '@soap' tag. In the doc comment, the type and name * of every input parameter and the type of the return value should be declared using * the standard phpdoc format. * * CWsdlGenerator recognizes the following primitive types (case-sensitive) in * the parameter and return type declarations: * <ul> * <li>str/string: maps to xsd:string;</li> * <li>int/integer: maps to xsd:int;</li> * <li>float/double: maps to xsd:float;</li> * <li>bool/boolean: maps to xsd:boolean;</li> * <li>date: maps to xsd:date;</li> * <li>time: maps to xsd:time;</li> * <li>datetime: maps to xsd:dateTime;</li> * <li>array: maps to xsd:string;</li> * <li>object: maps to xsd:struct;</li> * <li>mixed: maps to xsd:anyType.</li> * </ul> * * If a type is not a primitive type, it is considered as a class type, and * CWsdlGenerator will look for its property declarations. Only public properties * are considered, and they each must be associated with a doc comment block containg * the '@soap' tag. The doc comment block should declare the type of the property. * * CWsdlGenerator recognizes the array type with the following format: * <pre> * typeName[]: maps to tns:typeNameArray * </pre> * * The following is an example declaring a remote invokable method: * <pre> * / ** * * A foo method. * * @param string name of something * * @param string value of something * * @return string[] some array * * @soap * * / * public function foo($name,$value) {...} * </pre> * * And the following is an example declaring a class with remote accessible properties: * <pre> * class Foo { * / ** * * @var string name of foo * * @soap * * / * public $name; * / ** * * @var Member[] members of foo * * @soap * * / * public $members; * } * </pre> * In the above, the 'members' property is an array of 'Member' objects. Since 'Member' is not * a primitive type, CWsdlGenerator will look further to find the definition of 'Member'. * * @author Qiang Xue <qiang.xue@gmail.com> * @version $Id: CWsdlGenerator.php 2799 2011-01-01 19:31:13Z qiang.xue $ * @package system.web.services * @since 1.0 */ class SoapDiscovery { /** * @var string the namespace to be used in the generated WSDL. * If not set, it defaults to the name of the class that WSDL is generated upon. */ public $namespace; /** * @var string the name of the generated WSDL. * If not set, it defaults to "urn:{$className}wsdl". */ public $serviceName; private $_operations; private $_types; private $_messages; /** * Generates the WSDL for the given class. * @param string $className class name * @param string $serviceUrl Web service URL * @param string $encoding encoding of the WSDL. Defaults to 'UTF-8'. * @return string the generated WSDL */ public function getWSDL($className, $serviceUrl, $encoding = 'UTF-8') { $this->_operations = array(); $this->_types = array(); $this->_messages = array(); if ($this->serviceName === null) $this->serviceName = $className; if ($this->namespace === null) $this->namespace = "urn:{$className}wsdl"; $reflection = new ReflectionClass($className); foreach ($reflection->getMethods() as $method) { if ($method->isPublic()) $this->processMethod($method); } //return $this->buildDOM($serviceUrl, $encoding)->saveXML(); $fso = fopen($this->serviceName . ".wsdl", "w"); fwrite($fso, $this->buildDOM($serviceUrl, $encoding)->saveXML()); } /* * @param ReflectionMethod $method method */ private function processMethod($method) { $comment = $method->getDocComment(); if (strpos($comment, '@soap') === false) return; $methodName = $method->getName(); $comment = preg_replace('/^\s*\**(\s*?$|\s*)/m', '', $comment); $params = $method->getParameters(); $message = array(); $n = preg_match_all('/^@param\s+([\w\.]+(\[\s*\])?)\s*?(.*)$/im', $comment, $matches); if ($n > count($params)) $n = count($params); for ($i = 0; $i < $n; ++$i) $message[$params[$i]->getName()] = array($this->processType($matches[1][$i]), trim($matches[3][$i])); // name => type, doc $this->_messages[$methodName . 'Request'] = $message; if (preg_match('/^@return\s+([\w\.]+(\[\s*\])?)\s*?(.*)$/im', $comment, $matches)) $return = array($this->processType($matches[1]), trim($matches[2])); // type, doc else $return = null; $this->_messages[$methodName . 'Response'] = array('return' => $return); if (preg_match('/^\/\*+\s*([^@]*?)\n@/s', $comment, $matches)) $doc = trim($matches[1]); else $doc = ''; $this->_operations[$methodName] = $doc; } /* * @param string $type PHP variable type */ private function processType($type) { static $typeMap = array( 'string' => 'xsd:string', 'str' => 'xsd:string', 'int' => 'xsd:int', 'integer' => 'xsd:integer', 'float' => 'xsd:float', 'double' => 'xsd:float', 'bool' => 'xsd:boolean', 'boolean' => 'xsd:boolean', 'date' => 'xsd:date', 'time' => 'xsd:time', 'datetime' => 'xsd:dateTime', 'array' => 'soap-enc:Array', 'object' => 'xsd:struct', 'mixed' => 'xsd:anyType', ); if (isset($typeMap[$type])) return $typeMap[$type]; else if (isset($this->_types[$type])) return is_array($this->_types[$type]) ? 'tns:' . $type : $this->_types[$type]; else if (($pos = strpos($type, '[]')) !== false) { // if it is an array $type = substr($type, 0, $pos); if (isset($typeMap[$type])) $this->_types[$type . '[]'] = 'xsd:' . $type . 'Array'; else { $this->_types[$type . '[]'] = 'tns:' . $type . 'Array'; $this->processType($type); } return $this->_types[$type . '[]']; } } /* * @param string $serviceUrl Web service URL * @param string $encoding encoding of the WSDL. Defaults to 'UTF-8'. */ private function buildDOM($serviceUrl, $encoding) { $xml = "<?xml version=\"1.0\" encoding=\"$encoding\"?> <definitions name=\"{$this->serviceName}\" targetNamespace=\"{$this->namespace}\" xmlns=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:tns=\"{$this->namespace}\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:soap-enc=\"http://schemas.xmlsoap.org/soap/encoding/\"></definitions>"; $dom = new DOMDocument(); $dom->loadXml($xml); $this->addTypes($dom); $this->addMessages($dom); $this->addPortTypes($dom); $this->addBindings($dom); $this->addService($dom, $serviceUrl); return $dom; } /* * @param DOMDocument $dom Represents an entire HTML or XML document; serves as the root of the document tree */ private function addTypes($dom) { if ($this->_types === array()) return; $types = $dom->createElement('wsdl:types'); $schema = $dom->createElement('xsd:schema'); $schema->setAttribute('targetNamespace', $this->namespace); foreach ($this->_types as $phpType => $xmlType) { if (is_string($xmlType) && strrpos($xmlType, 'Array') !== strlen($xmlType) - 5) continue; // simple type $complexType = $dom->createElement('xsd:complexType'); if (is_string($xmlType)) { if (($pos = strpos($xmlType, 'tns:')) !== false) $complexType->setAttribute('name', substr($xmlType, 4)); else $complexType->setAttribute('name', $xmlType); $complexContent = $dom->createElement('xsd:complexContent'); $restriction = $dom->createElement('xsd:restriction'); $restriction->setAttribute('base', 'soap-enc:Array'); $attribute = $dom->createElement('xsd:attribute'); $attribute->setAttribute('ref', 'soap-enc:arrayType'); $attribute->setAttribute('wsdl:arrayType', substr($xmlType, 0, strlen($xmlType) - 5) . '[]'); $restriction->appendChild($attribute); $complexContent->appendChild($restriction); $complexType->appendChild($complexContent); } else if (is_array($xmlType)) { $complexType->setAttribute('name', $phpType); $all = $dom->createElement('xsd:all'); foreach ($xmlType as $name => $type) { $element = $dom->createElement('xsd:element'); $element->setAttribute('name', $name); $element->setAttribute('type', $type[0]); $all->appendChild($element); } $complexType->appendChild($all); } $schema->appendChild($complexType); $types->appendChild($schema); } $dom->documentElement->appendChild($types); } /* * @param DOMDocument $dom Represents an entire HTML or XML document; serves as the root of the document tree */ private function addMessages($dom) { foreach ($this->_messages as $name => $message) { $element = $dom->createElement('wsdl:message'); $element->setAttribute('name', $name); foreach ($this->_messages[$name] as $partName => $part) { if (is_array($part)) { $partElement = $dom->createElement('wsdl:part'); $partElement->setAttribute('name', $partName); $partElement->setAttribute('type', $part[0]); $element->appendChild($partElement); } } $dom->documentElement->appendChild($element); } } /* * @param DOMDocument $dom Represents an entire HTML or XML document; serves as the root of the document tree */ private function addPortTypes($dom) { $portType = $dom->createElement('wsdl:portType'); $portType->setAttribute('name', $this->serviceName . 'PortType'); $dom->documentElement->appendChild($portType); foreach ($this->_operations as $name => $doc) $portType->appendChild($this->createPortElement($dom, $name, $doc)); } /* * @param DOMDocument $dom Represents an entire HTML or XML document; serves as the root of the document tree * @param string $name method name * @param string $doc doc */ private function createPortElement($dom, $name, $doc) { $operation = $dom->createElement('wsdl:operation'); $operation->setAttribute('name', $name); $input = $dom->createElement('wsdl:input'); $input->setAttribute('message', 'tns:' . $name . 'Request'); $output = $dom->createElement('wsdl:output'); $output->setAttribute('message', 'tns:' . $name . 'Response'); $operation->appendChild($dom->createElement('wsdl:documentation', $doc)); $operation->appendChild($input); $operation->appendChild($output); return $operation; } /* * @param DOMDocument $dom Represents an entire HTML or XML document; serves as the root of the document tree */ private function addBindings($dom) { $binding = $dom->createElement('wsdl:binding'); $binding->setAttribute('name', $this->serviceName . 'Binding'); $binding->setAttribute('type', 'tns:' . $this->serviceName . 'PortType'); $soapBinding = $dom->createElement('soap:binding'); $soapBinding->setAttribute('style', 'rpc'); $soapBinding->setAttribute('transport', 'http://schemas.xmlsoap.org/soap/http'); $binding->appendChild($soapBinding); $dom->documentElement->appendChild($binding); foreach ($this->_operations as $name => $doc) $binding->appendChild($this->createOperationElement($dom, $name)); } /* * @param DOMDocument $dom Represents an entire HTML or XML document; serves as the root of the document tree * @param string $name method name */ private function createOperationElement($dom, $name) { $operation = $dom->createElement('wsdl:operation'); $operation->setAttribute('name', $name); $soapOperation = $dom->createElement('soap:operation'); $soapOperation->setAttribute('soapAction', $this->namespace . '#' . $name); $soapOperation->setAttribute('style', 'rpc'); $input = $dom->createElement('wsdl:input'); $output = $dom->createElement('wsdl:output'); $soapBody = $dom->createElement('soap:body'); $soapBody->setAttribute('use', 'encoded'); $soapBody->setAttribute('namespace', $this->namespace); $soapBody->setAttribute('encodingStyle', 'http://schemas.xmlsoap.org/soap/encoding/'); $input->appendChild($soapBody); $output->appendChild(clone $soapBody); $operation->appendChild($soapOperation); $operation->appendChild($input); $operation->appendChild($output); return $operation; } /* * @param DOMDocument $dom Represents an entire HTML or XML document; serves as the root of the document tree * @param string $serviceUrl Web service URL */ private function addService($dom, $serviceUrl) { $service = $dom->createElement('wsdl:service'); $service->setAttribute('name', $this->serviceName . 'Service'); $port = $dom->createElement('wsdl:port'); $port->setAttribute('name', $this->serviceName . 'Port'); $port->setAttribute('binding', 'tns:' . $this->serviceName . 'Binding'); $soapAddress = $dom->createElement('soap:address'); $soapAddress->setAttribute('location', $serviceUrl); $port->appendChild($soapAddress); $service->appendChild($port); $dom->documentElement->appendChild($service); } }