我有一个使用wsdl文件的类,

class myAPI{    

        public function Authenticate($id,$password){  

            $opts = array('location' => 'http://xx',
              'uri' => 'urn:xxx',
              'trace' => 1);
            $client2 = new SOAPClient(null, $opts);

            $quote = $client2 ->__soapCall('createsession', array(''));  
            $session = $quote -> sessionid;
            $sessionOk = $quote -> result;
            if ($sessionOk == 0)
            {     
                    $shaStr1 =  $id.$password;
                    $shaStr1 =  sha1($shaStr1);
                    $shaStr2 = $session.strtolower($shaStr1);
                    $shaStr2 =  strtoupper(sha1($shaStr2));


                    $xml_params = '<ns1:loginRequest> <ns1:initiator>'.$id.'</ns1:initiator>  <ns1:pin>'.$shaStr2.'</ns1:pin>  <ns1:sessionid>'.$session.'</ns1:sessionid> </ns1:loginRequest>';


                    try 
                    { 
                        $soapVar = new SoapVar($xml_params, XSD_ANYXML, null, null, null); 

                    }                   
                    catch(Exception $e)
                    {       
                        $message = $e->getMessage(); 
                        $err = array (
                           'result' => '999',
                           'transid' => '0',
                           'msg' => $message
                        );

                        return (object) $err;            
                    }

                    try 
                    {  
                        $result = $client2->login(new SoapParam($soapVar, 'login'));   

                        $resint = $result -> result;
                        $restrans = $result -> transid;   


                        return (object) array (
                           'result' => $resint,
                           'transid' => $restrans,
                           'msg' => 'Session Created',
                           'session' => $session
                        ); 


                    }  
                    catch(Exception $e) 
                    {  
                        $message = $e->getMessage(); 
                        $err = array (
                           'result' => '999',
                           'transid' => '0',
                           'msg' => $message
                        );

                        return (object) $err;       
                    } 


            }   
            else //session is invalid
            {
                    $err = array (
                           'result' => '999',
                           'transid' => '0',
                           'msg' => 'Invalid session'
                        );

                return (object) $err;  
            }       

        }
    ?>

我正在使用wsdl指向我的service.php文件,其中具有:service.php

<?php 
include("myAPI.php"); 
if(!extension_loaded("soap")){ 
  dl("php_soap.dll"); 
} 
ini_set("soap.wsdl_cache_enabled","0"); 
$server = new SoapServer("service.wsdl");

function login($info){
    $globeapi = new GlobeAPI;
    $loginResult = $globeapi->Authenticate($info -> id,$info -> password);  

     return $loginResult;

}

$server->AddFunction("login");   
$server->handle();

?>

当我尝试使用下面收到的所有代码使用它们时,我收到的是string(6)“ Object”,如果我尝试使用数组,它将返回string(5)“ Array”我在做什么错?

<?php
client = new SoapClient('http://xxxx/service.wsdl',
array(
'trace' =>true,
'exceptions' => 0,
'connection_timeout' => 500000,
'cache_wsdl' => WSDL_CACHE_BOTH,
'keep_alive' => false,
));

$response = $client->login('xxx','2222'); 
var_dump($response);
?>

===============>>#1 票数:0

我只想通知每个可能遇到相同问题的人。 我发现我的问题出在我的WSDL文件中。 我没有提供xsd:complexType,因此我返回的只是一个字符串。 我所做的是这样声明xsd:complexType

<xsd:schema targetNamespace="urn:xxx"
>
 <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
 <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
    <xsd:complexType name="resultInfo">
        <xsd:all>
            <xsd:element name="result" type="xsd:string"/>
            <xsd:element name="transid" type="xsd:string"/>
            <xsd:element name="msg" type="xsd:string"/>
            <xsd:element name="session" type="xsd:string"/>
        </xsd:all>
    </xsd:complexType>

</xsd:schema>

之后,我将所有响应类型从“ xsd:string”更改为我的复杂类型“ xsd:resultInfo”。 然后,我能够返回我的php页面中所需的对象。

  ask by mel mel translate from so

未解决问题?本站智能推荐: