2017-06-14 132 views
0

我在輕微的損失,沒有觸及永遠的肥皂腳本和四處張望stackoverflow和谷歌只是混淆更多的事情。 PHP.net的例子也顯得過時了。使用php發佈SOAP請求

該SOAP請求應該發佈到非WSDL url。 https://some.soapurl.com/provided

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:cam="http://kamp.gw.com/kamp"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <cam:setRolesUpdatedRequest> 
     <cam:orgCode>username</cam:orgCode> 
     <cam:password>password</cam:password> 
     <cam:emails> 
      <cam:email>[email protected]</cam:email> 
      <cam:email>[email protected]</cam:email> 
      <cam:email>[email protected]</cam:email> 
     </cam:emails> 
     <cam:updateAllUsers>false</cam:updateAllUsers> 
     </cam:setRolesUpdatedRequest> 
    </soapenv:Body> 
</soapenv:Envelope> 

只需運行該代碼段返回一個200 OK標頭,這是很好的。

try { 
     $client = new SoapClient("https://abc.kamp.group.com/axis/services/KampService/setRolesUpdated"); 
    } 
catch(Exception $e) 
    { 
     $e->getMessage(); 
    } 

我期待得到的迴應是應該看起來像

<?xml version='1.0' encoding='UTF-8'?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Body> 
     <ns1:returnStatus xmlns:ns1="http://kamp.gw.com/kamp"> 
      <ns1:type>S</ns1:type> 
      <ns1:desc>Successful</ns1:desc> 
     </ns1:returnStatus> 
    </soapenv:Body> 
</soapenv:Envelope> 

編輯:

我試圖捲曲版本直接發佈XML字符串。

$post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cam="http://kamp.gw.com/kamp"> 
        <soapenv:Header/> 
        <soapenv:Body> 
         <cam:setRolesUpdatedRequest> 
         <cam:orgCode>username</cam:orgCode> 
         <cam:password>password</cam:password> 
         <cam:emails> 
          <cam:email>[email protected]</cam:email> 
          <cam:email>[email protected]</cam:email> 
          <cam:email>[email protected]</cam:email> 
         </cam:emails> 
         <cam:updateAllUsers>false</cam:updateAllUsers> 
         </cam:setRolesUpdatedRequest> 
        </soapenv:Body> 
       </soapenv:Envelope>'; 

$user = "username"; 
$password = "password"; 


$headers = array(    
    "Content-type: text/xml;charset=\"utf-8\"", 
    "Accept: text/xml", 
    "Cache-Control: no-cache", 
    "Pragma: no-cache", 
    "SOAPAction: \"run\"", 
    "Content-length: ".strlen($xml), 
); 

$soap_do = curl_init(); 
curl_setopt($soap_do, CURLOPT_URL,   "https://abc.kamp.group.com/axis/services/KampService/setRolesUpdated"); 
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 100000); 
curl_setopt($soap_do, CURLOPT_TIMEOUT,  100000); 
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($soap_do, CURLOPT_POST,   true); 
curl_setopt($soap_do, CURLOPT_POSTFIELDS,  $post_string); 
curl_setopt($soap_do, CURLOPT_HTTPHEADER,  $headers); //array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($post_string)) 
curl_setopt($soap_do, CURLOPT_USERPWD, $user . ":" . $password); 

$result = curl_exec($soap_do); 
$err = curl_error($soap_do); 

var_dump($result); 
echo "<br /><br />"; 
var_dump($err); 

但不幸的是,結果是

bool(false) 

string(74) "Failed connect to abc.kamp.group.com:443; Connection timed out" 

而且我不能肯定,如果這是我的錯或Web服務的故障。即使我連接超時,返回的頭仍然是200 Ok。

回答

0

首先檢查SOAP服務url和訪問憑證是否正常。使用SoapUI或類似的工具來創建一個獨立於PHP SoapClient代碼的請求。

同時檢查進行調用時是否存在任何IP地址限制,如果有,請創建/請求您提出請求的IP地址的例外。

如果一切都檢查,請使用php.net SoapClient示例進行簡單調用並構建您的腳本邏輯。

<?php 
$client = new SoapClient('http://soap.amazon.com/schemas3/AmazonWebServices.wsdl'); 
var_dump($client->__getFunctions()); 
?> 

0

忘了我是一個代理之後,一旦到代理服務器一切工作只是罰款我指出捲曲。