this my xml request which i want to create for service.
<soapenv:Header>
<aut:AuthenticationHeader>
<aut:LoginName>John</aut:LoginName>
<aut:Password>Johnpass</aut:Password>
<aut:Culture>en_US</aut:Culture>
<aut:Version>8</aut:Version>
</aut:AuthenticationHeader>
</soapenv:Header>
<soapenv:Body>
<hot:GetCancellationPolicies>
<hot:hotelId>19752</hot:hotelId>
<hot:hotelRoomTypeId>20955</hot:hotelRoomTypeId>
<hot:dtCheckIn>2017-06-25</hot:dtCheckIn>
<hot:dtCheckOut>2017-06-28</hot:dtCheckOut>
</hot:GetCancellationPolicies>
and that is my php code
$p = new stdClass;
$p->request->HotelId = '19752';
$p->request->HotelRoomTypeId = '20955';
$p->request->dtCheckIn = '2017-06-25';
$p->request->dtCheckOut = '2017-06-28';
$quote = $client->GetCancellationPolicies($p);
actually i am getting error.which is mentioned below.
Error Details:
SOAP-ERROR: Encoding: object has no 'nResId' property
i'm new in web services it would be great if someone could help me out of it.
from the wsdl, you should generate the corresponding PHP sdk using a WSDL to php generator such as the PackageGenerator project as you won't wonder how to construct the request, in addition, it'll ease you handling the response as everything is OOP
I'm having trouble creating the right SOAP call in PHP. I've tested the following call in SOAP UI and it works, but I've tried everything from creating objects, arrays and SOAPHeaders and I can't seem to get the right call. Here is the request that works in SOAP UI:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="com.dtn.aghost.API.subscriptions">
<soapenv:Header>
<com:ServiceCredentials>
<usernamePasswordCombo>
<username>[username]</username>
<password>[password]</password>
</usernamePasswordCombo>
</com:ServiceCredentials>
</soapenv:Header>
<soapenv:Body>
<com:SubscriptionServiceIdList>
<visible>1</visible>
</com:SubscriptionServiceIdList>
</soapenv:Body>
</soapenv:Envelope>
Thanks!
I had some questions as your request has very little information regarding what you've already tried. I suggest you add some of the code that you have attempted to use and some of the resources you've looked at to get that information. In addition it would help to answer your request if you described the results of what you tried. Such as were there errors if so what errors did you see?
A good place to look to get examples of PHP code connecting to a SOAP web service would be the PHP documentation about the Soap Client.
In the comments of that page you will find examples of code that others have used. You may be adapt that to use that for your purposes.
As for an example of code connecting to a SOAP web service
<?php
$http_client = 'http://example.com/MyService.asmx?wsdl';
$client = new SoapClient($http_client, array(
'style' => SOAP_DOCUMENT,
'use' => SOAP_LITERAL,
'soap_version'=>SOAP_1_1,
'trace' => 1,
'connection_timeout' => 300));
$params = array( 'username' => $user_name, 'password' => $password);
$results = $client->myFunction($params);
// Debug code can be added after this
?>
Another thing that you will need to do is debug the results of the request. In the example above it sets the value of trace to 1. This allows you to debug the SOAP request that has taken place. You can do that with the following code.
// Debug code
echo $client->__getLastRequestHeaders();
echo $client->__getLastRequest()
echo $client->__getLastResponseHeaders();
echo $client->__getLastResponse();
PHP SoapClient getLastResponse
Last of all you can use is_soap_fault to determine if the request failed. There are some good code examples on the PHP documentation for getting the error code of what happened.
I'm using Zend_Soap_Client object for sending a soap request to another application here is the format of the XML that it's sending to the server:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="urllocation" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://www.w3.org/2003/05/soap-encoding"><env:Body><ns1:isAccountActive env:encodingStyle="http://www.w3.org/2003/05/soap-encoding"><param0 xsi:type="xsd:string">thisisatest</param0></ns1:isAccountActive></env:Body></env:Envelope>
I'm using it on the other SOAP servers that I have and seems to work fine but one of the server returned a response "Invalid XML" that is why I'm really wondering why it won't work on that server alone. Any ideas would be greatly appreciated.
Additional Details:
I've tried to commentout the code that calls the method from the Server here is the code:
$client = new Zend_Soap_Client(null,
array(
'uri'=>'http://'.$user->customconfigs['alumniuri'],
'encoding'=>'UTF-8',
'location'=>'http://'.$user->customconfigs['alumnilocation']
)
);
echo "Location: {$user->customconfigs['alumnilocation']} - uri: {$user->customconfigs['alumniuri']}";
$alumniactive = $client->isAccountActive($token);
upon commenting out:
$alumniactive = $client->isAccountActive($token);
the error disappeared.This is the same codes from my other applications and it's working fine from there.
After a long search for the answer to this question I finally found the problem... this code is actually located on a joomla component which I was using the uri same as what I have from the location that would include a character "&" which is illegal on xml standards removing these character from my xml will then cause the SOAP server to accept the request as valid. :)
I haven't done any xml projects, so I'm not quite sure what to do with this data...
I'm using curl to make a request to salesforce, and they give me back a response that I need to parse. I want to use simplexml. Here's part of the response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<loginResponse>
<result>
<metadataServerUrl>
https://na6-api.salesforce.com/services/Soap/m/18.0/
</metadataServerUrl>
<passwordExpired>
false
</passwordExpired>
<sandbox>
false
</sandbox>
<serverUrl>
https://na6-api.salesforce.com/services/Soap/u/18.0/
</serverUrl>
<sessionId>
!AQ4AQLtDIqY.
</sessionId>
<userId>
</userId>
<userInfo>
<accessibilityMode>
false
</accessibilityMode>
<currencySymbol>
$
</currencySymbol>
<orgDefaultCurrencyIsoCode>
USD
</orgDefaultCurrencyIsoCode>
<orgDisallowHtmlAttachments>
false
</orgDisallowHtmlAttachments>
<orgHasPersonAccounts>
false
</orgHasPersonAccounts>
<organizationId>
</organizationId>
<organizationMultiCurrency>
false
</organizationMultiCurrency>
<organizationName>
Ox
</organizationName>
<profileId>
sdfgsdfg
</profileId>
<roleId>
sdfgsdfg
</roleId>
<userDefaultCurrencyIsoCode xsi:nil="true"/>
<userEmail>
####gmail.com
</userEmail>
<userFullName>
### ###
</userFullName>
<userId>
asdfasdf
</userId>
<userLanguage>
en_US
</userLanguage>
<userLocale>
en_US
</userLocale>
<userName>
asdfasdf#gmail.com
</userName>
<userTimeZone>
America/Chicago
</userTimeZone>
<userType>
Standard
</userType>
<userUiSkin>
Theme3
</userUiSkin>
</userInfo>
</result>
</loginResponse>
</soapenv:Body>
</soapenv:Envelope>
Anyway, I expected to feed that stuff (we'll call it data) into
$results = simplexml_load_string($data);
var_dump($results);
And that would give me all the data back... and then to access specific parts, it would be $results->body->loginResponse->blah->blah...
But It's not giving me that, it's not really giving me anything back, just an empty simple xml object...
So one website made me think I might need an XSLT to read this correctly.
Or something else made me think it's because I don't have at the top.
Help!
You can use SimpleXML but it's not quite as simple as you hope due to the use of namespaces (e.g. soapenv). Look into using SimpleXMLElement::children like:
$sxe = new SimpleXMLElement($data);
$login_response = $sxe->children('soapenv', TRUE)->Body->children('', TRUE)->loginResponse->result;
// Now that we have the <loginResponse> lets take a look at an item within it
echo $login_response->userInfo->userEmail;
Finally, and importantly, have you had a look at salesforce's tools & examples?
SimpleXML needs a special treatment for namespaced XML (ref.)
Mate,
Name spaces usually require you to make a call using children to return the namespaced elements. I would recommend using a soap client like php soapclient, but since I've never used it before there is one other possible option.
$results = simplexml_load_string($data);
$xml = $results->children('http://schemas.xmlsoap.org/soap/envelope/');
var_dump($xml);
I believe that's how it works.
For what it's worth, you may find you have an easier time using a PHP SoapClient for this task. O'Reilly has a good tutorial on PHP SOAP.
Also checkout the PHP Toolkit for making SOAP calls to Salesforce.com
I try to follow the syntax by salathe. But children('soapenv', TRUE) doens't work for me, Jason's children('http://schemas.xmlsoap.org/soap/envelope/') work.
Therefore, to read the field value CreatedDate in Salesforce Outbound Message, I need following code:
$rcXML->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children('http://soap.sforce.com/2005/09/outbound')->notifications->Notification->sObject->children('urn:sobject.enterprise.soap.sforce.com')->CreatedDate
To help you understand how it work, I write a post with sames code and xml which shall be easier to understand.
http://amigotechnotes.wordpress.com/2013/11/16/parse-xml-with-namespace-by-simplexml-in-php/
Parsing soap responses with SimpleXML has a brilliant and concise example of multi-namespace XML parsing.
For anyone wanting to get at the RateResponse from the UPS Rating API, here's how :
// $client is your SoapClient object
$dom = new DOMDocument;
$dom->loadXML($client->__getLastResponse());
$xml = simplexml_load_string($dom->saveXML(), NULL, NULL, 'http://schemas.xmlsoap.org/soap/envelope/');
$RateResponse = $xml->xpath('/soapenv:Envelope/soapenv:Body')[0]->children('rate', true)->RateResponse;
foreach($RateResponse->RatedShipment as $RatedShipment) {
print_r((array)$RatedShipment);
}
For SAOP request, we can parse easily with a short code by replacing the SOAP-ENV: tag with blank
$response = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>';
$response = html_entity_decode($response);
$response = str_replace(['soapenv:', 'ns1:', ':ns1', 'SOAP-ENV:'], ['', '', '', ''], $response);
$objXmlData = simplexml_load_string($response);
I'm trying to use a webservice which only allows SOAP request
as far as I know I must create a request that looks like this
<?xml version="1.0" encoding="utf-8"?>
<SessionCreateRQ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<POS>
<Source PseudoCityCode="SECRET_CODE" />
</POS>
</SessionCreateRQ>
however while adding the parameter to SessionCreateRQ method I don't know how to add the POS parameter called Source and have no clue on how to set the attribute for that parameter
im trying the following in php
$body = array(
'POS' => array('source' => 'PseudoCityCode:SECRET_CODE'));
try
{
$result = $c->SessionCreateRQ($body);
}
but no luck, does anyone has a clue on how should I construct this call properly ?
thanks !
Firstly you need WSDL definition for this service (online or in local file). Any not bad SOAP service provide WSDL to users.
Secondly you need translate WSDL service definition to PHP-code. Try wsdl2php generator. Its generate file with classes, that making calls to web-services.
Your example will be approximately as follows:
require_once 'GeneratedTypes.php';
$client = new SOAPService();
$res = $client->SessionCreateRQ(SECRET_CODE);
p.s. wsdl2php not ideal but it is working :)