Parse 2 difference Soap Response PHP - php

I'm new in php, how to parse 2 difference response from soap xml ?
Response 1
'<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:MobileAgentAPI="urn:openApi">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<MobileAgentAPI:invokeResponse>
<SOAP-ENV:BodySOAP-ENV:Body>
<values xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="MobileAgentAPI:SoapMapValue[13]">
<item>
<name>amount</name>
<singleValue>5000</singleValue>
</item>
<item>
<name>balance</name>
<singleValue>12210000</singleValue>
</item>
<item>
<name>lastBalance</name>
<singleValue>12215000</singleValue>
</item>
<item>
<name>returnCode</name>
<singleValue>00</singleValue>
</item>
<item>
Response 2
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:MobileAgentAPI="urn:openApi"><SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><MobileAgentAPI:invokeResponse><invokeReturn><values xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="MobileAgentAPI:SoapMapValue[6]"><item><name>balance</name><singleValue>15420000</singleValue></item><item><name>returnCode</name><singleValue>01</singleValue></item><item><name>transactionStatus</name><singleValue>02</singleValue></item><item><name>errorCode</name><singleValue>324</singleValue></item><item><name>errorDescription</name><singleValue>(324) Maaf, transaksi pada 01/10/18 06:00 gagal. Nomor tujuan tidak terdaftar. =</singleValue></item><item><name>tran
im try with DOM Document but if we have 2 response the result is error

Why do you try to parse the XML response?
With the native PHP SoapClient class, you handle at least PHP arrays or betterly objects.
Use a WSDL to PHP generator so you won't wonder how to construct the request data nor how to handle the response as you'll always use an OOP approach which is better. Try the PackageGenerator project.

Related

How to form properly __soapCall parameters

Trying to make a soap call with parameters:
$client = new SoapClient( null, [
'location' => $url,
'uri' => $uri,
'trace' => 1,
'exceptions' => 1
] );
$params['parameters'] = [
'p1'=>'v1',
'p2'=>'v2'
];
$client->__soapCall('generate',$params);
I want my request look like this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="some_url_here">
<SOAP-ENV:Body>
<ns1:generate>
<parameters>
<p1>v1</p1>
<p2>v2</p2>
</parameters>
</ns1:generate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But what I get is:
var_dump($client->__getLastRequest());
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="some_url_here"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:generate>
<param0 xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">p1</key>
<value xsi:type="xsd:string">v1</value>
</item>
<item>
<key xsi:type="xsd:string">p2</key>
<value xsi:type="xsd:string">v2</value>
</item>
</param0>
</ns1:generate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Any ideas how properly form params list to get wanted request?
Your help would be appreciated.
The best and fast way to consume a Soap Web Service is to use a WSDL to php generator as you won't wonder how to construct the request.
Try the PackageGenerator project and you'll see it's easy to construct the request (without making any error unless you're doing it purposely ;)). In addition, the received response is easily handled. Each part is an object.

How do you set the NODE namespace with NuSoap?

Is there a way in NUSOAP to set a node's namespace?
Using normal PHP soap, it can be done with SoapVar.
What is the equivalent in NuSoap?
I have:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:own="www.ownyourliferewards.co.za" xmlns:own1="http://schemas.datacontract.org/2004/07/OwnYourLife.WebServices.WebServicesBase" xmlns:own2="http://schemas.datacontract.org/2004/07/OwnYourLife.WebServices.Generic.DataObjects">
<SOAP-ENV:Body>
<AuthenticateMember xmlns="www.ownyourliferewards.co.za">
<request>
<SecurityToken>9415CD31-0C7E-40AB-A45F-D3538B98B96B</own1:SecurityToken>
<MembershipNumber>200803407801</own2:MembershipNumber>
</request>
</AuthenticateMember>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
and I want:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:own="www.ownyourliferewards.co.za" xmlns:own1="http://schemas.datacontract.org/2004/07/OwnYourLife.WebServices.WebServicesBase" xmlns:own2="http://schemas.datacontract.org/2004/07/OwnYourLife.WebServices.Generic.DataObjects">
<SOAP-ENV:Body>
<AuthenticateMember xmlns="www.ownyourliferewards.co.za">
<request>
<own1:SecurityToken>9415CD31-0C7E-40AB-A45F-D3538B98B96B</own1:SecurityToken>
<own2:MembershipNumber>200803407801</own2:MembershipNumber>
</request>
</AuthenticateMember>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
(note the own1: and own2: namespaces on the nodes)
Thanks
Jacques

SOAPServer+php+iis v6 (not correct closing tag)

thanks for reading. I am having a big problem using the SOAPServer class from php.
when we make the test we have this respons, that works well:
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:WSDL" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:NotificacionClienteResponse>
<NotificacionClienteReturn xsi:type="xsd:string"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<NotificacionCliente>
<RESULTADO>
<CODIGORETORNO>8</CODIGORETORNO>
<DESCRIPCIONRETORNO>Xml incorrecto</DESCRIPCIONRETORNO>
</RESULTADO>
</NotificacionCliente>]]>
</NotificacionClienteReturn>
</ns1:NotificacionClienteResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
but when we do the same, but in other server, we have this response:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:WSDL" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:NotificacionClienteResponse>
<NotificacionClienteReturn xsi:type="xsd:string"><?xml version="1.0" encoding="UTF-8"?>
<NotificacionCliente>
<RESULTADO>
<CODIGORETORNO>8</CODIGORETORNO>
<DESCRIPCIONRETORNO>Xml incorrecto</DESCRIPCIONRETORNO>
</RESULTADO>
</NotificacionCliente>
</NotificacionClienteReturn>
</ns1:NotificacionClienteResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope
as you can see in the second respons there are 3 different problems:
it appers &lt and &gt in place of < and >
at the end of the xml its missing de >
and the xml its not formated (i did it for you :) )
Information about the server:
same wsdl, web server, php_soap.dll, php.ini
we use iis v6 and php v5.2.9-2
the php is calling the SOAPServer this way, in both servers:
new SOAPServer($Path, array('encoding'=>'ISO-8859-1'))
well, any information you can tell us or any clue you might think its worth tring just tell it...
of course, the same if you need more information.
thanks you all in advance!

