在PHP

2011-01-27 42 views
0

下實現SOAP 1.1是一個樣本SOAP 1.1請求和響應在PHP

POST /DEMOWebServices2.8/service.asmx HTTP/1.1 
Host: api.efxnow.com 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
SOAPAction: "https://api.efxnow.com/webservices2.3/DealRequestAtBest" 

<?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> 
    <Authenticator xmlns="https://api.efxnow.com/webservices2.3"> 
     <ApplicationName>string</ApplicationName> 
     <IPAddress>string</IPAddress> 
     <UserID>string</UserID> 
     <MachineName>string</MachineName> 
    </Authenticator> 
    </soap:Header> 
    <soap:Body> 
    <DealRequestAtBest xmlns="https://api.efxnow.com/webservices2.3"> 
     <UserID>string</UserID> 
     <PWD>string</PWD> 
     <Pair>string</Pair> 
    </DealRequestAtBest> 
    </soap:Body> 
</soap:Envelope> 

響應 -

HTTP/1.1 200 OK 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 

<?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:Body> 
    <DealRequestAtBestResponse xmlns="https://api.efxnow.com/webservices2.3"> 
     <DealRequestAtBestResult> 
     <Success>boolean</Success> 
     <ErrorDescription>string</ErrorDescription> 
     <ErrorNumber>int</ErrorNumber> 
     <Confirmation>string</Confirmation> 
     <ConfirmationNumber>string</ConfirmationNumber> 
     <Rate>double</Rate> 
     </DealRequestAtBestResult> 
    </DealRequestAtBestResponse> 
    </soap:Body> 
</soap:Envelope> 

我想知道如何進行請求以及如何處理響應,如果這必須在PHP中完成。我讀this,但我不知道如何__setSoapHeaders()__call()在我的情況下實施。提前致謝。

+0

看看教程http://devzone.zend.com/article/689 – 2011-01-27 09:28:21

回答

1

有一個用於PHP的SOAP庫,但對於簡單的交換,您可以考慮將XML請求主體構建爲字符串,並使用curl庫函數調度它。這是一個更低級的網絡api,至少我覺得它更易於使用。請注意,PHP需要編譯--with-curl [= DIR]。

<?php 
    $ch = curl_init(); 

    curl_setopt($ch, CURLOPT_URL, $uri); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    if ((bool)$proxy) { 
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Pragma:','Cache-Control:')); 
     curl_setopt($ch, CURLOPT_PROXY, $proxy); 
    } 
    // Apply the XML to our curl call 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data); 

    $out = curl_exec($ch); 
    curl_close($ch); 
?>