2

目前,我正在尝试与基于 SOAP 的摄像头系统进行交互,以将其绑定到其动作 API,以便我可以通过编程方式控制其灯何时亮起等等。但是,当我使用下面的代码时,它表示它无法绑定到服务并且似乎无法正确消化与 API 关联的 WSDL 文件,可以在此处找到:

http://www.axis.com/vapix/ws/action1/ActionService.wsdl

我的代码有什么问题,还是 WSDL 文件本身有问题?非常感谢您的帮助!预先,错误生成如下,在构造函数中实例化 SoapClient 对象时生成:

SOAP-ERROR:解析 WSDL:无法绑定到服务

<?php
/**
 * The purpose of this class is to act as a means to interface with a Vapix camera
 * using SOAP requests so that events may be broadcast to it.
 */

$vapix = new Vapix("http://www.axis.com/vapix/ws/action1/ActionService.wsdl",
                   "<http://camera.address.edu>",
                   "<username>", "<password>");
if ($vapix)
{
    echo "Connection to VAPIX successful!\n";
}
else
{
    echo "Connection to VAPIX unsuccessful!\n";
}

/**
 * The constructor takes in a WSDL address, the actual interfacing address of the
 * server we are connecting to, a username, and a password, and establishes the
 * SOAP client we need to interface with said address.
 *
 * @param   $wsdl       The WSDL specification for the service we are interacting with.
 * @param   $address    The actual server address we are interfacing with.
 * @param   $username   The username we need to access the server.
 * @param   $password   The password we need to access the server.
 *
 * @return              New Vapix object ready to interface with SOAP service.
 */
class Vapix
{
    // the soap client variable we will be using to store our Vapix connection
    private $soapClient;

    public function __construct($wsdl, $address, $username, $password)
    {
        try
        {
            $soapClient = new SoapClient($wsdl, array("soap_version" => SOAP_1_2));
        }
        catch (SoapFault $fault)
        {
            echo "Error instantiating SOAP object!\n";
            echo $fault->getMessage() . "\n";
        }

        // prepare SOAP headers
        $sh_param = array(
            "username" => $username,
            "password" => $password
        );

        $headers = new SoapHeader($address, "UserCredentials", $sh_param);


        // prepare SOAP client
        $soapClient->__setSoapHeaders(array($headers));
    }

    /**
     * This function is a generalized function used for calling a SOAP request to
     * whatever service or server we are linked up to (in this case a VAPIX camera)
     * so that other more specialized functions can derive from it. It will take in
     * the name of the function, as well as a list of parameters.
     *
     * @param   $funcName   The name of the function we want to call.
     * @param   $parameters The parameters for the function we want to call.
     *
     * @return  $info       Returns info from the call if successful, NULL otherwise.
     */
    public function callSoapFunction($funcName, $parameters)
    {
        try 
        { 
            $info = $soapClient->__call($funcName, array($parameters)); 
        } 
        catch (SoapFault $fault) 
        {   
            print( 
                "alert('Sorry, blah returned the following ERROR: " . $fault->faultcode . "-" .
                    $fault->faultstring.". We will now take you back to our home page.'); 
                window.location = 'main.php';"
            ); 

            return NULL;
        }

        if ($error == 0) 
        {        
            return $info;
        }
    }
}
?>
4

1 回答 1

4

至少提供的 WSDL 文件在块<service>之后的 wsdl-definition 末尾没有 -area <binding>。但是这个缺失<service>的 -block 是必需的,因为它包含具体的服务特定信息(例如,它的 web 服务 URL/端点在此处列出)。

于 2013-06-11T15:43:03.987 回答