Wsdl返回php对象

Wsdl返回php对象,php,soap,wsdl,zend-soap,Php,Soap,Wsdl,Zend Soap,编辑:我的代码没有问题。服务器正在从缓存中读取wsdl文件。要解决这个问题: 使用ini\u集禁用缓存(“soap.wsdl\u缓存已启用”,0) 否则,每次更改wsdl文件后,都要从/tmp目录中删除缓存文件 我正在使用zend soap创建web服务。我试图从中返回一个复杂类型。我的php类如下所示: require_once 'myclass.php'; class MyService { /** * * @param integer param1

编辑:我的代码没有问题。服务器正在从缓存中读取wsdl文件。要解决这个问题:

  • 使用
    ini\u集禁用缓存(“soap.wsdl\u缓存已启用”,0)
  • 否则,每次更改wsdl文件后,都要从/tmp目录中删除缓存文件
  • 我正在使用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ı';
    
    }
    
    我正在使用生成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>
    
    
    
    我可以毫无问题地接收基本类型。当我尝试返回一个对象时,它会将对象转换为字符串(显示“object”),并返回:

    <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>
    
    
    100
    好啊
    

    谢谢。

    你应该把你的答案当作一个对象来对待。当你得到一些基本类型时,结果是什么?它返回一个字符串对象,而不是myclass的实例。基本类型是可以的。当我返回“abc”时:abc。然而,我需要返回多个变量,所以我需要一个复杂的类型。它还生成(字符串)“Object”。我将查看wsdl的
    部分。什么是
    tns:myclass
    类型?这里需要一个复杂的类型。