Jump to content

[SOLVED] Weird Response From Webservice


biggusjimmus

Recommended Posts

So, I'm trying to write a simple webservice on OS X 10.5.6, PHP 5.2.6, but I can't get it to work.

 

I'm getting the following exception:

SoapFault exception: [Client] DTD are not supported by SOAP in /Users/jvelliott/Sites/soaptest/client.php:7 Stack trace: #0 [internal function]: SoapClient->__call('getCatalogEntry', Array) #1 /Users/jvelliott/Sites/soaptest/client.php(7): SoapClient->getCatalogEntry('catalog1') #2 {main}

 

I realize that this means that I'm getting some HTML back, so I went ahead and called the __getLastResponse() method, and it seems to be returning the content of index.html for some reason.

 

My code is below:

 

WSDL (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/~jvelliott/soaptest/myls.php'/> 
  </port> 
</service>
</definitions>

 

Server (myls.php):

<?php 
function getCatalogEntry($catalogId) { 
  if($catalogId=='catalog1') {

return "<HTML>
<HEAD>
  <TITLE>Catalog</TITLE>
</HEAD
<BODY>
...
</BODY>
</HTML>";
}
elseif ($catalogId='catalog2') {

return "<HTML>
<HEAD>
  <TITLE>Catalog</TITLE>
</HEAD
<BODY>
...
</BODY>
</HTML>";
} 
}
ini_set("soap.wsdl_cache_enabled", "0"); 
$server = new SoapServer("catalog.wsdl"); 
$server->addFunction("getCatalogEntry"); 
$server->handle(); 



?>

 

Client (client.php):

<?php  
  $client = new SoapClient("http://localhost/~jvelliott/soaptest/catalog.wsdl", array('trace'=>1));
  #$client = new SoapClient("catalog.wsdl", array('trace'=>1));

  $catalogId='catalog1';
  try {
    $result = $client->getCatalogEntry($catalogId);
    #$results = $client->__soapCall("getCatalogEntry", array($catalogId));
    
    echo $result;
  }
  catch(SoapFault $e) {
    echo "$e\n";
    echo $client->__getLastRequest();
    echo "\n";
    echo $client->__getLastResponse();
  }
?>

 

They're all in the same directory, and can be found at http://localhost/~username/soaptest/

 

They are returning the HTML from http://localhost/index.html

 

If there is a better forum for this, please let me know, or move this post.

Link to comment
https://forums.phpfreaks.com/topic/146341-solved-weird-response-from-webservice/
Share on other sites

OK, figured it out. Apparently the result got stuck in the cache, and I wasn't clearing it.

 

How it got into the cache in the first place, I have no idea, but clearing it seems to have solved the problem.

 

ini_set("soap.wsdl_cache_enabled", "0");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.