首页 > 解决方案 > 试图让soapclient添加xsi:type来请求

问题描述

所以我将数组项的字段传递给 Web 服务调用,请求和响应看起来不错,但我试图获取 Value 属性来告诉类型,所以这是我的字段:

$fields = array(
           "Password"=>'password',
           "entity"=>array(
                      "Name" =>"namehere",
                      "Id"=>'1234',
                      "Attributes"=>
                        array(
                            array(
                                "AttributeType"=>'SingleLineOfText',
                                "Key"=>'Key1',
                                "Value"=>'1',
                            ),
                            array(
                                "AttributeType"=>'SingleLineOfText',
                                "Key"=>'Key2',
                                "Value"=>'2',
                            ),
                            array(
                                "AttributeType"=>'DateAndTime',
                                "Key"=>'Key3',
                                "Value"=>'2016-09-16T00:00:00'
                            )

                        )
                    )
                );

所以我的请求是:

<?xml version="1.0" encoding="UTF-8"?>
 <SOAP-ENV:Envelope xmlns:SOAP- 
 ENV="http://schemas.xmlsoap.org/soap/envelope/" 
 xmlns:ns1="http://tempuri.org/"><SOAP-ENV:Body><ns1:Create> 
 <ns1:Password>password</ns1:Password><ns1:entity> 
 <ns1:Name>namehere</ns1:Name><ns1:Id>1234</ns1:Id><ns1:Attributes><ns1:Attribute> 
 <ns1:AttributeType>SingleLineOfText</ns1:AttributeType> 
 <ns1:Key>Key1</ns1:Key><ns1:Value>1</ns1:Value> 
 </ns1:Attribute><ns1:Attribute> 
 <ns1:AttributeType>SingleLineOfText</ns1:AttributeType> 
 <ns1:Key>Key2</ns1:Key><ns1:Value>2</ns1:Value> 
 </ns1:Attribute><ns1:Attribute> 
 <ns1:AttributeType>DateAndTime</ns1:AttributeType> 
 <ns1:Key>Key3</ns1:Key><ns1:Value>2016-09-16T00:00:00</ns1:Value></ns1:Attribute></ns1:Attributes></ns1:entity> 
 </ns1:Create></SOAP-ENV:Body></SOAP-ENV:Envelope>

所以你可以看到 <ns1:Value >1</ns1:Value> 但我需要它能够确定类型是什么样的 <Value xsi:type="xsd:string" >1</Value> 或< Value xsi:type="xsd:dateTime" >2016-09-16T00:00:00</Value> 如果它是一个日期字段,我试图循环并分配它,但它似乎不起作用,在这里是我尝试过的循环

foreach($fields['entity']['Attributes'] as $attribute){
                echo $attribute['Value'] = new SoapVar($attribute, XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema");
            }

标签: phparrayssoap

解决方案


推荐阅读