PackageGenerator icon indicating copy to clipboard operation
PackageGenerator copied to clipboard

Does not seem to add type to xml

Open fyem opened this issue 8 years ago • 9 comments
trafficstars

In my request I need to create a tag like:

<Partner xsi:type="partner:CT_Person" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

The generator created two different classes that seem to have to do something with this structure:

CT_Partner.php and CT_Person.php

However even if I use the CT_Person class the generated xml tag looks like this:

<ns5:Partner>

The same behavior also happens with other tags that require the type attribute.

fyem avatar Oct 22 '17 21:10 fyem

This often comes from the fact that the native PHP SoapClient class (used as the soap client by default) does not handle correctly this sort of abstraction.

This is why you might need to override the SoapClient class in order to generate your own XML request based on the parameters. This can seem hard to do but not really. In any case, you can override the used SoapClient following this example in the PackageEws365 package by looking to the SoapClient directory and the generate.sh file.

mikaelcom avatar Oct 23 '17 14:10 mikaelcom

Awesome. Thank you for your help. I will check out the example.

fyem avatar Oct 23 '17 21:10 fyem

The example did not really help me. The example simply shows how I can adjust the generated xml file later on. I think I would have to find out how the php SoapClient generates the request based on the parameters but I was not able to find any kind of resources for that.

fyem avatar Oct 26 '17 19:10 fyem

You have to use the SoapClient class as it used in the sample in order to alter the XML before it is actually sent. Look to https://github.com/WsdlToPhp/PackageEws365/blob/develop/SoapClient/SoapClient.php

mikaelcom avatar Oct 26 '17 20:10 mikaelcom

I get how to alter the XML. That is not sufficient for my case, though. I would need to change the XML generation in the first place

fyem avatar Oct 27 '17 02:10 fyem

If you agree to:

  • send me your WSDL
  • tell me a operation you need to call
  • the data you need to send

Maybe I can spend a little time on it in order to indicate how I would handle it. I have used many different kind of SOAP WS so maybe I would be able to help you better with these information.

mikaelcom avatar Oct 27 '17 03:10 mikaelcom

I sent you the wsdl via email.

I need to call the function getQuote()

The big issue that I have is with something like CT_Person and CT_JuristischePerson. They should be differentiated like <Partner type="CT_Person"> and <Partner type="CT_JuristischePerson"> but both of them get generated as <Partner> in this case. The information on which type to use would be lost while generating the XML

Thank you so much for your extensive help

fyem avatar Oct 27 '17 14:10 fyem

I'm running into the same issue, with a different WSDL, did you guys ever figure out a solution to this?

EDIT: Figured out a solution by overriding __call looping trough the fields, and manually creating the \SoapVar's

ghost avatar Mar 02 '18 10:03 ghost

this notice is not directly address to this issue, sorry, but it helped me to find a solution for my problem of missing namespaces.

just in case somone (like me) has similar problems and finds this issue here: in my case i am trying to communicate with the ebay finding api and it turns out, the whole request that is generated by the default php soapclient needs extra namespaces, so a simple helper function did the job, without any complicated replacements of the generator:

private function addNamespaceToObjects($obj) {
		foreach ((new \ReflectionObject($obj))->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
			$property_name = $property->name;
			if (is_object($obj->{$property->name})) {
				$obj->$property_name = new \SoapVar(self::addNamespaceToObjects($obj->{$property->name}),SOAP_ENC_OBJECT, null, null, null, $this->soap_namespace);
			} else {
				if ($obj->{$property->name}) {
					$obj->$property_name = new \SoapVar($obj->{$property->name}, XSD_STRING, null, null, null, $this->soap_namespace);
				}
			}
		}
		return $obj;
	}

@BTFO thanks, the notice with __call was perfect 😏

michabbb avatar Nov 30 '18 18:11 michabbb