How can I generate this schema using php soap client cant seem to get a way
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:loc="http://www.csapi.org/schema/parlayx/subscribe/manage/v1_0/local">
<soapenv:Header>
<tns:RequestSOAPHeader xmlns:tns="http://www.namesapace.com/common/v2_1">
<tns:one>***</tns:one>
<tns:two>***</tns:three>
<oauth_token>***</oauth_token>
</tns:RequestSOAPHeader>
</soapenv:Header>
<soapenv:Body>
<loc:ProductRequest>
<subInfo>
<productID>***</productID>
<isAutoExtend>0</isAutoExtend>
</subInfo>
</loc:ProductRequest>
</soapenv:Body>
</soapenv:Envelope>
On top of using the client, sometimes it may not bind to the namespace especially if using different soap versions or other strange reasons. Solved it by overriding the soap class and replacing the ns1 and ns2 values as described here http://php.net/manual/en/soapclient.dorequest.php#74123
IF no success with php soapclient, just post the request with curl.
Example in this answer - SOAP request in PHP with CURL
Related
With PHP, I need to send a SOAP request with a parameter (Hash) in the footer. I'm using SoapClient but I can not figure out how to do this, neither in internet searches, nor in documentation.
This is the envelope I used in the SoapUI tool to test:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:abc="" xmlns:abc1="" xmlns:abc2="">
<soapenv:Header/>
<soapenv:Body>
<abc:Method>
<!--Optional:-->
<abc:request>
<abc1:Header>
<abc1:Username>Username</abc1:Username>
<abc1:Password>Password</abc1:Password>
<!--Optional:-->
<abc1:PublicKeyUid></abc1:PublicKeyUid>
</abc1:Header>
<abc1:Body>
<abc2:Id></abc2:Id>
</abc1:Body>
<abc1:Footer>
<abc1:Hash></abc1:Hash>
</abc1:Footer>
</abc:request>
</abc:Method>
</soapenv:Body>
</soapenv:Envelope>
There is The SoapHeader class e the SoapClient::__setSoapHeaders method but I find nothing related to the footer.
I do not have access to the server and should follow this structure mentioned above.
What I need to know is how to send the HASH parameter that is inside the footer with SoapClient.
Thanks in advance for any help or suggestion.
As IMSoP and axiac have commented, the footer (<abc1: Footer>) is just a sub-structure of the envelop body and not a standard XML envelop element. I had not realized this and so I did not find it in the documentation.
So to send HASH to the requested structure, I need to pass a multidimensional array on the body element. The code looks like this:
$arrParameters = [
'request'=>[
'Header'=>[
'Username'=>$strUsername,
'Password'=>$strPassword
],
'Body'=>[
...
],
'Footer'=>[
'Hash'=>$strHash
]
]
];
$SoapClient = new SoapClient(<WSDL URL>);
$resp = $SoapClient->method($arrParameters);
Thank you IMSoP and axiac!
I have a SOAP webservice and in SOAP UI I see that there are methods with the same name. So, for example, there are 2 CreateNewContact methods, one of which takes 3 parameters and the other 4. Below are the stubs generated by SOAP UI
Method 1 Stub:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rfp="http://test.com/testWebservice/">
<soapenv:Header/>
<soapenv:Body>
<rfp:CreateNewContact_FullName>
<!--Optional:-->
<rfp:fullName>?</rfp:fullName>
<!--Optional:-->
<rfp:email>?</rfp:email>
<!--Optional:-->
<rfp:telNo>?</rfp:telNo>
</rfp:CreateNewContact_FullName>
</soapenv:Body>
</soapenv:Envelope>
Method 2 Stub:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rfp="http://test.com/testWebservice/">
<soapenv:Header/>
<soapenv:Body>
<rfp:CreateNewContact_FirstLastName>
<!--Optional:-->
<rfp:firstName>?</rfp:firstName>
<!--Optional:-->
<rfp:lastName>?</rfp:lastName>
<!--Optional:-->
<rfp:email>?</rfp:email>
<!--Optional:-->
<rfp:telNo>?</rfp:telNo>
</rfp:CreateNewContact_FirstLastName>
</soapenv:Body>
</soapenv:Envelope>
When I call the CreateNewContact method with 4 parameters using PHP SoapClient, it looks like I'm getting the response from the other method.
How can I specify which method to use using SoapClient?
Thanks,
As you can read here:
If you are using WSDL based SOAP requests and you have more than one
operation in your binding (with the same parameters), make sure the
style is set to rpc, NOT body! When you specify
'body' here, all that will be transmitted in the request is the
parameters for the function call, and SoapServer->handle() will use
the first function it finds with the same parameter-makeup to handle
the call. The actual method to call will only be included in the
request when your type is set to 'rpc', resulting in the expected
behavior
Therefore, you should check in your WSDL the operation element, which provides binding information from the abstract operation to the concrete SOAP operation.
For example:
<definitions ....>;
<binding .... >;
<operation .... >;
<soap12:operation soapAction="xs:anyURI" ?
soapActionRequired="xs:boolean" ?
style="rpc|document" ?
wsdl:required="xs:boolean" ? /> ?
</soap12:operation>
</binding>;
</definitions>
The style attribute value, if present, is a string that specifies the style for the operation. The style attribute indicates whether the operation is RPC-oriented (a messages containing parameters and return values) or document-oriented (a message containing documents). If the style attribute is omitted from the soap12:operation element, then the operation inherits the style specified or implied by the soap12:binding element in the containing wsdl:binding element.
So, in short, to solve your problem you should change the operation style from "document" to "rpc" in your WSDL.
As a further reference: https://bugs.php.net/bug.php?id=49169
I have faced the same with travelport universal API, I ended up modifying my local wsdl file to use different name for each method and it worked perfectly.
I would like it so customers don't have to travel off site to see their tracking info:(In other words they can track their shipment from my website) http://www.echo.com/ShipmentTracking/EchoShipmentTrack.aspx
I received the API documentation and I was able to test a remote API with SOAPUI successfully. I see that it has several tools to generating code for things like Java. I looked for a SoapUI to PHP tool but was unable to find one. I'm very new to PHP, could anyone give the code of how I could translate this XML into something that I could execute on a web server?
WSDL link: http://api.echo.com/Echo.API.ShipmentStatus/ShipmentStatusService.svc?wsdl
Sample Request generated by SOAPUI:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://api.echo.com/shipmentstatus/contracts/2012/02/" xmlns:ns1="http://api.echo.com/common/schemas/2012/02/" xmlns:ns2="http://api.echo.com/shipmentstatus/schemas/2012/02/">
<soapenv:Header/>
<soapenv:Body>
<ns:GetStatus>
<ns:getStatusRequest>
<ns1:UserCredentials>
<ns1:APIKey>------REMOVED-----</ns1:APIKey>
</ns1:UserCredentials>
<ns2:BatchProcessingOptions>
<ns1:NotificationOptions>
<ns1:NotifyByEmail>false</ns1:NotifyByEmail>
<ns1:NotifyEmail>dchol#echo.com</ns1:NotifyEmail>
</ns1:NotificationOptions>
<ns1:ShouldPartialProcessBatch>false</ns1:ShouldPartialProcessBatch>
<ns2:CostResultFormat>DETAIL</ns2:CostResultFormat>
<ns2:IncludeCostDetails>false</ns2:IncludeCostDetails>
<ns2:StatusResultFormat>DETAIL</ns2:StatusResultFormat>
</ns2:BatchProcessingOptions>
<ns2:ShipmentIdentifiers>
<ns1:ShipmentIdentifier>
<ns1:ShipmentAccountNumber>E9704</ns1:ShipmentAccountNumber>
<ns1:ShipmentNumber>17596853</ns1:ShipmentNumber>
</ns1:ShipmentIdentifier>
</ns2:ShipmentIdentifiers>
</ns:getStatusRequest>
</ns:GetStatus>
</soapenv:Body>
</soapenv:Envelope>
This question already have a solutions at stackoverflow.
Look at this answers:
https://stackoverflow.com/a/10505172/2324993
https://stackoverflow.com/a/1656763/2324993
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 using Zend_Soap_Client to query data from a webservice provided by SAP. Since the auto-generated WSDL file has a few flaws, I use the non-WSDL mode of the client.
I managed to successfully call a webservice which only requires simple parameters, like strings. Example:
This is what SAP expects:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style">
<soapenv:Header/>
<soapenv:Body>
<urn:Ze12RfcGetCustHistoryNew>
<PiDateHigh>2011-12-31</PiDateHigh>
<PiDateLow>1970-01-01</PiDateLow>
<PiKunnr>1</PiKunnr>
</urn:Ze12RfcGetCustHistoryNew>
</soapenv:Body>
</soapenv:Envelope>
This is my (working) code in PHP (with $soapClient already initialized in non-WSDL mode):
$soapClient->Ze12RfcGetCustHistoryNew(
new SoapParam(date('Y-m-d'), 'PiDateHigh'),
new SoapParam('1970-01-01', 'PiDateLow'),
new SoapParam('1', 'PiKunnr')
);
But as soon as I have to pass more complex parameters to the service, it does not work. Again, an example:
This is what SAP expects:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style">
<soapenv:Header/>
<soapenv:Body>
<urn:Ze12RfcGetCustHistoryNew>
<PiDateHigh>2011-12-31</PiDateHigh>
<PiDateLow>1970-01-01</PiDateLow>
<PiKunnr>1</PiKunnr>
<PiTBelegart>
<item>
<BelegartTyp>FAKTURA</BelegartTyp>
<Belegart>ZF2</Belegart>
</item>
</PiTBelegart>
</urn:Ze12RfcGetCustHistoryNew>
</soapenv:Body>
</soapenv:Envelope>
I have tried to use a multi-dimensional array containing SoapParams, but that did not work. In WSDL mode, I could pass the params as an array, without the need of using SoapParams. How can I do this in non-WSDL mode?
just a "quick-hit" ... I'm working in a different environment, but initially had my soap-value troubles too.
One solution for a particular problem was to pass complex arrays this way:
$data = (object)$complexArray;
$result = $webserviceClient->getResult($data);
"Casting" to object results in a StdClass object ... which often works fine for webservices.
Good Luck!
I have not come up with a nice solution for this yet - currently I pass the parameters to the client object as raw xml. That works, but does not seem to be the best way to do this. This is my code now:
$params = '
<PiDateHigh>2011-12-31</PiDateHigh>
<PiDateLow>1970-01-01</PiDateLow>
<PiKunnr>1</PiKunnr>
<PiTBelegart>
<item>
<BelegartTyp>FAKTURA</BelegartTyp>
<Belegart>ZF2</Belegart>
</item>
</PiTBelegart>
';
$result = $this->_client->Ze12RfcGetCustHistoryNew(new SoapVar($params,XSD_ANYXML));