通过PHP使用具有相同名称

时间:2015-11-12 15:31:39

标签: php axapta x++ dynamics-ax-2009

我正在尝试通过PHP在AX 2009中使用Web服务,之前没有任何问题就完成了,这次我需要生成一个带有多个同名密钥的XML,对于更新部分我找到了一个可行的解决方案,但我需要在更新之前选择记录,然后失败。

我收到此错误消息:“客户端SOAP-ERROR:编码:对象没有'DataSourceName'属性”

这是请求的XML:

  <?xml version="1.0" encoding="UTF-8" ?> 
- <xsd:schema targetNamespace="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria" xmlns="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xsd:element name="QueryCriteria" type="QueryCriteria" /> 
- <xsd:complexType name="QueryCriteria">
- <xsd:sequence minOccurs="1" maxOccurs="unbounded">
  <xsd:element name="CriteriaElement" type="CriteriaElement" /> 
  </xsd:sequence>
  </xsd:complexType>
- <xsd:complexType name="CriteriaElement">
- <xsd:sequence>
  <xsd:element name="DataSourceName" type="xsd:string" /> 
  <xsd:element name="FieldName" type="xsd:string" /> 
  <xsd:element name="Operator" type="Operator" /> 
  <xsd:element name="Value1" type="xsd:string" /> 
  <xsd:element name="Value2" type="xsd:string" minOccurs="0" /> 
  </xsd:sequence>
  </xsd:complexType>
- <xsd:simpleType name="Operator">
- <xsd:restriction base="xsd:string">
  <xsd:enumeration value="Equal" /> 
  <xsd:enumeration value="NotEqual" /> 
  <xsd:enumeration value="Greater" /> 
  <xsd:enumeration value="GreaterOrEqual" /> 
  <xsd:enumeration value="Less" /> 
  <xsd:enumeration value="LessOrEqual" /> 
  <xsd:enumeration value="Range" /> 
  </xsd:restriction>
  </xsd:simpleType>
  </xsd:schema>

这是我试图使用它的PHP代码:

  $CriteriaElement1 = new stdClass;
  $CriteriaElement1->DataSourceName = 'CustLoadListTrans';
  $CriteriaElement1->FieldName      = 'RefRecIdTrans';
  $CriteriaElement1->Operator       = 'Equal';
  $CriteriaElement1->Value1         = $refRecIdTrans;

  $CriteriaElement2 = new stdClass;
  $CriteriaElement2->DataSourceName = 'CustLoadListTrans';
  $CriteriaElement2->FieldName      = 'RefRecIdJour';
  $CriteriaElement2->Operator       = 'Equal';
  $CriteriaElement2->Value1         = $refRecIdJour;

  $CriteriaElement3 = new stdClass;
  $CriteriaElement3->DataSourceName = 'CustLoadListTrans';
  $CriteriaElement3->FieldName      = 'CustLoadListId';
  $CriteriaElement3->Operator       = 'Equal';
  $CriteriaElement3->Value1         = $custLoadListId;

  $QueryCriteria = new stdClass;

  $QueryCriteria->QueryCriteria->CriteriaElement[] = $CriteriaElement1;
  $QueryCriteria->QueryCriteria->CriteriaElement[] = $CriteriaElement2;
  $QueryCriteria->QueryCriteria->CriteriaElement[] = $CriteriaElement3;

如果我用这一行替换最后三行:

  $QueryCriteria->QueryCriteria->CriteriaElement = $CriteriaElement1;

它可以工作,但记录只能由一个关键字段选择。

我正在使用PHP版本5.1.6

1 个答案:

答案 0 :(得分:3)

这样可以解决问题:

$nameSpace = 'http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria'; 

$CriteriaElement1 = array(); 
$CriteriaElement1[] = new SoapVar('CustLoadListTrans', XSD_STRING, null, $nameSpace, 'DataSourceName', $nameSpace); 
$CriteriaElement1[] = new SoapVar('RefRecIdTrans', XSD_STRING, null, $nameSpace, 'FieldName', $nameSpace); 
$CriteriaElement1[] = new SoapVar('Equal', XSD_STRING, null, $nameSpace, 'Operator', $nameSpace); 
$CriteriaElement1[] = new SoapVar($refRecIdTrans, XSD_STRING, null, $nameSpace, 'Value1', $nameSpace); 
$CriteriaElement1[] = new SoapVar('', XSD_STRING, null, $nameSpace, 'Value2', $nameSpace); 
$CriteriaElementOne = new SoapVar($CriteriaElement1, SOAP_ENC_OBJECT, null, $nameSpace, 'CriteriaElement', $nameSpace ); 

$CriteriaElement2 = array(); 
$CriteriaElement2[] = new SoapVar('CustLoadListTrans', XSD_STRING, null, $nameSpace, 'DataSourceName', $nameSpace); 
$CriteriaElement2[] = new SoapVar('RefRecIdJour', XSD_STRING, null, $nameSpace, 'FieldName', $nameSpace); 
$CriteriaElement2[] = new SoapVar('Equal', XSD_STRING, null, $nameSpace, 'Operator', $nameSpace); 
$CriteriaElement2[] = new SoapVar($refRecIdJour, XSD_STRING, null, $nameSpace, 'Value1', $nameSpace); 
$CriteriaElement2[] = new SoapVar('', XSD_STRING, null, $nameSpace, 'Value2', $nameSpace); 
$CriteriaElementTwo = new SoapVar($CriteriaElement2, SOAP_ENC_OBJECT, null, $nameSpace, 'CriteriaElement', $nameSpace ); 

$CriteriaElement3 = array(); 
$CriteriaElement3[] = new SoapVar('CustLoadListTrans', XSD_STRING, null, $nameSpace, 'DataSourceName', $nameSpace); 
$CriteriaElement3[] = new SoapVar('CustLoadListId', XSD_STRING, null, $nameSpace, 'FieldName', $nameSpace); 
$CriteriaElement3[] = new SoapVar('Equal', XSD_STRING, null, $nameSpace, 'Operator', $nameSpace); 
$CriteriaElement3[] = new SoapVar($custLoadListId, XSD_STRING, null, $nameSpace, 'Value1', $nameSpace); 
$CriteriaElement3[] = new SoapVar('', XSD_STRING, null, $nameSpace, 'Value2', $nameSpace); 
$CriteriaElementThree = new SoapVar($CriteriaElement3, SOAP_ENC_OBJECT, null, $nameSpace, 'CriteriaElement', $nameSpace ); 

$parm = array(); 
$parm[] = new SoapVar($CriteriaElementOne, SOAP_ENC_OBJECT, null, $nameSpace, 'CriteriaElement', $nameSpace); 
$parm[] = new SoapVar($CriteriaElementTwo, SOAP_ENC_OBJECT, null, $nameSpace, 'CriteriaElement', $nameSpace); 
$parm[] = new SoapVar($CriteriaElementThree, SOAP_ENC_OBJECT, null, $nameSpace, 'CriteriaElement', $nameSpace); 
$CriteriaElement = new SoapVar($parm, SOAP_ENC_OBJECT, null, $nameSpace, 'CriteriaElement', $nameSpace ); 

$QueryCriteria->QueryCriteria = $CriteriaElement; 


$result = $client->find($QueryCriteria);