curl
  • wsdl
  • soap-client
  • 2014-01-12 84 views 0 likes 
    0

    的XMLSOAP請求還給響應:發生錯誤生成XML文檔

    $xml = "<?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> 
        <GetProviderTrades xmlns='ZuluTrade.WebServices'> 
         <providerId>128391</providerId> 
         <currencyIds> 
        <string>EURUSD</string> 
        <string>USDCAD</string> 
         </currencyIds> 
         <fromDateStr>1986-08-27T09:00:00</fromDateStr> 
         <toDateStr>2014-01-12T09:00:00</toDateStr> 
         <validTrades>true</validTrades> 
         <lotSize>Standard</lotSize> 
         <start>0</start> 
         <length>20</length> 
         <sortBy>dc</sortBy> 
         <sortAscending>false</sortAscending> 
        </GetProviderTrades> 
        </soap12:Body> 
    </soap12:Envelope>"; 
    

    請求函數

    function http_post ($url, $xml) 
    { 
    date_default_timezone_set('America/New_York'); 
    $post_string = $xml; 
    
    $soap_do = curl_init(); 
    curl_setopt($soap_do, CURLOPT_URL,   $url); 
    curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10); 
    curl_setopt($soap_do, CURLOPT_TIMEOUT,  10); 
    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,  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); 
    
    return $result; 
    } 
    

    呼叫

    $postRequest = http_post('http://www.zulutrade.com/WebServices/Performance.asmx?op=GetProviderTrades',$xml); 
    

    充分反應

    soap:ServerServer was unable to process request. ---> There was an error generating the XML document. ---> <>f__AnonymousType55`2[System.Int32,Z.T[]] cannot be serialized because it does not have a parameterless constructor. 
    

    的WSDL http://www.zulutrade.com/WebServices/Performance.asmx?WSDL

    有沒有發現什麼毛病我在做什麼,什麼想法?

    回答

    0
     <currencyIds> 
    <string>EURUSD</string> 
    <string>USDCAD</string> 
        </currencyIds> 
    

    根據你的wsdl,它是ArrayOfInt而不是ArrayOfString。

    <s:element name="GetProviderTrades"> 
        <s:complexType> 
        <s:sequence> 
        <s:element minOccurs="1" maxOccurs="1" name="providerId" type="s:int" /> 
        <s:element minOccurs="0" maxOccurs="1" name="currencyIds" type="tns:ArrayOfInt" /> 
        <s:element minOccurs="0" maxOccurs="1" name="fromDateStr" type="s:string" /> 
        <s:element minOccurs="0" maxOccurs="1" name="toDateStr" type="s:string" /> 
        <s:element minOccurs="1" maxOccurs="1" name="validTrades" type="s:boolean" /> 
        <s:element minOccurs="1" maxOccurs="1" name="lotSize" type="tns:LotSize" /> 
        <s:element minOccurs="1" maxOccurs="1" name="start" type="s:int" /> 
        <s:element minOccurs="1" maxOccurs="1" name="length" type="s:int" /> 
        <s:element minOccurs="0" maxOccurs="1" name="sortBy" type="s:string" /> 
        <s:element minOccurs="1" maxOccurs="1" name="sortAscending" type="s:boolean" /> 
        </s:sequence> 
        </s:complexType> 
    </s:element> 
    

    而且ArrayOfInt是,

    <s:complexType name="ArrayOfInt"> 
    <s:sequence> 
        <s:element minOccurs="0" maxOccurs="unbounded" name="int" type="s:int" /> 
    </s:sequence> 
    </s:complexType> 
    

    所以,你的請求XML應該是這樣的,

    <currencyIds> 
    <int>11</int> 
    <int>22</int> 
        </currencyIds> 
    
    相關問題