通过 PHP 使用具有多个同名关键字段的 Web 服务

Consuming AX webservice through PHP with multiple key fields with the same name

我正在尝试通过 PHP 在 AX 2009 中使用 Web 服务,之前这样做没有任何问题,这次我需要生成一个具有多个同名键的 XML ,对于更新部分,我找到了一个可行的解决方案,但我需要 select 在更新之前记录记录,但它失败了。

我收到此错误消息:"Client SOAP-ERROR: Encoding: object hasn't 'DataSourceName' property"

这是请求的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;

它有效,但记录 select 仅由一个关键字段编辑。

我正在使用 PHP 版本 5.1.6

这样做就可以了:

$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);