Page 1 of 1

How PHP SOAP handle client request?

Posted: Thu Apr 26, 2007 9:37 am
by sunnyside
It's my first time to touch the php SOAP. I have a wsdl file sits in my server. client send some request to the server (my side), then I'm gonna analyzes the data client sent to me, if it's correct, will put data into DB; otherwise I will send a response message back (all using SOAP format).

I've tried PHP Soap and NuSoap both, but just don't know how I can analyze the data that I received, then send message back.

Can you give me some tips? thank you!

Posted: Thu Apr 26, 2007 11:19 am
by volka
You might be interested in http://devzone.zend.com/node/view/id/689

Posted: Thu Apr 26, 2007 1:23 pm
by sunnyside
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


[quote="volka"]You might be interested in http://devzone.zend.com/node/view/id/689[/quote]

yes, I tried it already. but when I run it in my localhost, it gave me the following error:

Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in C:\Program Files\xampp\htdocs\xml\stockquote\client3.php:3 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://localhos...', 'urn:xmethods-de...', 1, 0) #1 [internal function]: SoapClient->__call('getQuote', Array) #2 C:\Program Files\xampp\htdocs\xml\stockquote\client3.php(3): SoapClient->getQuote('ibm') #3 {main} thrown in C:\Program Files\xampp\htdocs\xml\stockquote\client3.php on line 3

server1.php

Code: Select all

$quotes = array("ibm"=>98.42); 

function getQuote($symbol) {
  global $quotes;
  return $quotes[$symbol];
}

//ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("stockquote.wsdl");
$server->addFunction("getQuote");

$server->handle();

client3.php

Code: Select all

$client = new SoapClient("stockquote.wsdl");
$client->getQuote("ibm");
stockquote.wsdl

Code: Select all

<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='StockQuote'
  targetNamespace='http://localhost/xml/stockquote/StockQuote'
  xmlns:tns='http://localhost/xml/stockquote/StockQuote'
  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='getQuoteRequest'>
  <part name='symbol' type='xsd:string'/>
</message>
<message name='getQuoteResponse'>
  <part name='Result' type='xsd:float'/>
</message>

<portType name='StockQuotePortType'>
  <operation name='getQuote'>
    <input message='tns:getQuoteRequest'/>
    <output message='tns:getQuoteResponse'/>
  </operation>
</portType>

<binding name='StockQuoteBinding' type='tns:StockQuotePortType'>
  <soap:binding style='rpc'
    transport='http://schemas.xmlsoap.org/soap/http'/>
  <operation name='getQuote'>
    <soap:operation soapAction='urn:xmethods-delayed-quotes#getQuote'/>
    <input>
      <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
    </input>
    <output>
      <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
    </output>
  </operation>
</binding>

<service name='StockQuoteService'>
  <port name='StockQuotePort' binding='tns:StockQuoteBinding'>
    <soap:address location='http://localhost/xml/stockquote/server1.php'/>
  </port>
</service>
</definitions>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Apr 26, 2007 2:05 pm
by volka
sunnyside wrote:Could not connect to host
server1.php and client3.php are on the same computer and a webserver is running? It doesn't look that way.

Posted: Thu Apr 26, 2007 2:34 pm
by sunnyside
volka wrote:
sunnyside wrote:Could not connect to host
server1.php and client3.php are on the same computer and a webserver is running? It doesn't look that way.
both server1.php and client3.php are sit on my local machine (localhost), as well as the WSDL file. the purpose of it to testing. in my client3.php, if i run

Code: Select all

$client->__getFunctions()
, I have no problem to get the

Code: Select all

Array ( [0] => float getQuote(string $symbol) )
result.

Posted: Thu Apr 26, 2007 3:51 pm
by volka
For some reason it cannot connect to the webserver. Can't tell you why.

Posted: Wed May 02, 2007 8:11 am
by DariuzArkham
sunnyside wrote:
volka wrote:
sunnyside wrote:Could not connect to host
server1.php and client3.php are on the same computer and a webserver is running? It doesn't look that way.
both server1.php and client3.php are sit on my local machine (localhost), as well as the WSDL file. the purpose of it to testing. in my client3.php, if i run

Code: Select all

$client->__getFunctions()
, I have no problem to get the

Code: Select all

Array ( [0] => float getQuote(string $symbol) )
result.

I've had this exact problem myself.

When I changed "localhost" to "127.0.0.1" in the .wsdl file it worked.