This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

ckWebServicePlugin: extension and polymorphism support

Ask help about existing plugins, or find advice about the way to build up your own.

ckWebServicePlugin: extension and polymorphism support

by ventzy » Fri Aug 17, 2012 7:43 pm

I am trying to modify ckWebServicePlugin to support extending ComplexTypes and therefore polymorphism. I have success with extending, but I can't get polymorphism to work. I have no previous experience with SOAP and WSDL, so I will paste my wsdl schema and my php with hope somebody to help.

For simplicity I changed some types and code.

I have two classes - SfaQuantity and SfaQuantityTimePeriod extending SfaQuantity.
Code: Select all
/**
 * @PropertyStrategy('ckBeanPropertyStrategy')
 */
class SfaQuantity {

  /**
   * @var double
   */
  protected $amount;

  /**
   * @return double
   */
  public function getAmount() {
    return $this->amount;
  }

  /**
   * @param double $value
   */
  public function setAmount($value) {
    $this->amount = $value;
  }
}

/**
 * @PropertyStrategy('ckBeanPropertyStrategy')
 */
class SfaQuantityTimePeriod extends SfaQuantity {
 
  /**
   * @var double
   */
  protected $amountTime;

  /**
   * @return double
   */
  public function getAmountTime() {
    return $this->amountTime;
  }

  /**
   * @param double $value
   */
  public function setAmountTime($value) {
    $this->amountTime = $value;
  }
}


Method
Code: Select all
  /**
   *
   * @WSMethod(name='test', webservice='sfaBilling')
   *
   * @return SfaQuantity
   */
  public function executeTest(sfWebRequest $webRequest) {
    $q = new SfaQuantityTimePeriod();
    $this->result = $q;
    return sfView::SUCCESS;   
  }


WSDL
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="sfaBilling" targetNamespace="http://cms.local/" xmlns:tns="http://cms.local/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
  <wsdl:types xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://cms.local/">
      <xsd:complexType name="SfaQuantity">
        <xsd:sequence>
          <xsd:element name="amount" type="xsd:double"/>
        </xsd:sequence>
      </xsd:complexType>
      <xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SfaQuantityElement" type="tns:SfaQuantity"/>
      <xsd:complexType name="SfaQuantityTimePeriod">
        <xsd:complexContent>
          <xsd:extension base="tns:SfaQuantity">
            <xsd:sequence>
              <xsd:element name="amountTime" type="xsd:double"/>
            </xsd:sequence>
          </xsd:extension>
        </xsd:complexContent>
      </xsd:complexType>
      <xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SfaQuantityTimePeriodElement" type="tns:SfaQuantityTimePeriod"/>
    </xsd:schema>
  </wsdl:types>
  <wsdl:portType name="sfaBillingPortType">
    <wsdl:operation name="test">
      <wsdl:input message="tns:testRequest"/>
      <wsdl:output message="tns:testResponse"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="sfaBillingBinding" type="tns:sfaBillingPortType">
    <soap:binding xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="test">
      <soap:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="http://cms.local/test" style="rpc"/>
      <wsdl:input xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
        <soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" use="literal" namespace="http://cms.local/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </wsdl:input>
      <wsdl:output xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
        <soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" parts="result" use="literal" namespace="http://cms.local/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:message name="testRequest"/>
  <wsdl:message name="testResponse">
    <wsdl:part name="result" type="tns:SfaQuantity"/>
  </wsdl:message>
  <wsdl:service xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="sfaBillingService">
    <wsdl:port xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="sfaBillingPort" binding="tns:sfaBillingBinding">
      <soap:address xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" location="http://cms.local/sfaBilling.php"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>


So, method return type is defined as SfaQuantity and execution actually returns SfaQuantityTimePeriod. On client result is object with type SfaQuantity, so polymorphism does not work. I tried to return this object in another class field, but result is the same.

If method return type is SfaQuantityTimePeriod, on the client result is also SfaQuantityTimePeriod and both direct fields of SfaQuantityTimePeriod class and inherited fields of SfaQuantity have right values and thats why I think inheritance implementation is OK.

Why polymorphism does not work as I expect?
ventzy
Member
 
Posts: 30
Joined: Fri Jun 27, 2008 2:23 pm