Wsdl返回php对象

时间:2012-04-17 06:39:43

标签: php soap wsdl zend-soap

修改:我的代码没有问题。服务器正在从缓存中读取wsdl文件。解决问题:

  1. 使用ini_set("soap.wsdl_cache_enabled", 0);
  2. 停用缓存
  3. 否则,每次更改wsdl文件后,都会从/ tmp目录中删除缓存文件。
  4. 我正在使用zend soap来创建Web服务。我试图从中返回一个复杂的类型。我的php类看起来像这样:

    require_once 'myclass.php';
    
    class MyService {
        /**
         *
         * @param integer param1
         * @param string param2
         * @return myclass
         */
        public function myfunction ($param1, $param2) {
    
            $myobj= new myclass();
            $myobj->returncode = 100;
            return $myobj;
        }
    }
    

    myclass是一个带有两个公共变量的简单类

    class myclass {
        /** @var int */
        public $returncode = '0';
    
        /** @var string */
        public $returnmessage = 'Başarılı';
    
    }
    

    我使用AutoDiscovery生成wsdl文件:

    <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://my.domain.com/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="MyService" targetNamespace="http://my.domain.com/wsdl/">
      <types>
      <xsd:schema targetNamespace="http://my.domain.com/wsdl/">
      <xsd:complexType name="myclass">
        <xsd:all>
        <xsd:element name="returncode" type="xsd:int"/>
        <xsd:element name="returnmessage" type="xsd:string"/>
        </xsd:all>
      </xsd:complexType>
      </xsd:schema>
      </types>
      <portType name="MyServicePort">
      <operation name="myfunction">
      <documentation></documentation>
      <input message="tns:myfunctionIn"/>
      <output message="tns:myfunctionOut"/>
      </operation>
      </portType>
      <binding name="MyServiceBinding" type="tns:MyServicePort">
      <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
      <operation name="myfunction">
      <soap:operation soapAction="http://my.domain.com/wsdl/#myfunction"/>
      <input>
      <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://my.domain.com/wsdl/"/>
      </input>
      <output>
      <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://my.domain.com/wsdl/"/>
      </output>
      </operation>
      </binding>
      <service name="MyServiceService">
      <port name="MyServicePort" binding="tns:MyServiceBinding">
      <soap:address location="http://my.domain.com/wsdl/"/>
      </port>
      </service>
      <message name="myfunctionIn">
      <part name="param1" type="xsd:int"/>
      <part name="param2" type="xsd:string"/>
    
      </message>
        <message name="myfunctionOut">
        <part name="return" type="tns:myclass"/>
      </message>
      </definitions>
    

    我可以毫无问题地接收原始类型。当我尝试返回一个对象时,它将对象转换为字符串(显示“对象”)并返回:

    <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://my.domain.com/wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
       <ns1:myfunctionResponse>
          <return xsi:type="xsd:string">Object</return>
      </ns1:myfunctionResponse>
    </SOAP-ENV:Body>
    

    我想要一个这样的结果:

    <myclass>
      <returncode>100</returncode>
      <returnmessage>Ok</returnmessage>
    </myclass>
    

    谢谢。

0 个答案:

没有答案