Reputation: 154
I am creating a SOAP service and I do not give with it.
I have these files
server.php
<?php
ini_set("soap.wsdl_cache_enabled","0");
function simpleFunction() {
return 'simpleFunction';
}
// initialize SOAP Server
$server=new SoapServer("simple.wsdl");
$server->addFunction('simpleFunction');
$server->handle();
&
simple.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="Simple"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="Simple"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="Simple"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:message name="simpleFunctionRequest">
<wsdl:part name="in1" type="xsd:string"></wsdl:part>
<wsdl:part name="in2" type="xsd:string"></wsdl:part>
</wsdl:message>
<wsdl:message name="simpleFunctionResponse">
<wsdl:part name="out1" type="tns:integer"></wsdl:part>
<wsdl:part name="out2" type="xsd:string"></wsdl:part>
</wsdl:message>
<wsdl:portType name="Simple">
<wsdl:operation name="simpleFunction">
<wsdl:input message="tns:simpleFunctionRequest"/>
<wsdl:output message="tns:simpleFunctionResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Simple" type="tns:Simple">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="simpleFunction">
<soap:operation
soapAction="http://192.168.56.2/ws/verySimple/server.php"/>
<wsdl:input>
<soap:body use="literal" namespace="Simple"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal" namespace="Simple"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Simple">
<wsdl:port binding="tns:Simple" name="Simple">
<soap:address
location="http://192.168.56.2/ws/verySimple/server.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
to prove it I created this client
client.php
<?php
$in1='in1';
$in2='in2';
$client=new SoapClient('simple.wsdl',
['trace'=>1,'cache_wsdl'=>WSDL_CACHE_NONE]);
$resp =$client->simpleFunction($in1, $in2);
// dump response
var_dump($resp);
I have started a server in XAMP and if I make a call to the client.php it returns this:
array (2) {["out1"] => NULL ["out2"] => NULL}
I also try the service with SoapUI doing a project with the url
http: //localhost/verySimple/simple.wsdl
and gives me a Request for SimpleFuntion
<soapenv: Envelope xmlns: soapenv =
"http://schemas.xmlsoap.org/soap/envelope/" xmlns: sim = "Simple">
<soapenv: Header />
<soapenv: Body>
<sim: simpleFunction>
<in1>? </ in1>
<in2>? </ in2>
</ sim: simpleFunction>
</ soapenv: Body>
</ soapenv: Envelope>
and response
<SOAP-ENV: Envelope xmlns: SOAP-ENV = "http://schemas.xmlsoap.org/soap/envelope/" xmlns: ns1 = "Simple">
<SOAP-ENV: Body>
<ns1: simpleFunctionResponse />
</ SOAP-ENV: Body>
</ SOAP-ENV: Envelope>
If I copy the same service (changing the url from http: // localhost to http://192.168.56.2/ws/) to another server that I have in a virtual machine
and I call the client.php it does not show me anything
and if I use SoapUi against http://192.168.56.2/ws/verySimple/simple.wsdl
The request returns
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"xmlns:sim="Simple">
<soapenv:Header/>
<soapenv:Body>
<sim:simpleFunction>
<in1>?</in1>
<in2>?</in2>
</sim:simpleFunction>
</soapenv:Body>
</soapenv:Envelope>
but there is no response ...
I guess the problem is configuring the second server, but I do not know what I have to do it respond. Can you help me?
Bonus Question :-):
In localhost the the
var_dump($resp);
is
array (2) {["out1"] => NULL ["out2"] => NULL}
but I don't know how to fill this array because the function
return 'simpleFunction';
but I don't know where is this string :-(
Upvotes: 0
Views: 98
Reputation: 619
You've defined the response from the function as being a type like this:
class simpleFunctionResponse {
public $out1;
public $out2;
}
But the function actually returns a string.
Try something like:
// Using the class defined above
function simpleFunction() {
return new simpleFunctionResponse();
}
// or just with an array
function simpleFunction() {
return array(
'out1' => 1,
'out2' => 'my string',
);
}
Upvotes: 1