OK, no matter how hard I try I cannot figure the way this works... there is a certain magic attached to all SOAP related object that I cannot really understand...
I want to create the following with the PHP SOAP classes SoapClient, SoapParam etc...
Please help me understand how to do it. I created a somehow complex XML structure so that I can really "get" what is going on...
<env:Envelope>
<env:Body>
<ns:myMethod>
<TheInput xsi:type="ns:TheInputUser">
<ns:username>XXXX</ns:username>
</TheInput>
<TheOutput xsi:type="ns:TheOutUser">
<ns:var xsi:nil="true"/>
</TheOutput>
<Array1 xsi:type="ns:UserArray1"/>
<IdOut xsi:type="xsd:decimal">0</IdOut>
<ErrorOut xsi:type="ns:ErrorUser">
<ns:errorDescr xsi:nil="true"/>
</ErrorOut>
</ns:myMethod>
</env:Body>
</env:Envelope>
thanks in advance
Related
I'm trying to consume a C# WCF Webservice with PHP, and I'm currently facing a really big problem.
First, let me show you what one of the the WCF Webservice responses looks like :
<?xml version="1.0" encoding="UTF-8"?>
<s:envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:header>
<activityid xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics" correlationid="6b8187a6-79a9-4bc4-a195-7c3b66547408">b340ad42-7be9-466c-a9f1-4048d35b7cb5</activityid>
</s:header>
<s:body>
<getalljobsresponse xmlns="http://tempuri.org/">
<getalljobsresult xmlns:a="http://schemas.datacontract.org/2004/07/Transcode.Webservice.Messages" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:jobinfo>
<a:associatedfilesize>34551192</a:associatedfilesize>
<a:associateduserid>10</a:associateduserid>
<a:jobcompletiondate>2016-06-09T10:37:42.2568136</a:jobcompletiondate>
<a:jobid>29</a:jobid>
<a:jobsubmissiondate>2016-06-09T10:37:27.8522463</a:jobsubmissiondate>
<a:remotefilepath>ftp://localhost/transcode_uploads/Luc/LinkinPark-DontStay.au</a:remotefilepath>
<a:taskprice>0.05</a:taskprice>
<a:taskstate>2</a:taskstate>
</a:jobinfo>
<a:jobinfo>
<a:associatedfilesize>34551192</a:associatedfilesize>
<a:associateduserid>10</a:associateduserid>
<a:jobcompletiondate>2016-06-09T11:46:07.7590635</a:jobcompletiondate>
<a:jobid>1029</a:jobid>
<a:jobsubmissiondate>2016-06-09T11:45:55.8115507</a:jobsubmissiondate>
<a:remotefilepath>ftp://localhost/transcode_uploads/Luc/LinkinPark-DontStay.au</a:remotefilepath>
<a:taskprice>0.05</a:taskprice>
<a:taskstate>2</a:taskstate>
</a:jobinfo>
</getalljobsresult>
</getalljobsresponse>
</s:body>
</s:envelope>
I'm trying everything to get a jobinfo element with all its attributes, but it doesn't seem to work well ...
I tried the following line of code :
$xml->getElementsByTagName('associatedfilesize')->item(0)->nodeValue
And it works on a single attribute, as for jobid or anything else !
The problem is, I would like to get a jobInfo objet in its entirety, by using something like :
$xml->getElementsByTagName('jobInfo')
Could you please help me guys, I have very little time left to finish my work and I'm stuck on that issue for too long...
After breaking my head on a wall for a whole day i just think i need some help for this.
I'm receiving the following answer from a soap call :
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<SearchBrochuresResponse xmlns="http://services.iceportal.com/service">
<SearchBrochuresResult>
<pageNumber>0</pageNumber>
<brochures>
<SearchBrochure>
<iceID>10427</iceID>
<city>Acapulco</city>
</SearchBrochure>
</brochures>
</SearchBrochuresResult>
</SearchBrochuresResponse>
</soap:Body>
</soap:Envelope>
I tried all i could find on the subject on stackoverflow and all the other sources i found, but i couldn't access to the iceID, basically my goal is to get into a php variable the value of the iceID node.
Thanks a lot for your help.
Assume your xml data is in the variable $data you could create a simple XML object from it, then access it's nodes in the following way (example to get iceID):
$xml = simplexml_load_string($data);
$iceID = (string)$xml->children('soap', true)
->Body->children()
->SearchBrochuresResponse
->SearchBrochuresResult
->brochures
->SearchBrochure
->iceID;
You could look into XPath, the technique used to navigate and select parts of an XML document.
Wikipedia on XPath
If you need more help please post a more specific question. What have you tried? Do you only need to extract that specific value?
I was trying to find some examples how to write binding.xml with JiBX/PiBX for following SOAP response but with no luck. Does anyone know how to do this?
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns6:getDataResp xmlns:ns6="http://domain.com/response/data/">
<s3:requestId xmlns:s3="http://domain.com/entity/">12</s3:requestId>
<s4:errorCode xmlns:s3="http://domain.com/entity1/">0</s4:errorCode>
<ns6:dataResp>
<ns5:Data>Some string data</ns5:Data>
</ns6:dataResp>
</ns6:getDataResp>
</soapenv:Body>
</soapenv:Envelope>
If you are using JiBX you're in luck. You have a couple of options:
The apache cxf project has a databinding module for JiBX. You can use one of the open-source web servers such as servicemix to do your SOAP handling. This means you only have to bind the message schema (getDataResp in your example) with JiBX. You can find a nice example, here.
JiBX has it's own web server called JiBX/WS. It will also do all the SOAP handling for you.
I hope this helps!
Don
JiBX contributor
I am having serious issues parsing this xml array using curl. I only need the click_id printed on each new row. Does someone have an example of how I can pull this. I am using curl and get the response below in the variable $result. I am using php.
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfClick xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://cakemarketing.com/api/1/">
<Click>
<click_id>7458165</click_id>
<request_session_id>7901644</request_session_id>
<click_date>2011-09-08T13:53:37.143</click_date>
<offer_id>10346</offer_id>
<advertiser_id>1050</advertiser_id>
<campaign_id>6527</campaign_id>
</Click>
<Click>
<click_id>7459318</click_id>
<request_session_id>7903011</request_session_id>
<click_date>2011-09-08T14:41:37.953</click_date>
<offer_id>10346</offer_id>
<advertiser_id>1050</advertiser_id>
<campaign_id>6527</campaign_id>
</Click>
The best way is to use XPath with the help of this class http://php.net/manual/en/class.domxpath.php
A more simple method is to use regex (but I discourage this approach)
I am working on building a web service in PHP using the SoapServer class, but I'm running into an issue with casting of complex types.
The WSDL is completely valid, and the PHP SoapClient handles it flawlessly, but there seems to be an issue with the complex types that are returned not being cast properly. This came to light when consuming the service in .Net, as I was getting exceptions that indicated the type was not present in the given namespace.
I mangled my function numerous times, changing the namespace on the element, but .Net continues to give me errors, regardless of what namespace I use.
Consider the following abbreviation of the script:
function getCommands() {
$output = array();
// ...
foreach($result as $row) {
$output[] = new SoapVar($row, SOAP_ENC_OBJECT, 'ns1:command');
}
return $output;
}
The abbreviated response:
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="urn:MyWebService"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:getCommandsResponse>
<return SOAP-ENC:arrayType="ns1:command[12]" xsi:type="ns1:ArrayOfCommand">
<item xsi:type="ns1:command">
<!-- ... -->
</item>
<!-- ... -->
</return>
</ns1:getCommandsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
What I've noticed is that xmlns:ns1 is defined by way of the WSDL, and it does match the namespace in the WSDL. However, the .Net SOAP client doesn't seem to understand that the command element is defined there. It does, however, understand that that's where ArrayOfCommand is defined.
So my question is multipart:
Is this a known bug with the SoapServer?
If not, am I missing something grievous in my WSDL?
Am I not encoding my objects properly?
Is this an issue with .Net? If so, what's the work-around?
I was able to resolve this issue by working over the <types/> section of my WSDL again, using the Google WSDL for reference. Then, I had to work some magic in my PHP function, casting the elements of the $command appropriate to their respective types in the WSDL, and encoding the entire command as a ns2:command. When aligned with the WSDL, this all fell together nicely and .Net is having zero difficulty with it.
I'm surprised nobody in the development community was willing to answer this, but I hope someone will be able to glean from it at least some direction on how to fix their own instance of this problem.