2014-01-14 132 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)); 

这个固定的问题,现在我正在从服务器的响应。