Php and soap and wsdl

Hi,

I am trying out the webservice using php5 and soap. But even with a simple example from the internet I get always the same error on screen.

SoapFault exception: [HTTP] Could not connect to host in D:\www\int_soap\client.php:7

Anybody any idea?

Thanx in advance!
Jurgen

SoapFault exception: [HTTP] Could not connect to host in D:\www\int_soap\client.php:7

It tells you right there.

Is there an emoticon for smashing my head against a wall?

Yo Anus,

or mr ironic, I can read okay!

if you can’t help me or have no idea what it is about then leave this topic alone!

I think what Tanus means is that you have posted an error message and thats all, we could all have an educated guess if you want, but some sample code would have been nice.

It is also worth pointed out that this is the PHP Application Design forum and your question might be better in the general PHP forum.

George

Could it simply be that your script can’t connect to the address you tried…
The error message is pretty informative, just like Tanus says :slight_smile:

Try to surf to the address you have written in the script.

can you ping the host you’re trying to connect to?
post your code

I am using wampserver ( php 5.1.2 ).

The example I am testing is from:
http://www.zend.com/php5/articles/php5-SOAP.php

My client file:


$client = new SoapClient("quote.wsdl");
try {
	echo "<pre>\
";
	print($client->getQuote("ibm"));
	echo "\
";
	print($client->getQuote("microsoft"));
	echo "\
</pre>\
";
	}
catch(SoapFault $exception) {
	echo $exception;
	}

My server file:


class QuoteService {
  private $quotes = array("ibm" => 98.42);

  function getQuote($symbol) {
    if (isset($this->quotes[$symbol])) {
      return $this->quotes[$symbol];
    } else {
      throw new SoapFault("Server","Unknown Symbol '$symbol'.");
    }
  }
}

$server = new SoapServer("quote.wsdl");
$server->setClass("QuoteService");
$server->handle();

My localhost works fine, so my connection is no problem. But if I call the client file then I get this error:

SoapFault exception: [HTTP] Could not connect to host in D:\www\int_soap\client.php:5
Stack trace:
#0 [internal function]: SoapClient->__doRequest('__call(‘getQuote’, Array)
#2 D:\www\int_soap\client.php(5): SoapClient->getQuote(‘ibm’)
#3 {main}

Show us your WSDL file, specifically the <soap:address> element of the <port> section.

my wsdl file:

<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='StockQuote'
  targetNamespace='http://example.org/StockQuote'
  xmlns:tns=' http://example.org/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='QuoteService'>
  <port name='StockQuotePort' binding='StockQuoteBinding'>
    <soap:address location='http://locahost/int_soap/server.php'/>
  </port>
</service>
</definitions>

I have changed the address in the port section of my wsdl file from localhost to 127.0.0.1 and now it works.

Any explanation anyone?

Thank you all for your help!

Chances are your PC can’t resolve the hostname “localhost” to 127.0.0.1. Pull up a command shell and try to ping localhost. If you can’t, go into the hosts file:


%WINDIR%\\system32\\drivers\\etc\\hosts

In that file somewhere there should be a mapping between 127.0.0.1 and localhost:


127.0.0.1        localhost

If there isn’t, add it in. Then try accessing localhost again.

[ot]Any of the following should apply:
:headbang: :smashy: :faq1: :faq2: :rolleyes: :bomb: :whip: :badpc: :argue:[/ot]

Use NuSAOP and it auto creates your WSDL for you. :slight_smile:

I have to say that PHP5 is seriously lacking a solid WSDL generator. It’s one of the things which really stops me from wanting to use it. I know Zend has one, but IMHO it’s a bit hit || miss.

George