PHP SOAP传递ComplexType参数

PHP SOAP传递ComplexType参数,php,soap,wsdl,soap-client,Php,Soap,Wsdl,Soap Client,我正在尝试从我的web应用程序调用SOAP服务。我创建了一个soap客户机,但调用soap方法GetCustomer时遇到了问题。我得到了以下SOAP错误 SOAP-ERROR: Encoding: object hasn't 'any' property. 我认为问题在于提供的参数。参数的类型是ComplexType,我不确定是否从PHP直接传递它。下面是来自GetCustomer方法的WSDL: <s:element name="GetCustomer"> <s:

我正在尝试从我的web应用程序调用SOAP服务。我创建了一个soap客户机,但调用soap方法GetCustomer时遇到了问题。我得到了以下SOAP错误

SOAP-ERROR: Encoding: object hasn't 'any' property.
我认为问题在于提供的参数。参数的类型是
ComplexType
,我不确定是否从PHP直接传递它。下面是来自GetCustomer方法的WSDL:

<s:element name="GetCustomer">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="user" type="s:string"/>
            <s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
            <s:element minOccurs="0" maxOccurs="1" name="xmlParams">
                <s:complexType mixed="true">
                    <s:sequence>
                        <s:any/>
                    </s:sequence>
                </s:complexType>
            </s:element>
        </s:sequence>
    </s:complexType>
</s:element>
试试这个:

$params = new StdClass();

$params->user = '****';

$params->password = '****';

$foo = new StdClass();

$foo->any = $yourXML;

$param->xmlParams = $foo;

$soap_options = array('trace' => 1, 'exceptions'  => 1 );

$wsdl = "https://web-icdev.saop.si/iCenter_WS/SAOPWS_Customer.asmx?WSDL";

$client = new SoapClient($wsdl, $soap_options);

try {
    $result = $client->GetCustomer($params);
    var_dump($result);
} 
catch (SOAPFault $f) {
    echo $f->getMessage();
}

您必须创建3个文件:

1.GetCustomer.class.php

<?php 
class GetCustomer{ 
var $user; 
var $password;
var $xmlParams;
}
<?php 
class xmlParams{ 
}
xmlParams=新的xmlParams();
$soap_options=array('trace'=>1,'exceptions'=>1);
$wsdl=”https://web-icdev.saop.si/iCenter_WS/SAOPWS_Customer.asmx?WSDL";
$client=newsoapclient($wsdl,$soap\u选项);
试一试{
$result=$client->GetCustomer($params);
var_dump($结果);
}捕获(SOAPFault$f){
echo$f->getMessage();
}
这就是我处理此类Web服务的方式,您也可以将GetCustomer和xmlParams类放在文件ServiceConsumer.php中,或者可能将两者放在同一个名为的文件中

但我更喜欢在不同的文件中使用all


致以最诚挚的问候。

您还可以使用相同的结构创建一个数组
$params=['user'=>'**'、'password'=>'**'、'xmlParams'=>[]
没有测试过这个显式示例,但为我做过类似的工作。
<?php 
class xmlParams{ 
}
 <?php
 include_once 'GetCustomer.class.php';
 include_once 'xmlParams.class.php';

 $objGetCust = new GetCustomer();
 $objGetCust->user = '****';
 $objGetCust->password = '****';
 $objGetCust->xmlParams = new xmlParams();

 $soap_options = array('trace' => 1, 'exceptions'  => 1 );
 $wsdl = "https://web-icdev.saop.si/iCenter_WS/SAOPWS_Customer.asmx?WSDL";
 $client = new SoapClient($wsdl, $soap_options);

 try {
    $result = $client->GetCustomer($params);
    var_dump($result);
 }catch (SOAPFault $f) {
        echo $f->getMessage();
 }