Page 1 of 1

soap request parameters

Posted: Wed Dec 22, 2010 2:04 am
by thomasnegeli
Hi community,
I'm strugling around with the php soap implementation.
I need to request data from a java web application and the request parameters are sometimes passed as regular soap parameters and sometimes passed as attributes to the enclosing tag.

Example for a valid request:

Code: Select all

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:con="http://mynamespace">
   <soapenv:Header/>
   <soapenv:Body>
      <con:GetContainerRequest containerId="2">
         <!--Optional:-->
         <con:CustomFieldIds>
            <!--Zero or more repetitions:-->
            <con:CustomFieldId>1</con:CustomFieldId>
         </con:CustomFieldIds>
      </con:GetContainerRequest>
   </soapenv:Body>
</soapenv:Envelope>
To pass a parameter in the CustomFieldIds Tag is not the problem. My problem is how to pass the containerId attribute?
If I code something like:

Code: Select all

$obj = new stdClass;
			$obj->containerId['_'] = "containerId";
			$obj->containerId['containerId'] = $containerId;
			if($customFieldIds!= null) {
				$cfIds = new stdClass;
				foreach($customFieldIds as $cfId) {
					$contIds->CustomFieldId[] = new SoapVar($cfId, XSD_STRING, null, null, null, SoapApi::$containerServiceNs); 
				}
				$obj->CustomFieldIds = new SoapVar($cfIds, SOAP_ENC_OBJECT); 
			}
			
			$soapstruct = new SoapVar($obj, SOAP_ENC_OBJECT);

			return $this->clientForContainerService->GetContainer(new SoapParam($soapstruct, "inputStruct"));

The resulting request is:

Code: Select all

      <SOAP-ENV:Body>
		<ns1:GetContainerRequest>
			<containerId>
				<item>
					<key>_</key>
					<value>containerId</value>
				</item>
				<item>
					<key>containerId</key>
					<value>104</value>
				</item>
			</containerId>
		</ns1:GetContainerRequest>
	</SOAP-ENV:Body>
If found many examples with the "_" notation, but I think I coded it wrong because it does not work.
Anyone here who has knowledge about how my could should be structured?

Cheers and thanks in advance
Thomas

Re: soap request parameters

Posted: Wed Dec 22, 2010 9:23 am
by thomasnegeli
Problem solved.
I'm now using the classmap attribute of the SoapClient class.
That's the way it works.