Discussion:
Returning Data Objects to the client side
aouriques
2007-12-27 14:31:12 UTC
Permalink
Hello friends,

How can I return a Data Object to the client side?
I am using the SDO_DAS_XML to create the data object but I cannot send
to the client the correct object.

I have tried this example (and a lot others):
http://www.ibm.com/developerworks/web/library/ws-soa-scasdo/index.html

My service file:
<?php
include "SCA/SCA.php";

/**
* @service
* @binding.soap
*
* @location http://mydomain.com/SOA/Weather/WeatherService.php
* @types http://Weather http://mydomain.com/SOA/Weather/AreasTypes.xsd
* @types http://Weather http://mydomain.com/SOA/Weather/TemperaturesTypes.xsd
*/
class WeatherService {
/**
* @param Areas $Areas http://Weather
* @return Temperatures http://Weather
*/
public function getTemperature($Areas) {
$Temperatures = SCA::createDataObject('http://Weather',
'Temperatures');
$Pair = $Temperatures->createDataObject('entry');
$Pair->state = 'CA';
$Pair->temperature = 65;
$Pair = $Temperatures->createDataObject('entry');
$Pair->state = 'UT';
$Pair->temperature = 105;
$Pair = $Temperatures->createDataObject('entry');
$Pair->state = 'ND';
$Pair->temperature = -20;
return $Temperatures;
}
}
?>

My client file:
<?php
include "SCA/SCA.php";

$weather = SCA::getService('http://mydomain.com/SOA/Weather/
WeatherService.php');

$Areas = $weather->createDataObject('http://Weather','Areas');
$area = $Areas->createDataObject('area');
$area->state = 'CA';
$area = $Areas->createDataObject('area');
$area->state = 'UT';
$area = $Areas->createDataObject('area');
$area->state = 'ND';
$Temperatures = $weather->getTemperature($Areas);

echo "Received temperatures from Web service:<br>";
foreach($Temperatures->entry as $Pair)
echo $Pair->state . ": " . $Pair->temperature . "<br>";
?>

The AreasTypes.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://Weather" elementFormDefault="qualified">
<complexType name="StateType">
<sequence>
<element name="state" type="string"/>
</sequence>
</complexType>
<element name="Areas">
<complexType>
<sequence>
<element name="area" type="ns1:StateType" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
</schema>

The TemperaturesTypes.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://Weather" elementFormDefault="qualified">
<complexType name="PairType">
<sequence>
<element name="state" type="string"/>
<element name="temperature" type="float"/>
</sequence>
</complexType>
<element name="Temperatures">
<complexType>
<sequence>
<element name="entry" type="ns1:PairType" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
</schema>

The WSDL file:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:tns2="http://WeatherService"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://
schemas.xmlsoap.org/wsdl/soap/" xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance" targetNamespace="http://WeatherService">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ns0="http://Weather"
xmlns:ns1="http://Weather"
targetNamespace="http://WeatherService"
elementFormDefault="qualified">
<xs:import schemaLocation="http://mydomain.com/SOA/Weather/
AreasTypes.xsd" namespace="http://Weather"/>
<xs:import schemaLocation="http://mydomain.com/SOA/Weather/
TemperaturesTypes.xsd" namespace="http://Weather"/>
<xs:element name="getTemperature">
<xs:complexType>
<xs:sequence>
<xs:element name="Areas" type="ns1:Areas"/>

</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getTemperatureResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="getTemperatureReturn"
type="ns1:Temperatures"/>
</xs:sequence>
</xs:complexType>

</xs:element>
</xs:schema>
</wsdl:types>

<wsdl:message name="getTemperatureRequest">
<wsdl:part name="getTemperatureRequest"
element="tns2:getTemperature"/>
</wsdl:message>
<wsdl:message name="getTemperatureResponse">
<wsdl:part name="return" element="tns2:getTemperatureResponse"/>

</wsdl:message>
<wsdl:portType name="WeatherServicePortType">
<wsdl:operation name="getTemperature">
<wsdl:input message="tns2:getTemperatureRequest"/>
<wsdl:output message="tns2:getTemperatureResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="WeatherServiceBinding"
type="tns2:WeatherServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document"/>

<wsdl:operation name="getTemperature">
<soap:operation soapAction=""/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>

</wsdl:binding>
<wsdl:service name="WeatherServiceService">
<wsdl:port name="WeatherServicePort"
binding="tns2:WeatherServiceBinding">
<soap:address location="http://mydomain.com/SOA/Weather/
WeatherService.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

<!-- this line identifies this file as WSDL generated by SCA for PHP.
Do not remove -->


Can you tell me what I am doing wrong?

The next question is: How can I create a dynamic data object returning
to the client a list of some information?

Thank you guys!
simonslaws-gM/Ye1E23mwN+
2008-01-03 11:07:03 UTC
Permalink
Post by aouriques
Hello friends,
How can I return a Data Object to the client side?
I am using the SDO_DAS_XML to create the data object but I cannot send
to the client the correct object.
I have tried this example (and a lot others):http://www.ibm.com/developerworks/web/library/ws-soa-scasdo/index.html
<?php
include "SCA/SCA.php";
/**
*
*/
class WeatherService {
/**
*/
public function getTemperature($Areas) {
$Temperatures = SCA::createDataObject('http://Weather',
'Temperatures');
$Pair = $Temperatures->createDataObject('entry');
$Pair->state = 'CA';
$Pair->temperature = 65;
$Pair = $Temperatures->createDataObject('entry');
$Pair->state = 'UT';
$Pair->temperature = 105;
$Pair = $Temperatures->createDataObject('entry');
$Pair->state = 'ND';
$Pair->temperature = -20;
return $Temperatures;
}}
?>
<?php
include "SCA/SCA.php";
$weather = SCA::getService('http://mydomain.com/SOA/Weather/
WeatherService.php');
$Areas = $weather->createDataObject('http://Weather','Areas');
$area = $Areas->createDataObject('area');
$area->state = 'CA';
$area = $Areas->createDataObject('area');
$area->state = 'UT';
$area = $Areas->createDataObject('area');
$area->state = 'ND';
$Temperatures = $weather->getTemperature($Areas);
echo "Received temperatures from Web service:<br>";
foreach($Temperatures->entry as $Pair)
echo $Pair->state . ": " . $Pair->temperature . "<br>";
?>
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://Weather" elementFormDefault="qualified">
<complexType name="StateType">
<sequence>
<element name="state" type="string"/>
</sequence>
</complexType>
<element name="Areas">
<complexType>
<sequence>
<element name="area" type="ns1:StateType" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
</schema>
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://Weather" elementFormDefault="qualified">
<complexType name="PairType">
<sequence>
<element name="state" type="string"/>
<element name="temperature" type="float"/>
</sequence>
</complexType>
<element name="Temperatures">
<complexType>
<sequence>
<element name="entry" type="ns1:PairType" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
</schema>
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:tns2="http://WeatherService"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://
schemas.xmlsoap.org/wsdl/soap/" xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance" targetNamespace="http://WeatherService">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ns0="http://Weather"
xmlns:ns1="http://Weather"
targetNamespace="http://WeatherService"
elementFormDefault="qualified">
<xs:import schemaLocation="http://mydomain.com/SOA/Weather/
AreasTypes.xsd" namespace="http://Weather"/>
<xs:import schemaLocation="http://mydomain.com/SOA/Weather/
TemperaturesTypes.xsd" namespace="http://Weather"/>
<xs:element name="getTemperature">
<xs:complexType>
<xs:sequence>
<xs:element name="Areas" type="ns1:Areas"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getTemperatureResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="getTemperatureReturn"
type="ns1:Temperatures"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="getTemperatureRequest">
<wsdl:part name="getTemperatureRequest"
element="tns2:getTemperature"/>
</wsdl:message>
<wsdl:message name="getTemperatureResponse">
<wsdl:part name="return" element="tns2:getTemperatureResponse"/>
</wsdl:message>
<wsdl:portType name="WeatherServicePortType">
<wsdl:operation name="getTemperature">
<wsdl:input message="tns2:getTemperatureRequest"/>
<wsdl:output message="tns2:getTemperatureResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="WeatherServiceBinding"
type="tns2:WeatherServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document"/>
<wsdl:operation name="getTemperature">
<soap:operation soapAction=""/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="WeatherServiceService">
<wsdl:port name="WeatherServicePort"
binding="tns2:WeatherServiceBinding">
<soap:address location="http://mydomain.com/SOA/Weather/
WeatherService.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
<!-- this line identifies this file as WSDL generated by SCA for PHP.
Do not remove -->
Can you tell me what I am doing wrong?
The next question is: How can I create a dynamic data object returning
to the client a list of some information?
Thank you guys!
Hi there

You should be able to do this and on the face of it your code looks
good. Can you tell me....

1. What was the result of running it. An error? Just no return data?
2. Did the input parameter ($Areas) get delivered successfully?
3. What version of the code you are using?

We do return complex types in some of the samples, for example, [1].
Haven't run it for a while so will have to get set up and give it a
spin to make sure it still works.

Regards

Simon

[1] http://cvs.php.net/viewvc.cgi/pecl/sdo/examples/SCA/emailcontact/ContactService.php?view=markup
Continue reading on narkive:
Loading...