2013-03-27 159 views
2

我试图通过PEAR SOAP与API通信 我能够使用以下代码创建SOAP请求,但它不完整。pear soap xml请求

<?php 
    require_once 'SOAP/Client.php'; 

    $client = new SOAP_Client('https://api.mindbodyonline.com/0_5/SiteService.asmx? 
    wsdl',true); 

    $options = array('namespace' => 'http://schemas.xmlsoap.org/soap/envelope/', 
     'trace' => 1, 
     'SOAPAction' =>  'http://clients.mindbodyonline.com/api/0_5/GetLocations', 
     'Host'=> 'clients.mindbodyonline.com' 
    ); 

    $ret = $client->call( 
    'GetLocations', 
    array( 
    'Request'=>array('SourceCredentials' => array('SourceName'=>'*****','Password'=>'*****************','siteIDs'=> array('int'=>'23661'))),'XMLDetail'=>'Full','PageSize'=>'10','CurrentPageIndex'=>'0') 
    ,$options); 
    echo '<pre>'.htmlspecialchars($client->getLastRequest()).'</pre>'; 
    ?> 

这将导致以下SOAP请求:

POST /0_5/SiteService.asmx HTTP/1.0 
    User-Agent: PEAR-SOAP @[email protected] 
    Host: api.mindbodyonline.com 
    Content-Type: text/xml; charset=UTF-8 
    Content-Length: 464 
    SOAPAction: "http://clients.mindbodyonline.com/api/0_5/GetLocations" 
    Connection: close 

    <?xml version="1.0" encoding="UTF-8"?> 
    <SOAP-ENV:Envelope 
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
    xmlns:ns4="http://clients.mindbodyonline.com/api/0_5"> 
    <SOAP-ENV:Body> 
    <ns4:GetLocations> 
    <Request>Array</Request></ns4:GetLocations> 
    </SOAP-ENV:Body> 
    </SOAP-ENV:Envelope> 

当需要在以下格式:

POST http://clients.mindbodyonline.com/api/0_5/SiteService.asmx HTTP/1.1 
    Accept-Encoding: gzip,deflate 
    Content-Type: text/xml;charset=UTF-8 
    SOAPAction: "http://clients.mindbodyonline.com/api/0_5/GetLocations" 
    Host: clients.mindbodyonline.com 
    Content-Length: 795 

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <GetLocations xmlns="http://clients.mindbodyonline.com/api/0_5"> 
    <Request> 
     <SourceCredentials> 
      <SourceName>{SourceName}</SourceName> 
      <Password>{Password}</Password> 
      <SiteIDs> 
       <int>{SiteID}</int> 
      </SiteIDs> 
     </SourceCredentials> 
     <XMLDetail>Bare</XMLDetail> 
     <PageSize>10</PageSize> 
     <CurrentPageIndex>0</CurrentPageIndex> 
     <Fields> 
      <string>Locations.Name</string> 
      <string>Locations.City</string> 
     </Fields> 
    </Request> 
    </GetLocations> 
    </soapenv:Body> 
    </soapenv:Envelope> 

也许我需要一套新的眼睛来看待这个因为我已经玩了好几个小时了。任何意见或建议,将不胜感激。

WSDL链接:https://api.mindbodyonline.com/0_5/SiteService.asmx?wsdl

UPDATE: 使用SOAP_WSDL类而不是SOAP_Client I类是能够得到的XML SOAP请求略微更接近的requred版本。

<?php 
$WSDL=new SOAP_WSDL('https://api.mindbodyonline.com/0_5/SiteService.asmx?wsdl',array (trace=>1)); 


$proxy=$WSDL->getProxy(); 

$params = array('Request'=>array('SourceCredentials' => array('SourceName'=>'StudioSevaYoga','Password'=>'******','siteIDs'=>array('int'=>'23661')),'XMLDetail'=>'Full','PageSize'=>'10','CurrentPageIndex'=>'0')); 

$options=array('soapaction'=> 'http://clients.mindbodyonline.com/api/0_5/GetLocations'); 

$ret = $proxy->call("GetLocations",$params,$options); 

var_dump($ret); 
?> 

我再能拉这个XML SOAP信封出的var_dump:

["outgoing_payload"]=> 
     string(1118) "POST /0_5/SiteService.asmx HTTP/1.0 
User-Agent: PEAR-SOAP @[email protected] 
Host: api.mindbodyonline.com 
Content-Type: text/xml; charset=UTF-8 
Content-Length: 862 
SOAPAction: "http://clients.mindbodyonline.com/api/0_5/GetLocations" 
Connection: close 

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope 
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
<SOAP-ENV:Body> 
<GetLocations> 
<Request> 
<SourceCredentials> 
<SourceName xsi:type="xsd:string">StudioSevaYoga</SourceName> 
<Password xsi:type="xsd:string">*****</Password> 
<siteIDs> 
<int xsi:type="xsd:string">23661</int></siteIDs></SourceCredentials> 
<XMLDetail xsi:type="xsd:string">Full</XMLDetail> 
<PageSize xsi:type="xsd:string">10</PageSize> 
<CurrentPageIndex xsi:type="xsd:string">0</CurrentPageIndex></Request></GetLocations> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

我依然收到在此的var_dump错误也: 服务器无法处理请求。 ---没有将对象引用设置为对象的实例

如果有人愿意将问题拉出var_dump,可以在这里找到它: Pear Soap Request Page它似乎重复多次相同的信息。任何指导或意见,表示赞赏,谢谢。

我使用PEAR SOAP 0.9.1和PHP 5.2

+0

使用PHP的内置SOAP类。没有理由不使用它。 – cweiske 2013-03-27 12:21:58

+0

是的,我同意,不幸的是我的托管公司(fatcow)不支持PHP SOAP。他们只提供PEAR SOAP。 – 2013-03-27 22:16:20

+0

@DavidMcCarran:您可以自由接受您的答案:)(建议您将问题标记为已解决!) – hakre 2013-06-23 12:34:21

回答

2

我能够通过使用这里给出的建议,使这项工作:How to generate a PHP soap client code? ..... PEAR的SOAP generateProxyCode()方法提供所有适当的PEAR SOAP调用和参数将XML SOAP请求正确传递到服务器。我将以下php代码绑定到生成的服务代码上,并取得成功。

<?php 
require_once 'SOAP/Client.php'; 
require_once 'wsdl_proxy.php'; 

$proxyLocations= new WebService_Site_x0020_Service_Site_x0020_ServiceSoap(); 

$site=array('int'=>23661); 
$Request = array('SourceCredentials' => array('SourceName'=>'StudioSevaYoga','Password'=>'*********','SiteIDs'=>$site),'XMLDetail'=>'Full','PageSize'=>10,'CurrentPageIndex'=>0); 

$ret=$proxyLocations->GetLocations($Request); 
print_r($Request); 
var_dump($ret); 
?>