Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP SOAP响应包含一个具有不同XMLN的属性,显示为空_Php_Xml_Web Services_Soap_Soap Client - Fatal编程技术网

PHP SOAP响应包含一个具有不同XMLN的属性,显示为空

PHP SOAP响应包含一个具有不同XMLN的属性,显示为空,php,xml,web-services,soap,soap-client,Php,Xml,Web Services,Soap,Soap Client,在过去的几天里,我一直在为以下问题绞尽脑汁: 我使用以下代码向SOAP服务发送请求: $client = new SoapClient(WSDL, array('soap_version'=> SOAP_1_2, 'trace' => 1)); $result = $client->getHumanResourceID(array( 'cCode' => CLIENT_CODE, 'hFilter' => array('deltaDatum' =

在过去的几天里,我一直在为以下问题绞尽脑汁: 我使用以下代码向SOAP服务发送请求:

$client = new SoapClient(WSDL,  array('soap_version'=> SOAP_1_2, 'trace' => 1));

$result = $client->getHumanResourceID(array(
    'cCode' => CLIENT_CODE,
    'hFilter' => array('deltaDatum' => '2010-01-01T00:00:00-00:00')
));
部分变量转储($result)显示:

EntityType的对象中发生了一些奇怪的事情,它包含一个具有idValue和idOwner的对象。IdValue应包含其他属性或字段。 在这一刻,我不知道应该添加或修改什么来接收这些值

原始SOAP响应的一部分:

<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <getHumanResourceIDResponse xmlns="http://soapWeb.org/">   
            <getHumanResourceIDResult>
                <EntityIdType idOwner="internal">
                    <IdValue xmlns="http://ns.hr-xml.org/2007-04-15">5429</IdValue>
                </EntityIdType>
            </getHumanResourceIDResult>
        </getHumanResourceIDResponse>
    </soap:Body>
</soap:Envelope>

5429
我注意到的是IdValue字段中的xmlns,我可以想象返回的对象为null,因为没有包含名称空间

任何帮助和建议都将不胜感激

  • 斯特凡

由于响应包含多个名称空间,因此需要使用(如果使用SimpleXML,对于DOM,也有类似的方法)函数读取所有值

$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <getHumanResourceIDResponse xmlns="http://soapWeb.org/">   
            <getHumanResourceIDResult>
                <EntityIdType idOwner="internal">
                    <IdValue xmlns="http://ns.hr-xml.org/2007-04-15">5429</IdValue>
                </EntityIdType>
            </getHumanResourceIDResult>
        </getHumanResourceIDResponse>
    </soap:Body>
</soap:Envelope>
XML;

$xml = simplexml_load_string( $xml );

$xml->registerXPathNamespace( 's', 'http://soapWeb.org/' );

$xpath = $xml->xpath( '//s:getHumanResourceIDResponse' );

foreach( $xpath as $node ) {
    $idValue = ( string ) $node->getHumanResourceIDResult->EntityIdType->IdValue;
    $idOwner = ( string ) $node->getHumanResourceIDResult->EntityIdType[ 'idOwner' ];

    echo 'IdValue : ' . $idValue . '<br />';
    echo 'IdOwner : ' . $idOwner;
}
$xml=getHumanResourceIDResult->EntityIdType->IdValue;
$idOwner=(字符串)$node->getHumanResourceIDResult->EntityIdType['idOwner'];
回显“IdValue:”$idValue。”
; 回显“IdOwner:”$我的主人; }

希望这能有所帮助。

WSDL是否需要更多参数或任何条件?我是否可以根据WSDL自身看到这一点?在那里我找到了标记wsdl:定义、类型和多条消息。在wsdl中,您可以找到服务所期望的输入参数、条件等。我在这里复制了wsdl:您能给我一些提示吗?有两个不同的函数调用,名称相同。一个在
sedisWebSoap
中,另一个在
sedisWebSoap12
中,您使用哪一个
$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <getHumanResourceIDResponse xmlns="http://soapWeb.org/">   
            <getHumanResourceIDResult>
                <EntityIdType idOwner="internal">
                    <IdValue xmlns="http://ns.hr-xml.org/2007-04-15">5429</IdValue>
                </EntityIdType>
            </getHumanResourceIDResult>
        </getHumanResourceIDResponse>
    </soap:Body>
</soap:Envelope>
XML;

$xml = simplexml_load_string( $xml );

$xml->registerXPathNamespace( 's', 'http://soapWeb.org/' );

$xpath = $xml->xpath( '//s:getHumanResourceIDResponse' );

foreach( $xpath as $node ) {
    $idValue = ( string ) $node->getHumanResourceIDResult->EntityIdType->IdValue;
    $idOwner = ( string ) $node->getHumanResourceIDResult->EntityIdType[ 'idOwner' ];

    echo 'IdValue : ' . $idValue . '<br />';
    echo 'IdOwner : ' . $idOwner;
}