简体   繁体   English

PHP SOAP客户端需要在函数调用中进行身份验证

[英]PHP SOAP client with authentication required in function call

I'm completely new to using SOAP, and am looking to create some client software connecting to an existing service that provides no resources/demo's for PHP. 我对使用SOAP完全陌生,并且希望创建一些客户端软件来连接到现有服务,该服务不为PHP提供资源/演示。 I'd like to determine if I'm doing something wrong with my code, or if it's perhaps a systems issue (I've created an Apache2.4/PHP7.2.7 on Windows Server 2008 R2 environment). 我想确定我的代码是否做错了,或者这可能是系统问题(我已经在Windows Server 2008 R2环境中创建了Apache2.4 / PHP7.2.7)。

I've already spent hours going testing things and going through the numerous other SOAP/PHP topics on here, and the point of distinction I've where I'm making my own thread is that the authentication is required in the SoapClient call but rather the $client->__soapCall(function, params)call. 我已经花了几个小时来测试事物,并在这里遍历其他许多SOAP / PHP主题,而我要编写自己的线程的区别是,在SoapClient调用中需要身份验证,而实际上是$ client-> __ soapCall(function,params)调用。

First this is what I have in PHP. 首先,这就是我在PHP中所拥有的。

$customerArray = array( $cust1 , $cust2, $cust3 );
$credentials = array(
 'login' => $login,
 'password' => $password,
);  

try{
    $client = new SoapClient($soaplink);//, $credentials);
} catch (Exception $e) {
    echo "<h2>Exception Error in SoapClient</h2>";
    echo $e->getMessage();
}   
var_dump($client->__getFunctions());

try{
    $response = $client->__soapCall("getCustomers", array($customerArray, $credentials));
}catch (Exception $e) {
    echo "<h2>Exception Error in soapCall</h2>";
    echo $e->getMessage();
}   
var_dump($response());

The first try block completes, with or without the credentials array. 第一个try块完成(带有或不带有凭据数组)。 The second try block when trying to call the function returns the exception "looks like we got no XML document". 尝试调用该函数时,第二个try块返回异常“看起来我们没有XML文档”。

The SOAP service provided demo XML files, the one for this function looks like this: SOAP服务提供了演示XML文件,用于此功能的文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <ns1:getCustomers 
            soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
            xmlns:ns1="http://ws.praxedo.com/2008_07_01/customermodel/service"
        >
            <in0 
                soapenc:arrayType="soapenc:string[3]" 
                xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
            >
                <in0 xsi:type="soapenc:string">CUSTOMER001</in0>
                <in0 xsi:type="soapenc:string">CUSTOMER002</in0>
                <in0 xsi:type="soapenc:string">CUSTOMER003</in0>
            </in0>
            <in1 
                xsi:type="soapenc:string" 
                xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
            >
                login|password
            </in1>
        </ns1:getCustomers>
    </soapenv:Body>
</soapenv:Envelope>

WSDL files were also provided, it could be I need to load from that but following a demo to do so provided no results. 还提供了WSDL文件,可能是我需要从中加载文件,但在进行演示后未提供任何结果。 I could include some of the WSDL here but I believe the XML provides all the relevant details? 我可以在此处包括一些WSDL,但我相信XML提供了所有相关细节?

So can anyone see if there's something I'm doing wrong here in my PHP, or should what I'm doing work and I need to look into the client Apache/SOAP server side? 因此,谁能在我的PHP中看到我在做错什么,还是应该在做我正在做的事情,而我需要研究客户端Apache / SOAP服务器端?

I strongly advise you to use a WSDL to PHP generator as it'll allow you to construct the request without any wondering (depending on your PHP knowledge level at the least). 我强烈建议您使用WSDL to PHP生成器,因为它将允许您毫无疑问地构造请求(至少取决于您的PHP知识水平)。

Try the PackageGenerator project. 尝试PackageGenerator项目。 You have to install it then generate the PHP SDK. 您必须先安装它,然后生成PHP SDK。 The generated SDK uses composer and contains all the classes and methods required to send any request. 生成的SDK使用composer,并包含发送任何请求所需的所有类和方法。 Take a look to the auto-generated tutorial.php file which is a good starting point. 看一下自动生成的tutorial.php文件,这是一个很好的起点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM