繁体   English   中英

PHP SOAP / CURL请求返回错误

[英]PHP SOAP/CURL Request returns error

情况:我必须将SOAP数据提交到远程服务器。 第一个请求用于第二个请求所需的URL。 返回的URL启动第二个请求,并且应该以XML格式给我一堆用户数据的返回响应。

问题:我在第二个请求(数据)上从服务器返回了一个错误,该错误指的是C#问题,我不知道该如何解决。 我正在尝试解决的错误是:

由于提供的DateTime没有正确设置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 ---

您是否尝试过使用PHP的肥皂库进行调用,但是它可以处理与SOAP相关的大多数标头和复杂性。 该文档位于http://www.php.net/manual/zh/book.soap.php

我已经解决了这个问题。 将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));

这解决了问题,现在我从服务器得到响应。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM