SOAP servis
serveru bezi nekonecny cyklus ktory (momentalne) inkrementuje cislo, potreboval
by som vsak toto aktualne cislo zobrazit u uzivatela v prehliadaci, avsak so
SOAPom vela skusenosti nemam...nevedel by niekto pomoct? nie do databazy to
cislo ukladat nebudem...
velka vdaka za pomoc
Pre pridávanie komentárov sa musíte prihlásiť.
-mod na hostingu nemusi byt
-da sa upravit
ten druhy dovod je podstatny, ked chcem komunikovat s microsoftackym soap serverom - hajzlik to berie trocha svojsky ... ;-)
$server->addFunction("getCatalogEntry('$i')"); ale toto vsak nejde parameter mozem posielat iba z klienta a to stylom
$client->getCatalogEntry('nejaky integer'); ja si s tym vobeec neviem dat rady :( navyse ked to bude v nekonecnom cykle na serveri ta inkrementacia zobrazi sa aktualne cislo klientovi v prehliadaci?
tu je dobty priklad http://www.scottnichol.com/nusoapprogwsdl.htm
klientovy sa zobrazi cislo, ktore bude na serveri v momente zaslania poziadavky od klienta.
skusal som nieco na styl: server
$i=0;
while(true)
{
$i++;
}
function getCatalogEntry($catalogId) {
return $i;
}
ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer("catalog.wsdl");
$server->addFunction("getCatalogEntry");
$server->handle();
ktore bezi v konzole a:
$client = new SoapClient("catalog.wsdl");
$catalogId='catalog2';
$response = $client->getCatalogEntry($catalogId);
echo $response;
ktore bezi u klienta... avsak ked spustim klienta browser zamrzne
skusal som while prepisat aj na
function getCatalogEntry($catalogId) {
while(true)
{
$i++;
return $i;
}
}
ale to vzdy vypisalo iba 2 pretoze ta funkcia sa zavolala iba raz
nejake napady ako to spravit alebo nieco? :P vdaka
ja by som skopiroval kod z toho prikladu a upravil 'hello'. a ten nekonecny cyklus - ked tam php vojde, tak uz nevyjde (neviem ako je to pri preteceni...) takto to nefunguje, na serveri php nebezi na pozadi. ten cyklus sa spusti, ked posles soap request, ale ostane v nom vysiet do nekonecna. ak potrebujes na testovanie posielat nejaky integer, ktory sa inkrementuje mozes pouzit timestamp ;-)
function hello($name) {
return time();
}
kazdopadne malo to byt nieco v tom zmysle ze v php.exe (musim robit na windowse) bezi ten nekonecny cyklus ktory prijima packety (nick a data) a rozposiela ich online uzivatelom do prehliadaca kdekolvek po sieti... a prave na ten rozvoz dat by som potreboval soap aby klient dostal data co najskor od prijatia packetu UDPckom v php.exe... je to vobec mozne spravit cez SOAP alebo ako to inac spravit?
server1.php
<?php
$a=5;
function putCatalogEntry() {
global $a;
return $a;
}
function getCatalogEntry($dat){
global $a;
$a = $a.$dat;
return $a;
}
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("catalog.wsdl");
$server->addFunction("getCatalogEntry");
$server->handle();
?>
catalog.wsdl
<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='Catalog'
targetNamespace='http://example.org/catalog'
xmlns:tns=' http://example.org/catalog '
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:soapenc='http://schemas.xmlsoap.org/soap/
encoding/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
xmlns='http://schemas.xmlsoap.org/wsdl/'>
<message name='getCatalogRequest'>
<part name='catalogId' type='xsd:string'/>
</message>
<message name='getCatalogResponse'>
<part name='Result' type='xsd:string'/>
</message>
<portType name='CatalogPortType'>
<operation name='getCatalogEntry'>
<input message='tns:getCatalogRequest'/>
<output message='tns:getCatalogResponse'/>
</operation>
</portType>
<binding name='CatalogBinding' type='tns:CatalogPortType'>
<soap:binding style='rpc'
transport='http://schemas.xmlsoap.org/soap/http'/>
<operation name='getCatalogEntry'>
<soap:operation soapAction='urn:localhost-catalog#getCatalogEntry'/>
<input>
<soap:body use='encoded' namespace=
'urn:localhost-catalog'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</input>
<output>
<soap:body use='encoded' namespace='urn:localhost-catalog' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</output>
</operation>
</binding>
<service name='CatalogService'>
<port name='CatalogPort' binding='CatalogBinding'>
<soap:address location='http://localhost/server1.php'/>
</port>
</service>
</definitions>
nieco som uz skusal ale nevyslo to... potrebujem spravit aby SOAP bral aj funkciu getCatalogEntry aj putCatalogEntry
vdaka
client1
<?php
$client = new
SoapClient(
"catalog.wsdl"
);
print($client->putCatalogEntry("abc798654"));
?>
client2
<?php
$adder = new
SoapClient(
"catalog.wsdl"
);
//$adder->getCatalogEntry("sth");
echo $adder->getCatalogEntry();
?>
server1
<?php
$a=5;
//client1.php put
//client2.php get
function putCatalogEntry($dat){
global $a;
$a = $a.$dat;
return $a;
}
function getCatalogEntry() {
global $a;
return $a;
}
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("catalog.wsdl");
$server->addFunction("getCatalogEntry");
$server->addFunction("putCatalogEntry");
$server->handle();
?>