php - 试图让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");
}
解决方案
推荐阅读
- algorithm - 找到一个有效的算法来得到一条线
- angular - 我可以动态加载 HTML 字符串作为组件模板并在 Angular 7 中完全编译它吗?
- unity3d - 我可以与其他 Unity 程序共享游戏画面吗?
- javascript - localStorage 存储 HTMLTextAreaElement 而不是值
- c# - 单击字符串时如何转换日历上的天数
- python-3.x - 如何用 3 个点定义一个平面,并在 3D 中绘制它?
- ruby - Ruby 对象分配类型强制
- matlab - 运行我的旧项目,但在较新的 matlab 版本上。使用 table() 方法弹出错误。有什么改变吗?
- java - 部署到heroku时在飞行途中访问被拒绝
- python-3.x - 从读取文件中删除换行符不起作用