- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
这个问题涉及在 PHP SOAP 客户端中使用 SoapParam 和 SoapVar 来处理重复元素,其中请求不能被构造为关联数组。更具体地说,它解决了将 SoapParam/SoapVar 用于复杂元素的困难。
我有我正在尝试修改的工作代码,以允许 SOAP 请求中的重复元素。
工作代码如下,并正确返回单个 consignmentID 的详细信息。
$oClient = new SoapClient($wsdlFilespec, $arguments);
$parameters = array(
'header' => array(
'source' => $_POST['source'],
'accountNo' => $_POST['accountNo'],
'userAccessKey' => $connection['userAccessKey']
),
'consignmentId' => $_POST['consignmentId']
);
$request = array('parameters' => $parameters);
$result = $oClient->__soapCall($operation, $request);
我现在需要能够传入多个 consignmentId,显然关联数组对此不起作用。所以我一直在尝试使用SoapParam和SoapVar;顺便说一句,没有找到很多关于这些的文档或示例。
我尝试了以下方法:
$header = array(
new SoapParam((string)$_POST['source'], 'source'),
new SoapParam((int)$_POST['accountNo'], 'accountNo'),
new SoapParam((string)$connection['userAccessKey'], 'userAccessKey')
);
$parameters = array(
new SoapParam($header, 'header'),
new SoapParam((string)'PDH44109', 'consignmentId'),
new SoapParam((string)'PDH44110', 'consignmentId')
);
$request = array('parameters' => $parameters);
这给出:SOAP-ERROR:编码:对象没有“ header ”属性。
我也尝试过使用 SoapVar,希望强制使用复杂类型的“header”,如下所示:
$header = array(
new SoapParam((string)$_POST['source'], 'source'),
new SoapParam((int)$_POST['accountNo'], 'accountNo'),
new SoapParam((string)$connection['userAccessKey'], 'userAccessKey')
);
$headerVar = new SoapVar($header, SOAP_ENC_OBJECT, 'TransactionHeaderType',
"http://myexpress/Common/actions/externals/Consignment/v1");
$parameters = array(
new SoapParam($headerVar, 'header'),
new SoapParam((string)'PDH44109', 'consignmentId'),
new SoapParam((string)'PDH44110', 'consignmentId')
);
$request = array('parameters' => $parameters);
这还会给出:SOAP-ERROR:编码:对象没有“ header ”属性。
我还尝试了最后一行代码的变体,例如:
$request = array('parameters' => $parameters);
$request = array($parameters);
$request = $parameters;
作为实验,我临时为 $header 分配了一个字符串,然后能够在调用 __doRequest 之前查看 __soapCall 生成的 XML,发现它包含以下内容:
<SOAPENV:Body><ns1:getConsignmentDetailRequest/>
<consignmentId>PDH44109</consignmentId><consignmentId>PDH44110</consignmentId>
</SOAP-ENV:Body>
您可以看到已正确包含多批 cargo ——该部分似乎已解决——但完全省略了“header”(复杂类型)。
非常感谢任何帮助!我是一个真正的初学者,并且在这上面花了一天多的时间。我对 SoapVar 非常不确定,例如,合适的参数是什么。
也许“header”的输入有问题?下面提供了一些 wsdl 摘录以供引用。
------
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://my.com.au/ESB/Services/Concrete/External/Services/v1"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns0="http://myexpress/Common/actions/externals/Consignment/v1"
xmlns:ns1="http://myexpress/Common/externals/Faultv1" xmlns:ns2="http://myexpress/Common/actions/externals/FreightCalculation/v1"
xmlns:ns3="http://myexpress/Common/Primitives/v1" xmlns:ns4="http://myexpress/Common/FreightProcessing/v1"
xmlns:ns5="http://myexpress/Common/Account/v1" xmlns:ns6="http://myexpress/Common/Imaging/v1" name="Untitled"
targetNamespace="http://my.com.au/ESB/Services/Concrete/External/Services/v1">
------
<xsd:schema xmlns="http://myexpress/Common/Primitives/v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:acc="http://myexpress/Common/Account/v1" targetNamespace="http://myexpress/Common/Primitives/v1" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:import namespace="http://myexpress/Common/Account/v1"/>
.
.
.
.
<xsd:complexType name="TransactionHeaderType">
<xsd:sequence>
<xsd:element name="source" type="xsd:string"/>
<xsd:element name="accountNo" type="xsd:integer"/>
<xsd:element name="userAccessKey" type="xsd:string"/>
<xsd:element name="userId" type="ns3:userIdType" minOccurs="0"/>
<xsd:element name="transactionId" type="ns3:transactionIdType" minOccurs="0"/>
<xsd:element name="transactionDatetime" type="xsd:dateTime" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
------
<xsd:simpleType name="consignmentIdType">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="30"/>
</xsd:restriction>
</xsd:simpleType>
------
<xsd:element name="getConsignmentDetailRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="header" type="prim:TransactionHeaderType"/>
<xsd:element name="consignmentId" type="ns0:consignmentIdType" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
------
最佳答案
在与 SoapVar 和 SoapParam 折腾了好几天却一无所获之后,找到了以下简单的解决方案:
$oClient = new SoapClient($wsdlFilespec, $arguments);
$parameters = array(
'header' => array(
'source' => $_POST['source'],
'accountNo' => $_POST['accountNo'],
'userAccessKey' => $connection['userAccessKey']
),
'consignmentId' => array('PDH44109', 'PDH44110')
);
$request = array('parameters' => $parameters);
$result = $oClient->__soapCall($operation, $request);
关于复杂类型的 PHP SoapParam/SoapVar 给出 "object hasn' t 'xxx' 属性”- 重复元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4666994/
我正在尝试使用函数“SoapVar”发布我的 SoapHeader。当我打印变量的信息时,我可以看到发布的数据不正确: SoapHeader Object ( [namespace] => h
有没有人知道如何向 SoapVar 对象添加属性?看起来这很简单,但我无法接受/工作。 我查看了 PHP 文档和以下 stackoverflow 问题: Documentation on SoapVa
我正在尝试向 soap 请求添加一些属性。 PHP.net ( http://php.net/manual/en/soapvar.soapvar.php ) 和 here 上评分最高的评论和 here
我想创建具有如下属性的 soapVars: yyy 这是否可以通过 SoapVar 构造函数实现,但不使用 XSD_ANYXML 和原始 xml 字符串? 最佳答案 最好的方法是: 结果是: yyy
我需要在我的 SOAP 请求中包含此节点(使用 1.1): ricky@email.net password 所以我有以下 PHP: $client = new SoapClient("ht
在 PHP 中,我们有 SoapVar 和 SoapParam 类。我已经困惑很久了,因为在 php.net 上没有关于它们的合适文档。 今天我惊讶地发现这些行将在 XML 输入中产生完全相同的结果:
如何向 PHP SoapVar 对象添加属性? (PHP5、SoapClient、SoapVar) 我有一个 SOAP 客户端请求情况,其中有重复的部分(“答案”),每个部分都有一个问题和选择。这都是
我的目标是能够创建一个可以包含如下项目的 soap 请求: IAG Group Ticket # 但是,我能想到的 soapvar 和 soapparam 的每一种组合
我必须使用 SoapClient 对象调用 SOAP Web 服务。其中一个参数必须包含 CDATA 部分中包含的一些 XML,如下所示: baz]]> 注意节点命名空间,这是我痛苦的根源......
谁能解释一下如何在 php 中使用 soapvar 为 anytype 参数分配类型?
这个问题涉及在 PHP SOAP 客户端中使用 SoapParam 和 SoapVar 来处理重复元素,其中请求不能被构造为关联数组。更具体地说,它解决了将 SoapParam/SoapVar 用于复
我是一名优秀的程序员,十分优秀!