2016-02-10 2 views
0

Я сделал много интеграции REST, но у меня нет опыта работы с SOAP. Вот пример запроса SOAP v1.1 ... как это выполнить на PHP? Кроме того, нам предоставляется возможность использовать SOAP v1.1 или v1.2 - что я должен использовать?Сделать запрос SOAP с помощью PHP

POST /l/webservice/employee.asmx HTTP/1.1 
Host: webservices.domain.com 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
SOAPAction: "http://www.domain.com/l/webservices/ExportEmployeeInformation" 

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <ExportEmployeeInformation xmlns="http://www.domain.com/l/webservices/"> 
     <sTicket>string</sTicket> 
    </ExportEmployeeInformation> 
    </soap:Body> 
</soap:Envelope> 

Вот запрос v1.2 образец МЫЛО:

POST /l/webservice/employee.asmx HTTP/1.1 
Host: webservices.domain.com 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <ExportEmployeeInformation xmlns="http://www.domain.com/l/webservices/"> 
     <sTicket>string</sTicket> 
    </ExportEmployeeInformation> 
    </soap12:Body> 
</soap12:Envelope> 

Спасибо!

ответ

1

Я подключаюсь к веб-сервису SOAP, используя функцию PHP ниже. Я надеюсь, что это помогает.

public $credentials = array('login'=>'my_login', 'pass'=>'my_pass'); 

/** 
* @param string $url URL E.g.: http://domain.com/webservice/page.asmx 
* @param string $method E.g.: findEmployees 
* @param string $parameters E.g.: array('employed_id'=>100) 
* @return stdClass|SoapFault 
*/ 
public function soapFunction($url = null, $method = null, $parameters = array(), $debug = false) { 
    $configs = array(
     'soap_version' => SOAP_1_2, 
     'cache_wsdl' => WSDL_CACHE_NONE, 
     'exceptions' => false, 
     'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP 
    ); 
    if($debug) $configs['trace'] = true; 

    if(substr($url, -5) != '?WSDL') $url.= '?WSDL'; 
    @$webService = new SoapClient($url, $configs); 


    $parameters = array_merge($parameters, array('credential'=>$this->credentials)); 
    $response = $webService->__soapCall($method, array($method=>$parameters)); 

    if($debug) { // Return debug in XML 
     header('Content-type: text/xml'); 
     echo $webService->__getLastRequest(); 
     exit(); 
    } 
    else return $response; 
} 
Смежные вопросы