How to easily consume a web service from PHP

后端 未结 7 1766
Happy的楠姐
Happy的楠姐 2020-11-27 10:50

Is there available any tool for PHP which can be used to generate code for consuming a web service based on its WSDL? Something comparable to clicking \"Add Web Reference\"

7条回答
  •  醉话见心
    2020-11-27 11:10

    Say you were provided the following:

    
        
        
            
                12345
            
        
    
    

    and

    
        
            
                
                    true
                    003p0000006XKX3AAO
                    Abcdef1234567890
                
            
        
    
    

    Let's say that accessing http://thesite.com/ said that the WSDL address is: http://thesite.com/PortalIntegratorService.svc?wsdl

    $client = new SoapClient('http://thesite.com/PortalIntegratorService.svc?wsdl');
    $result = $client->authenticateLogin(array('LoginId' => 12345));
    if (!empty($result->authenticateLoginResult->RequestStatus)
        && !empty($result->authenticateLoginResult->UserName)) {
        echo 'The username is: '.$result->authenticateLoginResult->UserName;
    }
    

    As you can see, the items specified in the XML are used in the PHP code though the LoginId value can be changed.

提交回复
热议问题