PHP Soap客户端不会在webservice调用中发送所有对象属性

PHP Soap客户端不会在webservice调用中发送所有对象属性,php,soap,soap-client,Php,Soap,Soap Client,我试图用php实现一个webservice客户端,但遇到了问题。。。 我正在使用一个名为metadataservice的现有Web服务和一个已知的wsdl。 我将使用WSDL2HPGenerator为数据类型和服务本身创建php类。 使用Webservice方法之一(addMetadataToObject),我必须向服务器发送一个对象数组。 有一个基类: class AssetInfo { public $dataFieldId = null; public $dataField

我试图用php实现一个webservice客户端,但遇到了问题。。。 我正在使用一个名为metadataservice的现有Web服务和一个已知的wsdl。 我将使用WSDL2HPGenerator为数据类型和服务本身创建php类。 使用Webservice方法之一(addMetadataToObject),我必须向服务器发送一个对象数组。 有一个基类:

class AssetInfo
{
    public $dataFieldId = null;
    public $dataFieldName = null;
    public $dataFieldTagName = null;
    public function __construct($dataFieldId, $dataFieldName, $dataFieldTagName)
    {
      $this->dataFieldId = $dataFieldId;
      $this->dataFieldName = $dataFieldName;
      $this->dataFieldTagName = $dataFieldTagName;
    }
}
和一个包含字符串值的派生类(还有其他用于long等的派生类):

对于Metadataservice->addMetadataToObject的调用,还定义了addMetadataToObject:

class addMetadataToObject
{
    public $objectId = null;
    public $objectType = null;
    public $assetInfos = null;
    public function __construct($objectId, $objectType)
    {
      $this->objectId = $objectId;
      $this->objectType = $objectType;
    }
} 
属性$AssetInfo应包含AssetInfo对象数组。WDSL2HPGenerator为my MetadataService创建一个类,该类派生自SoapClient。此类提供此服务的所有可访问方法。这里我只显示addMetadataToObject方法:

public function addMetadataToObject(addMetadataToObject $parameters)
{
  return $this->__soapCall('addMetadataToObject', array($parameters));
}
我的代码是:

// Define the Data    
$ServiceOptions = [];
    $AssetInfos = [];
    $AssetInfo = new StringAssetInfo(2, "TitleName", "TitleName","New Title Name);        
    array_push($AssetInfos, $AssetInfo);

// Create the Service
    $Service = new MetadataService($ServiceOptions, getServiceWSDL($Options, "MetadataService"));
    $Service->__setSoapHeaders(getGalaxySoapHeader($Options));
    $NewMetaData = new addMetadataToObject(61755, "ASSET");
    $NewMetaData->assetInfos = $AssetInfos;

// Call the Service
    $failedAssets = $Service->addMetadataToObject($NewMetaData);
该调用引发无法提取值的Soap异常。这让我想知道。我开始使用wireshark监控到Soap服务器的流量,是的……不再有StringAsset信息类中定义的值……以下是wireshark显示的Soap主体:

<SOAP-ENV:Body>
    <ns1:addMetadataToObject>
        <objectId>61755</objectId>
        <objectType>ASSET</objectType>
        <assetInfos>
            <dataFieldId>2</dataFieldId>
            <dataFieldName>TitleName</dataFieldName>
            <dataFieldTagName>TitleName</dataFieldTagName>
        </assetInfos>
    </ns1:addMetadataToObject>
Id</SOAP-ENV:Body>
但是没有任何改变。这里似乎有某种运行时类型转换或类型对齐,但我看不出原因。我对webservices和php仍然是新手(但目前我必须同时使用这两种服务:-)


有人能评论或给我一个提示这里发生了什么吗?

我能够通过使用数组和soapvars实现它,请注意我在代码中的评论:

$ServiceOptions = [];
    $AssetInfos = [];

// I have to use an Array because the Server depends on the order of the properties. I wasn't able to define expected order using the existing objects but with arrays
    $AssetInfo =  array("dataFieldId"=>2, "dataFieldName"=>"TitleName","dataFieldTagName"=>"TitleName, "value"=>"New Title Name");        

// instead of pushing the Array directly, I create an instance of an SoapVar, pass the Array as data and set the Encoding, the expected type and the Namespace uri
array_push($AssetInfos, new SoapVar($AssetInfo, SOAP_ENC_OBJECT, "StringAssetInfo", "http://metadataservice.services.provider.com"));
    array_push($AssetInfos, $AssetInfo);

// Create the Service
    $Service = new MetadataService($ServiceOptions, getServiceWSDL($Options, "MetadataService"));
    $Service->__setSoapHeaders(getGalaxySoapHeader($Options));
    $NewMetaData = new addMetadataToObject(61755, "ASSET");
    $NewMetaData->assetInfos = $AssetInfos;

// Call the Service
    $failedAssets = $Service->addMetadataToObject($NewMetaData);
这在Soap主体中产生了预期的输出(并且还向Soap信封添加了一些名称空间)

<SOAP-ENV:Body>
    <ns1:addMetadataToObject>
        <objectId>61755</objectId>
        <objectType>ASSET</objectType>
        <assetInfos xsi:type="ns1:StringAssetInfo">
            <dataFieldId>2</dataFieldId>
            <dataFieldName>TitleName</dataFieldName>
            <dataFieldTagName>TitleName</dataFieldTagName>
            <value>New Titel Name 1146</value>
        </assetInfos>
    </ns1:addMetadataToObject>
</SOAP-ENV:Body>

61755
资产
2.
标题名
标题名
新名称1146
$ServiceOptions = [];
    $AssetInfos = [];

// I have to use an Array because the Server depends on the order of the properties. I wasn't able to define expected order using the existing objects but with arrays
    $AssetInfo =  array("dataFieldId"=>2, "dataFieldName"=>"TitleName","dataFieldTagName"=>"TitleName, "value"=>"New Title Name");        

// instead of pushing the Array directly, I create an instance of an SoapVar, pass the Array as data and set the Encoding, the expected type and the Namespace uri
array_push($AssetInfos, new SoapVar($AssetInfo, SOAP_ENC_OBJECT, "StringAssetInfo", "http://metadataservice.services.provider.com"));
    array_push($AssetInfos, $AssetInfo);

// Create the Service
    $Service = new MetadataService($ServiceOptions, getServiceWSDL($Options, "MetadataService"));
    $Service->__setSoapHeaders(getGalaxySoapHeader($Options));
    $NewMetaData = new addMetadataToObject(61755, "ASSET");
    $NewMetaData->assetInfos = $AssetInfos;

// Call the Service
    $failedAssets = $Service->addMetadataToObject($NewMetaData);
<SOAP-ENV:Body>
    <ns1:addMetadataToObject>
        <objectId>61755</objectId>
        <objectType>ASSET</objectType>
        <assetInfos xsi:type="ns1:StringAssetInfo">
            <dataFieldId>2</dataFieldId>
            <dataFieldName>TitleName</dataFieldName>
            <dataFieldTagName>TitleName</dataFieldTagName>
            <value>New Titel Name 1146</value>
        </assetInfos>
    </ns1:addMetadataToObject>
</SOAP-ENV:Body>