/    Sign up×
Community /Pin to ProfileBookmark

How PHP SOAP handle client request?

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!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@sunnysideauthorApr 26.2007 — server1.php
[CODE]
$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();
[/CODE]


client3.php
[CODE]
$client = new SoapClient("stockquote.wsdl");
$client->getQuote("ibm");
[/CODE]


stockquote.wsdl
[CODE]

<?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>
[/CODE]


After I run client3.php, give me the following error message:

Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in C:Program Filesxampphtdocsxmlstockquoteclient3.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 Filesxampphtdocsxmlstockquoteclient3.php(3): SoapClient->getQuote('ibm') #3 {main} thrown in C:Program Filesxampphtdocsxmlstockquoteclient3.php on line 3

All these three files are sitting on my localhost within one same folder. when I run $client-&gt;__getFunctions(), I have no problem to see the right result: Array ( [0] =&gt; float getQuote(string $symbol) )
×

Success!

Help @sunnyside spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...