try set location param if not yet exist in wsdl schema:
WSDL mode:
$client = new SoapClient('HelloWorld.wsdl',
array(
'location' => 'http://xxx.xxx.x.xx/testcode.php',
));
Non WSDL mode:
$client = new SoapClient(null, array(
'location' => "http://xxx.xxx.x.xx/testcode.php",
'uri' => "urn://etc",
'trace' => 1 ));
echo $client->sayHello('foo');
server example for non WSDL mode:
class Service
{
public function sayHello($name)
{
return 'Hello ' . $name;
}
}
$server = new SoapServer(null, array('uri' => "urn://etc/"));
$server->setClass("Service");
$server->handle();
and similar for wsdl..
also you can use php-wsdl-creator for generated new wsdl data
added:
Full sample for WSDL mode - step by step:
1) Create the simple example service:
class Service
{
/**
* @param string $name
* @return string
*/
public function sayHello($name)
{
return 'Hello ' . $name;
}
}
$server = new SoapServer('http://example.com/wsdl-gen/'); //our auto-gen. schema
$server->setClass("Service");
$server->handle();
2) For new generated schema, I use php-wsdl-creator (go to the next step if you already have)
require_once 'php-wsdl/class.phpwsdl.php';
$namespace = 'http://example.com/';
$location = 'http://example.com/server.php';
$wsdl = PhpWsdl::CreateInstance($namespace, $location, './cache',
array(
'../soap-server.php' // all classes for generator
),
null,
null,
null,
false,
false);
//$wsdl->RunServer(); // bonus :) generated full client with documentation
$wsdl->Optimize = false;
$wsdl = $wsdl->CreateWsdl();
3) WSDL-Schema can be:
<wsdl:definitions xmlns:tns="http://example.com/" targetNamespace="http://example.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<wsdl:message name="sayHelloSoapIn">
<wsdl:part name="name" type="s:string" />
</wsdl:message>
<wsdl:message name="sayHelloSoapOut">
<wsdl:part name="return" type="s:string" />
</wsdl:message>
<wsdl:portType name="ServiceSoap">
<wsdl:operation name="sayHello">
<wsdl:input message="tns:sayHelloSoapIn" />
<wsdl:output message="tns:sayHelloSoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ServiceSoap" type="tns:ServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc" />
<wsdl:operation name="sayHello">
<soap:operation soapAction="http://example.com/sayHello" />
<wsdl:input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://example.com/" parts="name" />
</wsdl:input>
<wsdl:output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://example.com/" parts="return" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Service">
<wsdl:port name="ServiceSoap" binding="tns:ServiceSoap">
<soap:address location="http://example.com/soap-server.php" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
4) Create example client for current scheme:
$client = new SoapClient(
'http://example.com/wsdl-gen/', //schema
array(
'location' => 'http://test/server.php' //SOAP server addr
//we provide this option if the location param is not valid in scheme or not exist
));
5) That's all, example working with our service methods:
$client->sayHello('reg'); //string 'Hello reg' (length=9)
Documentation and instruments: