Jump to content

Strange problem with SOAP.Only first declareted operation in bindings works fine


butterflydaniel

Recommended Posts

I have strange problem with SOAP. My file SchoolAPI look like that:

 

<?php
require_once('../require/constants.php');
require_once('../require/connection.inc.php');

class SchoolAPI{
private $dbh;

   	public function __construct()
    {
	 	$this->dbh = new PDO(DRIVER.':host='.HOST.';dbname='.DB, USER, PASSWORD);
  	}
  	
//function return all subcjects
public function getSubjects(){
	$sth = $this->dbh->prepare('  SELECT id, nazwa ROM subjects');
	$sth->execute(); 

		return $sth->fetchAll(PDO::FETCH_NUM); 	
	//return array(array("1", "subject1"),array("2", "subject2"));
}

//function return all classes
public function getClasses(){
	$sth = $this->dbh->prepare('  SELECT id, nazwa FROM classes');
	$sth->execute();  
		return $sth->fetchAll(PDO::FETCH_NUM);	
	//return array(array("1", "class1"),array("2", "class2"));
}
  
}
ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer("SchoolAPI.wsdl");
$server->setClass("SchoolAPI");
$server->handle();
?>

 

wsdl file is named SchoolAPI.wsdl and look like that:

 

<wsdl:definitions  
xmlns="http://schemas.xmlsoap.org/wsdl/" 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:tns="http://schema.example.com" 
targetNamespace="http://schema.example.com" >
  
  <wsdl:types>
  	<xsd:schema targetNamespace="http://schema.example.com">
	<xsd:complexType name="myarry2">
		<xsd:sequence>
			<xsd:element minOccurs="0" maxOccurs="unbounded" name="row" nillable="true" type="xsd:string" /> 
		</xsd:sequence>
	</xsd:complexType>
</xsd:schema>
    <xsd:schema targetNamespace="http://schema.example.com">
	<xsd:complexType name="myarray">
		<xsd:sequence>
			<xsd:element minOccurs="0" maxOccurs="unbounded" name="table" nillable="true" type="tns:myarry2" /> 
		</xsd:sequence>
	</xsd:complexType>
</xsd:schema>
  </wsdl:types>

  <wsdl:message name="getSubjectsRequest"></wsdl:message>
  <wsdl:message name="getSubjectsResponse">
    <part name="getSubjectsReturn" type="tns:myarray"/>
  </wsdl:message>

  <wsdl:message name="getClassesRequest"></wsdl:message>
  <wsdl:message name="getClassesResponse">
    <part name="getClassesReturn" type="tns:myarray"/>
  </wsdl:message>

  <wsdl:portType name="SchoolAPIPortType">
    <wsdl:operation name="getSubjects">
      <wsdl:input message="tns:getSubjectsRequest"/>
      <wsdl:output message="tns:getSubjectsResponse"/>
    </wsdl:operation>

    <wsdl:operation name="getClasses">
      <wsdl:input message="tns:getClassesRequest"/>
      <wsdl:output message="tns:getClassesResponse"/>
    </wsdl:operation>
  </wsdl:portType>

  <wsdl:binding name="SchoolAPIBinding" type="tns:SchoolAPIPortType">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="getSubjects">
      <soap:operation soapAction="urn:SchoolAPI/getSubjects" style="document"/>
      <wsdl:input> <soap:body use="literal"/></wsdl:input>
      <wsdl:output><soap:body use="literal"/></wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getClasses">
      <soap:operation soapAction="urn:SchoolAPI/getClasses" style="document"/>
      <wsdl:input> <soap:body use="literal"/></wsdl:input>
      <wsdl:output><soap:body use="literal"/></wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  
  <wsdl:service name="SchoolAPI">
    <wsdl:port name="SchoolAPIPort" binding="tns:SchoolAPIBinding">
      <soap:address location="http://localhost:82/myschool/webservices/SchoolAPI.php" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

 

The problem is that correct data is returned olny by first function declarated in <wsdl:binding> section. In this example correct data will be return by getSubjects function, and function getClassses return null. However, if we change order and put getClasses operation first in binding section like this:

 

  <wsdl:binding name="SchoolAPIBinding" type="tns:SchoolAPIPortType">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
 <wsdl:operation name="getClasses">
      <soap:operation soapAction="urn:SchoolAPI/getClasses" style="document"/>
      <wsdl:input> <soap:body use="literal"/></wsdl:input>
      <wsdl:output><soap:body use="literal"/></wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getSubjects">
      <soap:operation soapAction="urn:SchoolAPI/getSubjects" style="document"/>
      <wsdl:input> <soap:body use="literal"/></wsdl:input>
      <wsdl:output><soap:body use="literal"/></wsdl:output>
    </wsdl:operation>
  </wsdl:binding>

 

then correct data will be return by getClasses function, and getSubjects will return null. Do you know what is going on? I do my best to solve this problem and I have no idea what is wrong...

 

 

Link to comment
Share on other sites

I figure it out. This is solution:

 

  <wsdl:message name="getSubjectsRequest">
<part name="getSubjectsReq" type="xsd:string" />
  </wsdl:message>
  <wsdl:message name="getSubjectsResponse">
    <part name="getSubjectsReturn" type="tns:myarray"/>
  </wsdl:message>
  <wsdl:message name="getClassesRequest">
<part name="getClassesReq" type="xsd:string" />
  </wsdl:message>
  <wsdl:message name="getClassesResponse">
    <part name="getClassesReturn" type="tns:myarray"/>
  </wsdl:message>

 

Request Messages can't be empty.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.