2

我正在尝试通过 PEAR SOAP 与 API 通信我能够使用以下代码创建 SOAP 请求,但它并不完整。

    <?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 @version@-beta
    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

更新:通过使用 SOAP_WSDL 类而不是 SOAP_Client 类,我能够使 XML SOAP 请求稍微接近所需版本的请求。

<?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 ENVELOPE 从 var_dump 中拉出来:

["outgoing_payload"]=>
      string(1118) "POST /0_5/SiteService.asmx HTTP/1.0
User-Agent: PEAR-SOAP @version@-beta
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

4

1 回答 1

2

I was able to make this work by using the advice given here:How to generate a PHP soap client code?..... The PEAR SOAP generateProxyCode() method provided all the proper PEAR SOAP calls and arguments to pass the XML SOAP request to the server correctly. I tied the following php code to the generated services code with success.

<?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);
?>
于 2013-04-08T03:48:18.653 回答