2014-01-14 131 views
1

情況:我必須將SOAP數據提交給遠程服務器。第一個請求是針對第二個請求所需的URL。返回的URL開始第二個請求,應該給我一個XML格式的一堆用戶數據的返回響應。PHP SOAP/CURL請求返回錯誤

問題:我收到第二個請求(數據)引用C#問題的服務器錯誤,我不知道該如何解決此問題。我試圖解決的錯誤是:

轉換無法完成,因爲提供的日期時間 沒有Kind屬性設置正確



這裏是我的編碼

PHP:

error_reporting(E_ALL); 

    $soapUrl = "https://domain.com/insidews/insidews.asmx"; 
    $soapUser = "*******"; 
    $soapPassword = "***************************"; 

    // xml post structure 

    $xml_post_string = '<?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:Header> 
          <inCredentials xmlns="http://inlogin.com/inSideWS"> 
           <busNo>****************</busNo> 
           <password>******************</password> 
          </inCredentials> 
          </soap:Header> 
          <soap:Body> 
          <GetURL xmlns="http://inlogin.com/inSideWS" /> 
          </soap:Body> 
         </soap:Envelope>'; 

     $headers = array(
        "Content-type: text/xml;charset=\"utf-8\"", 
        "Accept: text/xml", 
        "SOAPAction: http://inlogin.com/inSideWS/GetURL", 
        "Content-length: ".strlen($xml_post_string), 
       ); //SOAPAction: your op URL 

     $url = $soapUrl; 

     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
     curl_setopt($ch, CURLOPT_URL, $url); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); 
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
     curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
     curl_setopt($ch, CURLOPT_POST, true); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request 
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

     // converting 
     $response = curl_exec($ch); 
     if(curl_errno($ch)){ 
      echo 'Curl error: ' . curl_error($ch); 
     }    
     curl_close($ch); 
     //echo $response; 
     // converting 
     $response1 = str_replace("<soap:Body>","",$response); 
     $response2 = str_replace("</soap:Body>","",$response1); 
     $parser = new SimpleXmlElement($response2); 

     foreach($parser as $p) { 
      foreach($p as $n) { 
       $new_url = $n; 
      } 
     } 

$timezone = new DateTimeZone('UTC'); 
$dateone = '12/1/2013 00:00:00'; 
$startdate = new DateTime($dateone,$timezone); 
$startdate = $startdate->format('c'); 

echo "Start Date: ".$startdate."<br><br>"; 

$datetwo = '12/31/2013 23:59:59'; 
$enddate = new DateTime($datetwo,$timezone); 
$enddate = $enddate->format('c'); 

echo "End Date: ".$enddate."<br><br>"; 

echo "<font style='font-size: 18px; font-weight: bold; text-decoration: underline;'>FILE GET Destination URL:</font> ".$new_url."<br><br>"; 
$xml_post_string_2 = '<?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:Header> 
         <inCredentials xmlns="http://inlogin.com/inSideWS"> 
          <busNo>**************</busNo> 
          <password>*******************************</password> 
          <timeZoneName>UTC</timeZoneName> 
         </inCredentials> 
         </soap:Header> 
         <soap:Body> 
         <DataDownloadReport_Run xmlns="http://inlogin.com/inSideWS"> 
          <reportNo>16</reportNo> 
          <startDate>'.$startdate.'</startDate> 
          <endDate>'.$enddate.'</endDate> 
         </DataDownloadReport_Run> 
         </soap:Body> 
        </soap:Envelope>'; 

$new_headers = array(
        "Content-type: text/xml;charset=\"utf-8\"", 
        "Accept: text/xml", 
        "SOAPAction: http://inlogin.com/inSideWS/DataDownloadReport_Run", 
        "Content-length: ".strlen($xml_post_string_2), 
       ); 


