I have a working SOAP UI xml, and I have my SOAP request XML and they are almost identical. SOAP UI works, mine gets a null response. Here's the SOAPUI XML first
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:get="http://www.cornerstoneondemand.com/Webservices/GetDetailsWebService">
<soapenv:Header>
<get:AuthHeader>
<get:CorpName>corp</get:CorpName>
<get:UserId>1234</get:UserId>
<get:Signature>ABC123</get:Signature>
</get:AuthHeader>
</soapenv:Header>
<soapenv:Body>
<get:GetDetails xmlns:get="http://www.cornerstoneondemand.com/Webservices/GetDetailsWebService">
<get:object_id>qwerty-123</get:object_id>
</get:GetDetails>
</soapenv:Body>
</soapenv:Envelope>
and here is my PHP code and the request.
$client=new SoapClient($wsdl,array('trace' => 1, 'exception' => 0));
$auth = array(
'CorpName' => $CorpName,
'UserId' => $username,
'Signature' => $Signature
);
$header = new SoapHeader('http://www.cornerstoneondemand.com/Webservices/GetDetailsWebService','AuthHeader',$auth,false);
$client->__setSoapHeaders($header);
$parm[] = new SoapVar($LOid, XSD_STRING, null, null, 'object_id' );
var_dump($client->GetDetails( new SoapVar($parm, SOAP_ENC_OBJECT) )); //output is NULL
//and the PHP request:
print_r($client->__getLastRequest());
output is
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.cornerstoneondemand.com/Webservices/GetDetailsWebService">
<SOAP-ENV:Header>
<ns1:AuthHeader>
<ns1:CorpName>corp</ns1:CorpName>
<ns1:UserId>1234</ns1:UserId>
<ns1:Signature>ABC123</ns1:Signature>
</ns1:AuthHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:GetDetails>
<object_id>qwerty-123</object_id>
</ns1:GetDetails>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I can't tell if I'm close to creating a good request, or miles off. I'm working to make the PHP request match SOAPUI's since it works and mine doesn't.
The contain the nearly same information. Namespace prefixes for element nodes are exchangeable and optional. So all these 3 variants are resolved to and element node with the local name Envelope in the namespace http://schemas.xmlsoap.org/soap/envelope/.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"/>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>
You can read the element name as {http://schemas.xmlsoap.org/soap/envelope/}:Envelope.
The same goes for the get vs ns1 namespaces prefixes. They both resolve to the same actual namespace.
But the element object_id has no namespace in your XML. The sixth argument of the SoapVar constructor is the node namespace so you might want to try:
$namespace = 'http://www.cornerstoneondemand.com/Webservices/GetDetailsWebService';
$parm[] = new SoapVar($LOid, XSD_STRING, null, null, 'object_id', $namespace);
Related
I need to send the following SOAP request using PHP:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sup="url">
<soapenv:Header/>
<soapenv:Body>
<ControlledEnquiryRequest xmlns="url">
<Authentication>
<SubscriberDetails>
<Username>*****</Username>
<Password>***</Password>
</SubscriberDetails>
</Authentication>
<ControlledRequest>
<Asset>
<Name>Tranquility</Name>
</Asset>
<ParameterList/>
<PrimaryProduct>
<Code>Platinum</Code>
</PrimaryProduct>
</ControlledRequest>
</ControlledEnquiryRequest>
</soapenv:Body>
</soapenv:Envelope>
At the moment I've got:
$requestParams = array(
'CustomerCode' => '*****',
'Password' => '***'
);
$client = new SoapClient('url?wsdl');
$response = $client->ControlledEnquiryRequest($requestParams);
print_r($response);
However I'm getting a 500 error. I'm also unsure on how I pass the other Name and product codes through?
Obviously I'm using the actual URL instead of a 'url'. In Soap UI it's getting a result, but I can't get my head around adapting it to PHP.
I wanted to generate the following SOAP header format,
<soapenv:Header>
<SoapHeaderMsg xmlns="http://xyz.com.au">
<opt:UserSoapHeader>
<opt:IdentityName>TEST</opt:IdentityName>
<opt:AuthenticationToken>jjjkjkjkjkjkj</opt:AuthenticationToken>
</opt:UserSoapHeader>
</SoapHeaderMsg>
</soapenv:Header>
So i am using the following php functions to generate this,
$this->__setSoapHeaders(array(
new SoapHeader('http://xyz.com.au', 'SoapHeaderMsg', array(
new SoapHeader('http://xyz.com.au', 'IdentityName', 'TEST'),
new SoapHeader('http://xyz.com.au', 'AuthenticationToken', 'jkjkjkk')
)),
));
Which generates following headers which is completely different to what i wanted above ? how do i generate exact same headers using PHP functions like above ?
<SOAP-ENV:Header>
<ns1:SoapHeaderMsg>
<SOAP-ENC:Struct>
<namespace>http://xyz.com.au</namespace>
<name>IdentityName</name>
<data>TEST</data>
<mustUnderstand>false</mustUnderstand>
</SOAP-ENC:Struct>
<SOAP-ENC:Struct>
<namespace>http://xyz.com.au</namespace>
<name>AuthenticationToken</name>
<data>hjhhjjhjhjhj</data>
<mustUnderstand>false</mustUnderstand>
</SOAP-ENC:Struct>
</ns1:SoapHeaderMsg>
</SOAP-ENV:Header>
array is mostly used on the PHP side, which gets converted to Struct. Can you please try to use object and see if you have any success with it.
$this->__setSoapHeaders(array(
new SoapHeader('http://xyz.com.au', 'SoapHeaderMsg',
(object)array(
'opt:UserSoapHeader' => (object)array(
'opt:IdentityName' => 'TEST',
'opt:AuthenticationToken' => 'jkjkjkk'
)
)),
));
The request looks like below:
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://test.domain.com/"
xmlns:ns2="http://xyz.com.au">
<SOAP-ENV:Header>
<ns2:SoapHeaderMsg>
<opt:UserSoapHeader>
<opt:IdentityName>TEST</opt:IdentityName>
<opt:AuthenticationToken>jkjkjkk</opt:AuthenticationToken>
</opt:UserSoapHeader>
</ns2:SoapHeaderMsg>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
......
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
How can I edit the xmlns attributes of the <SOAP-ENV:Envelope /> tag?
I have a situation where xmlns:xsi and xmlns:xsd are missing. I'd like to know how to add them back in?
Example:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://fedex.com/ws/track/v12">
<SOAP-ENV:Body>
<ns1:TrackRequest>
...
But I need it be this:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://fedex.com/ws/track/v12"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns1:TrackRequest>
...
I know this is kinda old, but in case someone stumbles upon it...
After fiddling around with SoapVar, this is how it worked for me:
$params[] = new SoapVar('',XSD_ANYXML, '', null, 'Envelope', 'http://www.w3.org/2001/XMLSchema');
$params[] = new SoapVar('',XSD_ANYXML, '', null, 'Envelope', 'http://www.w3.org/2001/XMLSchema-instance');
//you can add more vars here.
//E.g. in my case I also needed $params[] = new SoapVar('<notifications xmlns="http://soap.sforce.com/2005/09/outbound"><Ack>true</Ack></notifications>',XSD_ANYXML); as I was working with salesforces soap.
return new SoapVar($params, XSD_ANYXML);
I want to call a function of a web service in my project developed by PHP. This is my code:
$wsdl="http://x.x.x.x:8090/charge/services/Amount?wsdl";
$client = new SoapClient($wsdl) or die("Error");
$chargeAmountArray = array('UserIdentifier' => $number ,
'data' => array(
'description' => array("Channel=test|".$Origin),
'currency' => NULL,
'code' => $code),
'refrence' => $refcode);
$header = new SoapHeader('servicekey', $servicekey);
$client->__setSoapHeaders($header);
$res = $client->__call('chargeAmount',$chargeAmountArray);
return $res->return;
I have seen my xml code with tcpdump and it is like:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.csapi.org/schema/parlayx/payment/amount_charging/v4_0/local" xmlns:ns2="servicekey">
<SOAP-ENV:Header>
<ns2:e0ce5ed56d7c4d60/>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:chargeAmount/>
<param1>
<item>
<key>description</key>
<value>yChannel=test|30733</value>
</item>
<item>
<key>currency</key>
<value/>
</item>
<item>
<key>code</key>
<value>MOBDY</value>
</item>
</param1>
<param2>1PN1mROoZop2hAy</param2>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
As you see the UserIdentifier is not passed and the refrence parameter has no name in the XML.
I see a few errors here.
The constructor signature for the SoapHeader class shows the first parameter is a namespace declaration, which it doesn't appear you are setting.
Also, SoapClient::__call() is deprecated; instead you should call the method directly:
$res = $client->chargeAmount($chargeAmountArray);
SoapClient::__call() expects parameters in an array with key "parameters", which you are not providing.
Finally, you should be doing some error checking with try/catch in case the connection can't be made for whatever reason.
I create an XML document using PHP's XMLWriter.
$xmlWriter = new \XMLWriter();
$xmlWriter->openMemory(); //generate XML in-memory, not on disk
//Please keep the indentation intact to preserve everybody's sanity!
$xmlWriter->startElement('RootElement');
// ...
$xmlWriter->endElement();
$myXml = $xmlWriter->outputMemory(true);
Now I connect to a SOAP service in non-WSDL mode.
$soapClient = new \SoapClient(null, array(
"location" => "https://theservice.com:1234/soap/",
"uri" => "http://www.namespace.com",
"trace" => 1
)
);
$params = array(
new \SoapParam($myXml, 'param')
);
$result = $soapClient->__soapCall('method', $params);
The problem is that the SOAP message received by the SOAP service contains my data as escaped XML characters. (Warning : dummy SOAP message ahead!)
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope" ...>
<SOAP-ENV:Header>
...
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:method>
<Request xsi:type="xsd:string">
<Root>
(escaped data)
</Root>
</Request>
</ns1:method>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The SOAP service will not work with escaped data but, on the other hand, I don't escape my data, the SoapClient does so. How do I make my SoapClient send unescaped data?
Escaping characters is the expected behavior of the XmlWriter::writeElement method.
It took me a while to figure it out but the answer was simple : put a SoapVar with the XSD_ANYXML parameter into the SoapParam :
$params = array(
new \SoapParam(new \SoapVar($myXml, XSD_ANYXML), 'param')
);
The SoapVar documentation mentions that its second parameter (encoding) can be "one of the XSD_... constants" which are not documented in the PHP docs.