Error in Soap Web Service
Posted: Sat Mar 21, 2009 9:15 am
Hi,
I try to create web sevice with soap extension in php.
But I get "looks like we got no XML document" Exception.
The code for soapserver.php
The code for soapclient.php
And City.wsdl file is as follows
So please help me .
Thanks in advance.
I try to create web sevice with soap extension in php.
But I get "looks like we got no XML document" Exception.
The code for soapserver.php
Code: Select all
<?php
function sayHello($name){
$salutation = "You, $name, will be delighted to know I am working!";
return $salutation;
}
function City($po)
{
var_dump($po);
//$out1 = ob_get_contents();
if (!$link = mysql_connect('localhost', 'root', ''))
{
die('Not connected : ' . mysql_error());
// make foo the current db
$conn = mysql_select_db('example', $link);
if(!$conn){
throw new SoapFault("Server","Failed to connect to database");
};
$sql = "select City_Name from city where City='".$po."'";
$query=mysql_query($sql)or die("Failed to select PO");
// $msg=$po;//'<rsltMsg>City Select!</rsltMsg>';
$msg='<rsltMsg>City Select!</rsltMsg>';
return $msg;
}
}
$server = new SoapServer ("City.wsdl");
$server->addFunction("City");
$server->handle();
?>
Code: Select all
<?php
$client = new SoapClient("City.wsdl");
$po='1';
try {
print $result=$client->City(1);
}
catch (SoapFault $exp) {
print $exp->getMessage()."Error";
}
?>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.example.org/NewWSDLFile/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="NewWSDLFile" targetNamespace="http://www.example.org/NewWSDLFile/">
<wsdl:types>
<xsd:schema targetNamespace="http://www.example.org/NewWSDLFile/">
<xsd:element name="City">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="City_Id" type="xsd:int" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="CityResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="City_Name" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="CityRequest">
<wsdl:part element="tns:City" name="parameters"/>
</wsdl:message>
<wsdl:message name="CityResponse">
<wsdl:part element="tns:CityResponse" name="parameters"/>
</wsdl:message>
<wsdl:portType name="City">
<wsdl:operation name="City">
<wsdl:input message="tns:CityRequest"/>
<wsdl:output message="tns:CityResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="NewWSDLFileSOAP" type="tns:City">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="City">
<soap:operation soapAction="http://www.example.org/NewWSDLFile/NewOperation"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="City">
<wsdl:port binding="tns:NewWSDLFileSOAP" name="City">
<soap:address location="http://localhost/WebService/SoapServer/soapserver.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Thanks in advance.