Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not seem to add type to xml #118

Open
fyem opened this issue Oct 22, 2017 · 9 comments
Open

Does not seem to add type to xml #118

fyem opened this issue Oct 22, 2017 · 9 comments

Comments

@fyem
Copy link

fyem commented Oct 22, 2017

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.

@mikaelcom
Copy link
Member

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.

@fyem
Copy link
Author

fyem commented Oct 23, 2017

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

@fyem
Copy link
Author

fyem commented Oct 26, 2017

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.

@mikaelcom
Copy link
Member

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

@fyem
Copy link
Author

fyem commented Oct 27, 2017

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

@mikaelcom
Copy link
Member

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.

@fyem
Copy link
Author

fyem commented Oct 27, 2017

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

@ghost
Copy link

ghost commented Mar 2, 2018

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

@michabbb
Copy link

michabbb commented Nov 30, 2018

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 😏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants