PHP SoapServer - Change SOAP-ENV to soapenv - php

I am creating a SoapServer side in php. Someone makes a request and the server responds with an xml.
I've been asked to change the response envelope from SOAP-ENV to soapenv.
This is how it's looking now:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://testing.bonusfarma.com.ar/api/serverSideSoap" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
...
</SOAP-ENV:Envelope>
This is how it has to be:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://testing.bonusfarma.com.ar/api/serverSideSoap" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
...
</soap:Envelope>
I've been trying to change the soap version because I read that it is what defines the envelope but it doesn't seem to work. The change is supposed to be just a parameter:
$server = new SoapServer(null, array(
'location' => 'xxxxx'
'uri' => 'xxxxx'
'soap_version' => SOAP_1_2 // not working
)
);
Have any idea about what's generating the SOAP-ENV and what can I do to change it?

Related

Using PHP SOAP client on .NET web service

I am trying to consume a .NET SOAP service but I'm currently just getting a 'false' response.
Visiting the service endpoint tells me the following:
The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SendData xmlns="http://tempuri.org/">
<myObj>string</myObj>
</SendData>
</soap:Body>
</soap:Envelope>
But when I check my request, it is sending the following:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body>
<ns1:SendData>
<ns1:myObj>My data</ns1:myObj>
</ns1:SendData>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
So we can see that my request has different nodes titles and also adds in "ns1:" to the parameters.
Here is my (brief) PHP
$soap = new SoapClient('wsdl.xml', array("trace" => 1, "exception" => 1));
$call = $soap->__soapCall("SendData", array("SendData" => array("myObj" => "My data")));
So my question is: Could this difference in request schema be responsible for the request failing or is this just another way of writing the same thing? If it is responsible, is it possible to write my request exactly as specified at the endpoint?
It is the same thing.
In the given example <SendData xmlns="http://tempuri.org/"> is without namespace prefix (the ns1 in your own request) so default prefix is used, and it specifies it with xmlns attribute for itself and its descendants.
In your request ns1 namespace prefix is defined using xmlns:ns1="http://tempuri.org/" and used in <ns1:SendData>.

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!

PHP SOAP Request Attributes not created properly

I am trying to create a SOAP request in PHP using NUSOAP,
require_once('lib/nusoap.php');
$client = new nusoap_client('wsdl_link', true);
The structure of the request i want to generate is:
<rootlevel att1="abc" att2="def" >
<Start>
</Start>
</rootlevel >
The parameters are as follows:
$params=array('att1'=>'abc',
'att2'=>'def',
'start'=>array(/*array defined here*/));
$result = $client->call('function_name', array('rootlevel' => $params));
But with the request generated is as follows:
<?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/" xmlns:ns4439="http://tempuri.org">
<SOAP-ENV:Body>
<rootlevel xmlns="http://site/01">
<start>
</start>
</rootlevel>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Kindly tel me why my attributes are getting replaced by xmlns..
Edit:
I was going through my wsdl:
In the wsdl, the tag rootlevel is defined as ref="tns:rootlevel" and attributes are defined under name=rootlevel which is somewhere else in the wsdl.
For some of the attributes the request is coming proper(here the tag is defined as name and the attributes are under this tag.). but some are being replaced by xmlns.. Please let me know where im going wrong.
I solved my problem using the "send" function of NUSOAP.. Here u dont have to create an array and all.. The request can be sent in the XML format itself as follows:
$params="<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/" xmlns:ns4439="http://tempuri.org">
<SOAP-ENV:Body>
<rootlevel xmlns="http://site/01">
<start>
</start>
</rootlevel>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>";
$result = $client->send($params, 'wsdl_url/function',0,$timeout);
Hope this Helps You.. :)

Forming DoubleClick for Publishers Soap Requests without a library in PHP

I'm stuck developing in an environment where I cannot use the PHP DFP library. I'm using PHP's SoapClient and I'm having trouble forming the headers correctly for SOAP requests. Here's the example:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<ns1:RequestHeader
soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
soapenv:mustUnderstand="0"
xmlns:ns1="https://www.google.com/apis/ads/publisher/v201308">
<ns1:authentication xsi:type="ns1:ClientLogin" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ns1:token>SuchALongToken</ns1:token>
</ns1:authentication>
<ns1:networkCode>123456</ns1:networkCode>
<ns1:applicationName>DfpApi-Java-2.1.0-dfp_test</ns1:applicationName>
</ns1:RequestHeader>
</soapenv:Header>
<soapenv:Body>
<getAdUnitsByStatement xmlns="https://www.google.com/apis/ads/publisher/v201308">
<filterStatement>
<query>WHERE parentId IS NULL LIMIT 500</query>
</filterStatement>
</getAdUnitsByStatement>
</soapenv:Body>
</soapenv:Envelope>
It's the Authentication section that's getting me. Not sure how to set the internal params (type and xsd) and create the 'token' child.
$header_params = new stdClass();
$header_params->networkCode = self::$network_code;
$header_params->applicationName = $app_name;
$header_params->authentication = array('token' => $this->auth_token);
$headers = new SoapHeader(self::getNamespace(), 'RequestHeader', $header_params);
This gets me the following:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://www.google.com/apis/ads/publisher/v201308">
<SOAP-ENV:Header>
<ns1:RequestHeader>
<ns1:networkCode>########</ns1:networkCode>
<ns1:applicationName>Get Companies By Filter</ns1:applicationName>
<ns1:authentication />
</ns1:RequestHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getCompaniesByStatement>
<ns1:filterStatement />
</ns1:getCompaniesByStatement>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Looks like wsdl is rejecting my authentication as well as my filterStatement. I'd be happy to get the authentication working at the moment. This request give me an 'Unmarshalling' error.
Any help would be much appreciated!

Php soap service evenlope <return> element

I am trying to build a web service to a specification of a 3rd party who will be connecting to it as a client, the service must be written in PHP but I am a total PHP n00b so struggling a little. Basically my responses are being wrapped in a element however the client is not accepting my responses because of this, here is an example.
service.php
<?php
class MyService {
public function Ping() {
return date('d/m/Y H:i:s');
}
}
$server = new SoapServer(null, array( 'soap_version' => SOAP_1_2, 'encoding' => 'UTF-8', 'uri' => 'http://tempuri.org/'));
$server->setClass("MyService");
$server->handle();
?>
Request
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:Ping />
</soapenv:Body>
</soapenv:Envelope>
Response
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" 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:PingResponse>
<return xsi:type="xsd:string">18/11/2010 18:51:02</return>
</ns1:PingResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
What the client is expecting is the PingResponse to just contain the date but without the wrapped around the outside. How can I get the PHP SoapClient to do this?
E.g.
<ns1:PingResponse>18/11/2010 18:51:02</ns1:PingResponse>
I don't think you can, I think this is written into the core of SOAP so it's something your client will have to work around. If they're already getting the contents of PingResponse I can't see it being much more difficult for them to go 1 tree deeper into the response.

Categories