有问题制作php soap请求

时间:2013-05-08 20:59:00

标签: php soap

我很难理解如何正确创建soap请求,以及从服务器接收信息。

这是我需要连接的服务文档的链接。它显示了soap请求和响应格式。

https://www.team-intro.com/ws/distributorWS.asmx?op=GetReplicatedSite

查看他们的请求格式,我不确定我是如何将其传递给他们的服务器的。我已经google了一下,发现了几种发送请求的方法,但我一直在收到肥皂错误。以下是我最近的尝试。

<?php

//error_reporting(E_ALL);

//soap connect
$client = new SoapClient("http://www.team-intro.com/ws/distributorWS.asmx?WSDL");

$params = new SoapVar("<soap12:Header><AuthHeader Domain='THEDOMAIN' xmlns='http://www.prodogix.com/'><AuthorizationKey>MYAUTHKEY</AuthorizationKey></AuthHeader></soap12:Header><soap12:Body><GetReplicatedSite xmlns='http://www.prodogix.com/'><website>USERNAME</website></GetReplicatedSite></soap12:Body>", XSD_ANYXML);

//$info[
try {
    $result = $client->GetReplicatedSite($params);
}
catch (SoapFault $exception) {
  echo $exception;      
} 

print_r($result);

?>

我已经删除了输入值并将其替换为全部大写。

我也看到人们构建一个数组发送到soap服务器,但我似乎无法弄清楚如何传递authHeader中的域和xmlns之类的额外信息。

任何人都可以指出我正确的方向。

1 个答案:

答案 0 :(得分:1)

本教程最终得到了我需要的功能:

http://www.xillent.com/blog/codesharing/php-soap-call-for-wsdl-envelope-and-payload/

以下是代码如何在行动中发挥作用,因为其他任何人都有像我这样的问题。

<?php

//error_reporting(E_ALL);

class feedSoap extends SoapClient
{

    var $XMLStr = "";
    function setXMLStr ($value){$this->XMLStr = $value; }
    function getXMLStr(){return $this->XMLStr; }

    function __doRequest($request, $location, $action, $version) 
    {
        $request = $this -> XMLStr;
        $dom = new DOMDocument('1.0');

        try 
        {
            $dom->loadXML($request);
        } 
        catch (DOMException $e) 
        {
            die($e->code);
        }

        $request = $dom->saveXML();

        //doRequest
        return parent::__doRequest($request, $location, $action, $version);
    }

    function SoapClientCall($SOAPXML)
    {
        return $this -> setXMLStr ($SOAPXML);
    }
}

function soapCall($wsdlURL, $callFunction="", $XMLString)
{
    $client = new feedSoap($wsdlURL, array('trace' => true));
    $reply = $client-> SoapClientCall($XMLString);
    $client->__call("$callFunction", array(), array());

    return $client -> __getLastResponse();
}

    //i just copied the soap request they provided and dropped in my values (removed for stackoverflow
$XMLString= '<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>
    <AuthHeader Domain="THEDOMAIN" xmlns="http://www.prodogix.com/">
        <AuthorizationKey>MYKEY</AuthorizationKey>
    </AuthHeader>
</soap:Header>
<soap:Body>
    <GetReplicatedSite xmlns="http://www.prodogix.com/">
        <website>USERSNAMEe</website>
    </GetReplicatedSite>
</soap:Body>
</soap:Envelope>';

//set up the url to post the soap request to
$wsdlURL = 'https://www.team-intro.com/ws/distributorWS.asmx?WSDL';

    //make the call, and set the soap function that I'll be using
$result = soapCall($wsdlURL, $callFunction="GetReplicatedSite", $XMLString);

print_r($result);

?>