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.. :)
Related
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>.
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 < and > 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!
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!
It's my first time using the SOAP API by BetFair I have created one XML file and one file that will call that file. I am not understanding how can I call this and get an output. I have created the XML file below:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<login xmlns="http://www.betfair.com/publicapi/v3/BFGlobalService/">
<request>
<locationId xmlns="">0</locationId>
<username xmlns="">usrname</username>
<password xmlns="">password</password>
<productId xmlns="">18</productId>
<vendorSoftwareId xmlns="">0</vendorSoftwareId>
</request>
</login>
</soap:Body>
</soap:Envelope>
Now to call this file I have also created one php file to do this.
BetFair has given this link for the login api: https://api.betfair.com/global/v3/BFGlobalService.wsdl
<?php
$get_data = file_get_contents("http://pixelonsell.com/dev2/betfair/login.xml");
$b = html_entity_decode($get_data);
$data= urlencode($b);
print_r($data);
$client = new SoapClient("https://api.betfair.com/global/v3/BFGlobalService.wsdl");
$result = $client->LoginReq($data);
print_r($result);
?>
I don't know why it's not working; can you help me out with this? Thank you in advance.
I would avoid using a dedicated SOAP library; in my experience they often don't work because of inconsistencies in the ways different servers implement the SOAP specification. Use a simple HTTP/HTTPS library instead, with the following headers
SOAPAction: urn:login
Content-Length: #{myContentLength}
Content-Type: text/xml
User-Agent: #{myUserAgent}
and the following payload (assuming you're using the Free API):
<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 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">
<SOAP-ENV:Body>
<m:login xmlns:m="https://api.betfair.com/global/v3/BFGlobalService">
<m:request>
<username>#{myUsername}</username>
<password>#{myPassword}</password>
<locationId>0</locationId>
<vendorSoftwareId>0</vendorSoftwareId>
<productId>82</productId>
</m:request>
</m:login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
It looks to me like you're using the wrong namespace for the login element; should be 'https://api.betfair.com/..' not 'http://www.betfair.com/..'.
Good luck.
The format of my SOAP call needs to be:
<?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:FunctionName>
<ns1:HostUserName>hostuser</ns1:HostUserName>
<ns1:HostPassword>pass</ns1:HostPassword>
<ns1:OwnerName>owner</ns1:OwnerName>
<ns1:UserName>user</ns1:UserName>
<ns1:OptionalParam>
<ns1:Parameters>
<ns1:Parameter Name="FirstName">First<ns1:/Parameter>
<ns1:Parameter Name="LastName">Last<ns1:/Parameter>
<ns1:/Parameters>
</ns1:OptionalParam>
<ns1:/FunctionName>
</SOAP-ENV:Body>
How do I represent this in a PHP request?
I build the request like this:
$client = new SoapClient($url,array('trace' => 1));
$data['HostUserName']=$this->hostname;
$data['HostPassword']=$this->hostpassword;
$data['OwnerName']=$this->ownername;
$data['UserName']=$username;
$data['FirstName']=$FirstName;
$data['LastName']=$LastName;
$result = $client->FunctionName($data);
I've tried a few combinations of building arrays, SOAPVAR and SOAPPARAM but nothing has worked.
The target SOAP server is .NET based.
Any suggestions?
Thanks