// PHP cURL for https connection with auth 
$cho = curl_init(); 
curl_setopt($cho, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($cho, CURLOPT_SSL_VERIFYHOST, FALSE); 
curl_setopt($cho, CURLOPT_URL, $new_url); 
curl_setopt($cho, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); 
curl_setopt($cho, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($cho, CURLOPT_USERPWD, $soapUser.":".$soapPassword); 
curl_setopt($cho, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
curl_setopt($cho, CURLOPT_TIMEOUT, 10); 
curl_setopt($cho, CURLOPT_POST, true); 
curl_setopt($cho, CURLOPT_POSTFIELDS, $xml_post_string_2); // the SOAP request 
curl_setopt($cho, CURLOPT_HTTPHEADER, $new_headers); 

// converting 

$second_response = curl_exec($cho); 
// var_dump($second_response); 
// var_dump(curl_getinfo($cho)); 
// var_dump(curl_error($cho)); 
if(curl_errno($cho)){ 
    echo '<br><br>Curl error: ' . curl_error($cho); 
} 

//echo $second_response; 
print_r($second_response); 
curl_close($cho); 

// converting 
$new_response1 = str_replace("<soap:Body>","",$second_response); 
$new_response2 = str_replace("</soap:Body>","",$new_response1); 

// convertingc to XML 
$new_parser = simplexml_load_string($second_response); 

OUTPUT:

Start Date: 2013-12-01T00:00:00+00:00 

End Date: 2013-12-31T23:59:59+00:00 

FILE GET Destination URL: https://domain.com/inSideWS/inSideWS.asmx 

string(0) "" soap:ServerSystem.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentException: The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly. For example, when the Kind property is DateTimeKind.Local, the source time zone must be TimeZoneInfo.Local. Parameter name: sourceTimeZone at System.TimeZoneInfo.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags) at System.TimeZoneInfo.ConvertTimeFromUtc(DateTime dateTime, TimeZoneInfo destinationTimeZone) at UCN.Common.TimeZoneUtilities.ConvertUTCToTimeZone(DateTime time, String id) in d:\Agents\7\inContact\RC-Web.inSideWS\Sources\C#\Library\Common\Utilities\TimeZoneUtilities.cs:line 109 at inContact.DataDownload.Report.GetData(String dataSourceModule, Int32 reportType) in d:\Agents\7\inContact\RC-Web.inSideWS\Sources\C#\Library\inContact.DataDownload\Report.cs:line 128 at inContact.DataDownload.Report.RunReport(Nullable`1 busNo, Nullable`1 reportNo, Nullable`1 maximumRows, Nullable`1 startIndex, String orderColumn, Nullable`1 orderASC, String searchText, Nullable`1& rowCount) in d:\Agents\7\inContact\RC-Web.inSideWS\Sources\C#\Library\inContact.DataDownload\Report.cs:line 78 at inSideWebService.inSideWS.DataDownloadReport_Run(Int32 reportNo, DateTime startDate, DateTime endDate) --- End of inner exception stack trace --- 

回答

0

您是否嘗試過製作使用PHP的SOAP庫調用,它需要的大多數與SOAP相關的頭和錯綜複雜的照顧。文檔在這裏http://www.php.net/manual/en/book.soap.php

+0

從來沒有想過這件事(諷刺在文字形式中表現不佳)!說真的,儘管我看了我所有的選擇,並且使用CURL來傳遞我的SOAP是做我需要的最好的方式。順便說一句,你提供的鏈接不是一個有效的鏈接,你只是粘貼了我粘貼在我的代碼中的無意義鏈接。 – griff4594

+0

其實你可以去看看這個:http://www.halon.se/blog/making-phps-soap-client-asynchronous/。在裏面你會發現一個使用SoapClient創建請求的腳本,並且允許cURL在請求實際發生時接管。雖然該解決方案使用全局變量,但並不太好,但它確實顯示瞭如何使用cURL和簡化肥皂細節。 https://github.com/halonsecurity/sp-enduser/commit/4ef77895bd334bf04a1d90f035a317c4dd3838ef – SteveB

0

我已經解決了這個問題。將DateTime從PHP轉換爲C#應該可以工作,但由於某種原因,C#不接受ISO8601格式,就像它應該(正如我被告知的那樣)。所以,我只是改變了以下編碼日期:

$timezone = new DateTimeZone('UTC'); 
$time = time("00:00:00"); 
$dateone = '12/1/2013 00:00:00'; 
$startdate = date("Y-m-d", strtotime($dateone)) . 'T' . date("H:i:s", strtotime($dateone)); 

$datetwo = '12/31/2013 23:59:59'; 
$enddate = date("Y-m-d", strtotime($datetwo)) . 'T' . date("H:i:s", strtotime($datetwo)); 

這個固定的問題,現在我正在從服務器的響應。