INVALID_TYPE when creating salesforce attachment

Bellow is the XML POST and Response i get from the sales force servers.
Im trying to add an attachment to an Account but i keep getting INVALID_TYPE.
Im using NuSoap instead of the SalesForce PHP library because the server i'm working on doesnt have the SOAP extension required.
I have no issue with going in and amending the library to make it work but i dont have a clue whats wrong with the XML to fix the issue. I get query information perfectly fine.
All help and advice appreciated!
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
<nu2113:SessionHeader xmlns:nu2113="urn:enterprise.soap.sforce.com">
<sessionId>00Di00000{---cutting out for privacy--}UrYmByvpO5yRWIK0Gmy</sessionId>
</nu2113:SessionHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<create xmlns="urn:enterprise.soap.sforce.com">
<sObject>
<type xsi:type="xsd:string">Attachment</type>
<fieldsToNull>
<elementName xsi:type="xsd:string">fieldsToNull</elementName>
<values xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:string[5]">
<item xsi:type="xsd:string">OwnerId</item>
<item xsi:type="xsd:string">IsPrivate</item>
<item xsi:type="xsd:string">IsPartnerShared</item>
<item xsi:type="xsd:string">ConnectionSentId</item>
<item xsi:type="xsd:string">BodyLength</item>
</values>
</fieldsToNull>
<Id xsi:nil="true"/>
<ParentId xsi:type="xsd:string">001i000000JG17b</ParentId>
<Name xsi:type="xsd:string">Test document</Name>
<Description xsi:type="xsd:string">Test upload from WIN form</Description>
<ContentType xsi:type="xsd:string">.pdf</ContentType>
<Body xsi:type="xsd:string">hello</Body>
</sObject>
</create>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
HTTP/1.1 100 Continue
HTTP/1.1 500 Server Error
Date: Mon, 13 Jan 2014 15:49:56 GMT
Content-Type: text/xml;charset=UTF-8
Content-Length: 676
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>sf:INVALID_TYPE</faultcode>
<faultstring>INVALID_TYPE: Must send a concrete entity type.</faultstring>
<detail>
<sf:InvalidSObjectFault xsi:type="sf:InvalidSObjectFault">
<sf:exceptionCode>INVALID_TYPE</sf:exceptionCode>
<sf:exceptionMessage>Must send a concrete entity type.</sf:exceptionMessage>
<sf:row>-1</sf:row>
<sf:column>-1</sf:column>
</sf:InvalidSObjectFault>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
This line might be the problem:
<ContentType xsi:type="xsd:string">.pdf</ContentType>
that is not a valid content type. try this:
<ContentType xsi:type="xsd:string">application/pdf</ContentType>

Return a php xpath answer with SOAP

I m trying to return an xpath answer to a soap client (i am using an xml file as database).
The method works fine when it's called on the server side, unfortunatelly, the client always get an annoying " looks like we got no XML document " error, with this kind of
xml answer:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn://localhost/projet/srv" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://xml.apache.org/xml-soap" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:getTypesVehiculeResponse>
<return SOAP-ENC:arrayType="SOAP-ENC:Struct[4]" xsi:type="SOAP-ENC:Array">
<item xsi:type="SOAP-ENC:Struct">
<#attributes xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">id</key>
<value xsi:type="xsd:string">0</value>
</item>
...
</return>
</ns1:getTypesVehiculeResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Should I use another way to send my XML database answers than directly return xpath answer?
SoapClient should eliminate the need for xpath querying since it already parses the SOAP XML, but if you still want to use xpath, you can try using simplexml as per this answer. If you have an issue with namespaces, try this

Categories