Witam,
stworzyłem do celów testowych prosty web service "MathCalculator", który posiada dwie metody MathAdd i MathMulti (dodawanie i mnożenie). Metody przyjmują dwa parametry wejściowe NoA i NoB, wynik to MathResult. Poniżej plik WSDL serwisu:
<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://example.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" name="MathCalculator" targetNamespace="http://example.com/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xs:schema xmlns:tns="http://schemas.xmlsoap.org/wsdl/" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://example.com/">
<element name="MathCalc">
<complexType>
<sequence>
<element name="NoA" type="int" />
<element name="NoB" type="int" />
</sequence>
</complexType>
</element>
<element name="MathCalcResponse">
<complexType>
<sequence>
<element name="MathResult" type="int" />
</sequence>
</complexType>
</element>
<element name="string" type="string" />
</xs:schema>
</types>
<message name="MathCalculatorSoapIn">
<part name="parameters" element="tns:MathCalc" />
</message>
<message name="MathCalculatorSoapOut">
<part name="parameters" element="tns:MathCalcResponse" />
</message>
<portType name="MathCalculatorSoap">
<operation name="MathMulti">
<input message="tns:MathCalculatorSoapIn" />
<output message="tns:MathCalculatorSoapOut" />
</operation>
<operation name="MathAdd">
<input message="tns:MathCalculatorSoapIn" />
<output message="tns:MathCalculatorSoapOut" />
</operation>
</portType>
<binding name="MathCalculatorSoap" type="tns:MathCalculatorSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="MathAdd">
<soap12:operation soapAction="MathAdd" />
<input>
<soap12:body use="literal" />
</input>
<output>
<soap12:body use="literal" />
</output>
</operation>
<operation name="MathMulti">
<soap12:operation soapAction="MathMulti" />
<input>
<soap12:body use="literal" />
</input>
<output>
<soap12:body use="literal" />
</output>
</operation>
</binding>
<service name="MathCalculator">
<port name="MathCalculatorSoap" binding="tns:MathCalculatorSoap">
<soap12:address location="http://localhost/math/MathCalculator.php" />
</port>
</service>
</definitions>
Web service wygląda następująco (plik MathCalculator.php):
<?php
define("WSDL_PATH","MathCalcService.wsdl");
if (isset($_GET['WSDL'])) { header('Content-Type: text/xml'); }
else {
$server = new SoapServer(WSDL_PATH);
function MathMulti($MathCalc) {
$rr=$MathCalc->NoA * $MathCalc->NoB;
return array("MathResult"=>$rr); }
function MathAdd($MathCalc) {
$rr=$MathCalc->NoA + $MathCalc->NoB;
return array("MathResult"=>$rr); }
$server->AddFunction(array("MathMulti","MathAdd")); $server->handle();
}
?>
Klient testujący web service (odałem wywołanie __getFunctions() i __getTypes() żeby sprawdzić so się dzieje):
<?php
$client = new SoapClient("http://localhost/math/MathCalculator.php?WSDL");
"NoA" => 5,
"NoB" => 5
);
$response = $client->__soapCall
("MathAdd", array($params)); echo '<p>Result : ' . $params['NoA'] . '+' . $params['NoB'] . ' = ' . $response->MathResult . '</p>';
$response = $client->__soapCall
("MathMulti", array($params)); echo '<p>Result : ' . $params['NoA'] . '*' . $params['NoB'] . ' = ' . $response->MathResult . '</p>'; ?>
Wynik wywołania klienta w przeglądarce:
Cytat
array (size=2)
0 => string 'MathCalcResponse MathAdd(MathCalc $parameters)' (length=46)
1 => string 'MathCalcResponse MathMulti(MathCalc $parameters)' (length=48)
array (size=2)
0 => string 'struct MathCalc {
int NoA;
int NoB;
}' (length=39)
1 => string 'struct MathCalcResponse {
int MathResult;
}' (length=44)
Result : 5+5 = 10
Result : 5*5 = 10
Jak widać serwis wykonuje tylko jedną metodę, w tym przypadku MathAdd, ponieważ jest ona pierwsza w definicji WSDL. Jeśli zmienię kolejność deklaracji metod w pliku WSDL, serwer będzie zawsze wykonywał tylko mnożenie. Czy mogę prosić o pomoc w zdiagnozowaniu problemu?
Z góry dziękuję