I have to make a SOAP request but I'm facing some problems because using SoapClient I can't get the same XML that is supposed.
This is the correct xml request
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header>
<wsse:Security
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Username>10983</wsse:Username>
<wsse:Password>test2019</wsse:Password>
<Context>10000Hoteis</Context>
</wsse:Security>
</soap-env:Header>
<soap-env:Body>
<OTA_ReadRQ xmlns:ns="http://www.opentravel.org/OTA/2003/05/common"
xmlns="http://www.opentravel.org/OTA/2003/05" TimeStamp="2015-07-16T06:38:10.60">
<ReadRequests>
<HotelReadRequest>
<TPA_Extensions>
<RequestType>GetCities</RequestType>
<CountryCode>PT</CountryCode>
</TPA_Extensions>
</HotelReadRequest>
</ReadRequests>
</OTA_ReadRQ>
</soap-env:Body>
</soap-env:Envelope>
And this is my current php code
$xmlheader = <<<XML
<wsse:Security
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Username>myusername</wsse:Username>
<wsse:Password>mypassword</wsse:Password>
<Context>10000Hoteis</Context>
</wsse:Security>
XML;
$xmlbody = <<<XML
<OTA_ReadRQ xmlns:ns="http://www.opentravel.org/OTA/2003/05/common"
xmlns="http://www.opentravel.org/OTA/2003/05" TimeStamp="2015-07-16T06:38:10.60">
<ReadRequests>
<HotelReadRequest>
<TPA_Extensions>
<RequestType>GetCities</RequestType>
<CountryCode>PT</CountryCode>
</TPA_Extensions>
</HotelReadRequest>
</ReadRequests>
</OTA_ReadRQ>
XML;
$headerXML = new \SoapVar($xmlheader,XSD_ANYXML);
$body = new \SoapVar($xmlbody,XSD_ANYXML);
$client = new \SoapClient(null, ['location' => 'http://10000hoteis.com.pt/NewAvailabilityServlet/staticdata/OTA2014A', 'uri' =>'http://schemas.xmlsoap.org/soap/envelope/' ,'trace' => true]);
$header = new \SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'Security', $headerXML);
$client->__setSoapHeaders($header);
$result = $client->OTA_ReadRQ($body);
But this don't work because put an extra
<SOAP-ENV:OTA_ReadRQ>
between the body tag and
<OTA_ReadRQ xmlns:ns="http://www.opentravel.org/OTA/2003/05/common"
xmlns="http://www.opentravel.org/OTA/2003/05" TimeStamp="2015-07-16T06:38:10.60">
How can I do this request correctly?
Related
I am trying to figure how to create this soap envelope using soap client
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Header>
<m:sendDataExtraccionTraza
xmlns:m="http://www.mop.cl/controlextraccion/xsd/datosExtraccion/SendDataExtraccionRequest">
<m:codigoDeLaObra>OB-0303-204</m:codigoDeLaObra>
<m:timeStampOrigen>2001-12-17T09:30:47Z</m:timeStampOrigen>
</m:sendDataExtraccionTraza>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<m:sendDataExtraccionRequest
xmlns:m="http://www.mop.cl/controlextraccion/xsd/datosExtraccion/SendDataExtraccionRequest">
<m:dataExtraccionSubterranea>
<m:fechaMedicion>17-08-1967</m:fechaMedicion>
<m:horaMedicion>00:01:01</m:horaMedicion>
<m:totalizador>1234567891</m:totalizador>
<m:caudal>12345678.12</m:caudal>
<m:nivelFreaticoDelPozo >12345678.12</m:nivelFreaticoDelPozo >
</m:dataExtraccionSubterranea>
</m:sendDataExtraccionRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Tried making it like this:
$client = new SoapClient($url, array('trace' => 1));
$ns = 'http://www.mop.cl/controlextraccion/xsd/datosExtraccion/SendDataExtraccionRequest';
$headerbody = array('codigoDeLaObra' => POZO_PRUEBA,
'timeStampOrigen' => '2020-01-01T09:30:47Z');
$header = new SOAPHeader($ns, 'sendDataExtraccionTraza', $headerbody);
$client->__setSoapHeaders($header);
$args = array( "fechaMedicion" => "10-10-2020",
"horaMedicion" => "10:01:01",
"totalizador" => "1234567891",
"caudal" => "12345678.12",
"nivelFreaticoDelPozo" => "12345678.12"
);
$res = $client->__soapCall('sendDataExtraccionOp', [
new SoapParam("10-10-2020", "fechaMedicion"),
new SoapParam("10:01:01", "horaMedicion"),
new SoapParam("1234567891", "totalizador"),
new SoapParam("12345678.12", "caudal"),
new SoapParam("1", "nivelFreaticoDelPozo")]);
I am getting an error as result, so i've managed to htmlentities the $client->__getLastRequest() and seeing this outcome
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.mop.cl/controlextraccion/xsd/datosExtraccion/SendDataExtraccionRequest">
<SOAP-ENV:Header>
<ns1:sendDataExtraccionTraza>
<ns1:codigoDeLaObra>OB-0202-251</ns1:codigoDeLaObra>
<ns1:timeStampOrigen>2020-01-01T09:30:47Z</ns1:timeStampOrigen>
</ns1:sendDataExtraccionTraza>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:sendDataExtraccionRequest/>
<horaMedicion>10:01:01</horaMedicion>
<totalizador>1234567891</totalizador>
<caudal>12345678.12</caudal>
<nivelFreaticoDelPozo>1</nivelFreaticoDelPozo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I am missing a <m:dataExtraccionSubterranea> parent inside the senddataExtraccionRequest, and i can't figure how to create it.
Any hint?
How do i create this specific xml output by SOAP using SoapHeader and __setSoapHeaders? I can't do the same XML like i want. i don't want this ns1 and ns2 in envelope tag, and in header i need this Action SOAP-ENV:mustUnderstand="1" ...
This is my code:
try{
$client = new SoapClient('https://thesite.com.br/wcf/SvcContratos.svc?wsdl', array('trace' => 1,'use' => SOAP_LITERAL));
$usuario='user_1';
$senha='1234';
$tipo='1';
$header = new SoapHeader("http://schemas.microsoft.com/ws/2005/05/addressing/none","Action", "http://tempuri.org/ISvcContratos/GerarToken");
$client->__setSoapHeaders($header);
$params = new SoapVar("<objLogin xmlns:d4p1='http://schemas.datacontract.org/2004/07/EPFWeb.Repository.Default.WCF' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'><d4p1:DsSenha>".$senha."</d4p1:DsSenha><d4p1:DsUsuario>".$usuario."</d4p1:DsUsuario><d4p1:IdTipoConsulta>".$tipo."</d4p1:IdTipoConsulta></objLogin>", XSD_ANYXML);
$data = $client->GerarToken($params);
echo $client->__getLastRequest();
}catch(SoapFault $fault){
echo $client->__getLastRequest()."<br>".$fault->getMessage();
}
With this php code i had this wrong XML:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:ns2="http://schemas.microsoft.com/ws/2005/05/addressing/none">
<SOAP-ENV:Header>
<ns2:Action>http://tempuri.org/ISvcContratos/GerarToken</ns2:Action>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<GerarToken>
<objLogin xmlns:d4p1='http://schemas.datacontract.org/2004/07/EPFWeb.Repository.Default.WCF' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
<d4p1:DsSenha>1234</d4p1:DsSenha>
<d4p1:DsUsuario>user_1</d4p1:DsUsuario>
<d4p1:IdTipoConsulta>1</d4p1:IdTipoConsulta>
</objLogin>
</GerarToken>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I need to send this XML by soap:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/ISvcContratos/GerarToken</Action>
</s:Header>
<s:Body>
<GerarToken xmlns="http://tempuri.org/">
<objLogin xmlns:d4p1="http://schemas.datacontract.org/2004/07/EPFWeb.Repository.Default.WCF" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<d4p1:DsSenha>1234</d4p1:DsSenha>
<d4p1:DsUsuario>USER_1</d4p1:DsUsuario>
<d4p1:IdTipoConsulta>1</d4p1:IdTipoConsulta>
</objLogin>
</GerarToken>
</s:Body>
</s:Envelope>
well, finally I got an affirmative answer from the server, which opens the doors for me now to try to consume the wsdl follows below the code that I used to solve the problem:
try{
$client = new SoapClient('https://thesite.com.br/wcf/SvcContratos.svc?wsdl', array('trace' => 1,'use' => SOAP_LITERAL, 'style' => SOAP_DOCUMENT,));
$usuario='user_1';
$senha='1234';
$params = new SoapVar("<GerarToken xmlns='http://tempuri.org/'><objLogin xmlns:d4p1='http://schemas.datacontract.org/2004/07/EPFWeb.Repository.Default.WCF' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'><d4p1:DsUsuario>".$usuario."</d4p1:DsUsuario><d4p1:DsSenha>".$senha."</d4p1:DsSenha><d4p1:IdTipoConsulta>Data</d4p1:IdTipoConsulta></objLogin></GerarToken>", XSD_ANYXML);
$data = $client->GerarToken($params);
$xml = json_decode(json_encode($data),true);
print_r($xml);
echo $client->__getLastRequest();
}catch(SoapFault $fault){
echo $client->__getLastRequest()."<br>".$fault->getMessage();
}
I need to add the following complex header with different namespace and types to my SoapClient Header.
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>****</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">*****</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<wsa:Action>/IntS5/S5WS</wsa:Action>
</soapenv:Header>
As proposed in other answers I tried the following approach in my php project.Since I need WSA Addressing, I set the wsa:Action with security header together.
$header_part = '<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">'
. '<wsse:UsernameToken><wsse:Username>****</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">****</wsse:Password>'
. '</wsse:UsernameToken></wsse:Security><wsa:Action>/IntS5/S5WS</wsa:Action>';
$soap_var_header = new SoapVar($header_part, XSD_ANYXML, null, null, null);
$soap_header = new SOAPHeader('http://www.w3.org/2005/08/addressing', 'wsa', $soap_var_header);
$client->__setSoapHeaders($soap_header);
Some how __soapCall returns me the following error.
SoapFault exception: [Client] DTD are not supported by SOAP.I am not sure if it's related to header or the parameters of the putCall. Anybody can help me ?
EDIT: The problem is probably related with the namespace of the HEADER/Envelope.
The request which is sent to server looks like this.
UPDATED
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://ws.s5.mediasat.de/" xmlns:ns2="http://www.w3.org/2005/08/addressing">
<env:Header>
<wsse:Security env:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>****</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">*****</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">/IntS5/S5WS</wsa:Action>
</env:Header>
<env:Body>
<ns1:putCall>
<transaction>createIncident</transaction>
<transactionSender>Request</transactionSender>
<caseDataModel>
<senderId>7</senderId>
<ticketTypeId>102</ticketTypeId>
<title>test</title>
<priorityId>101</priorityId>
<categoryId>128</categoryId>
<description>Description</description>
<ticketNumberSender>INCC00000743809</ticketNumberSender>
<createTypeId>701</createTypeId>
<serviceId>B001APP05K</serviceId>
<categoryId>128</categoryId>
<serviceRecipientId>77888</serviceRecipientId>
<serviceLocationSAPCode>V135</serviceLocationSAPCode>
</caseDataModel>
</ns1:putCall>
</env:Body>
</env:Envelope>
The request that works on SOAP UI
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.s5.mediasat.de/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>***</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">***</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<wsa:Action>/IntS5/S5WS</wsa:Action>
</soapenv:Header>
<soapenv:Body>
<ws:putCall>
<transaction>createIncident</transaction>
<transactionSender>Request</transactionSender>
<caseDataModel>
<senderId>7</senderId>
<ticketTypeId>102</ticketTypeId>
<title>test</title>
<priorityId>101</priorityId>
<categoryId>128</categoryId>
<description>Description</description>
<ticketNumberSender>INCC00000743809</ticketNumberSender>
<createTypeId>701</createTypeId>
<serviceId>B001APP05K</serviceId>
<categoryId>128</categoryId>
<serviceRecipientId>77888</serviceRecipientId>
<serviceLocationSAPCode>V135</serviceLocationSAPCode>
</caseDataModel>
</ws:putCall>
</soapenv:Body>
</soapenv:Envelope>
Is there anyway to set/override the namespace for the header?
You should generate the header procedurally instead of using the string.
Example:
<?php
$client = new SoapClient(null, array(
'location' => "http://localhost/soap/",
'uri' => "http://ws.s5.mediasat.de/",
'soap_version' => SOAP_1_2
));
$username = '***';
$password = '***';
$sec_namespace = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
$wsa_namespace = 'http://www.w3.org/2005/08/addressing';
// prepare security token
$node1 = new \SoapVar($username, XSD_STRING, null, null, 'Username', $sec_namespace);
$xml = new XMLWriter(); // this is a little hacky, but no other way to set the type as far as I know
$xml->openMemory();
$xml->startElementNS('wsse', 'Password',$sec_namespace);
$xml->writeAttribute('Type', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText');
$xml->Text($password);
$xml->endElement();
$node2 = new \SoapVar($xml->outputMemory(), XSD_ANYXML);
$token = new \SoapVar(array($node1, $node2), SOAP_ENC_OBJECT, null, null, 'UsernameToken', $sec_namespace);
$security = new \SoapVar(array($token), SOAP_ENC_OBJECT, null, null, 'Security', $sec_namespace);
$soap_header_sec = new \SOAPHeader($sec_namespace, 'Security', $security, true);
// prepare action token
$action = new \SoapVar('/IntS5/S5WS', XSD_STRING, null, null, 'Action', $wsa_namespace);
$soap_header_action = new \SOAPHeader($wsa_namespace, 'Action', $action, false);
// set prepared headers
$client->__setSoapHeaders(
[$soap_header_sec,$soap_header_action]
);
$client->putCall();
This will produce the valid envelope with all namespaces set:
<?xml version="1.0" encoding="utf-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://ws.s5.mediasat.de/" xmlns:ns2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns3="http://www.w3.org/2005/08/addressing" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
<env:Header>
<ns2:Security env:mustUnderstand="true">
<ns2:UsernameToken>
<ns2:Username>***</ns2:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">***</wsse:Password>
</ns2:UsernameToken>
</ns2:Security>
<ns3:Action>/IntS5/S5WS</ns3:Action>
</env:Header>
<env:Body>
<ns1:putCall env:encodingStyle="http://www.w3.org/2003/05/soap-encoding" />
</env:Body>
</env:Envelope>
The name space "http://www.w3.org/2005/08/addressing" is not bound to the prefix "wsa".
The "mustUnderstand" attribute must use the prefix "env" not "soapenv".
You can declare the missing namespace locally. You just have to fix you header_part to look like this:
header_part = '<wsse:Security env:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">'
. '<wsse:UsernameToken><wsse:Username>****</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">****</wsse:Password>'
. '</wsse:UsernameToken></wsse:Security><wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">/IntS5/S5WS</wsa:Action>';
Note: Maybe it is obvious but it is kind of dangerous to assume that the prefix for the "http://www.w3.org/2003/05/soap-envelope" will always be "env". The framework can change this at any time. If you want to be on the really safe side you might prefer to bind the namespace locally to a new prefix:
<wsse:Security soapenv:mustUnderstand="1" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" ...
But having one namespace bound to two different prefixes will make things even harder to read and understand so I would say it is a question of taste.
In PHP I need to create a soap-xml request like
<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/">
<SOAP-ENV:Header xmlns:NS1="urn:UCoSoapDispatcherBase" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<NS1:TAuthenticationHeader xsi:type="NS1:TAuthenticationHeader">
<UserName xsi:type="xsd:string">user</UserName>
<Password xsi:type="xsd:string">pass</Password>
</NS1:TAuthenticationHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<NS2:ExecuteRequest xmlns:NS2="urn:UCoSoapDispatcherCustomLink-ICustomLinkSoap">
<ARequest xsi:type="xsd:string">
<?xml version="1.0" encoding="windows-1252"?> <EoCustomLinkRequestDateTime Type="TEoCustomLinkRequestDateTime"></EoCustomLinkRequestDateTime>
</ARequest>
</NS2:ExecuteRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But the problem is to get param in the header (like xmlns:NS1...) and body (like xmlns:NS2...) tags
With my script I get NS1 and NS2 swapped in the first tag after header and body. results in <NS1:TAuthenticationHeader> .... and . </NS2:ExecuteRequest>
My php script:
<?php
$wsdl_url = 'http://xxx.xxx.xxx.xxx:yyyy/wsdl/ICustomLinkSoap';
$location = 'http://xxx.xxx.xxx.xxx:yyyy/soap/ICustomLinkSoap';
$action = 'ExecuteRequest';
$version = SOAP_1_1;
$one_way = 0;
$soapClient = new SoapClient($wsdl_url, array(
'cache_wsdl' => WSDL_CACHE_NONE,
'trace' => true,
'encoding' => 'ISO-8859-1',
'exceptions' => true,
));
$auth = (object)array(
'UserName'=>'xxxx',
'Password'=>'yyyy'
);
$header = new SoapHeader($wsdl_url,'TAuthenticationHeader',$auth,false);
$soapClient->__setSoapHeaders($header);
$request1 = '
<ARequest>
<?xml version="1.0" encoding="windows-1252"?>
<EoCustomLinkRequestDateTime Type="TEoCustomLinkRequestDateTime" xsi:noNamespaceSchemaLocation="GdxEoStructures.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</EoCustomLinkRequestDateTime></ARequest>
';
$xmlVar = new SoapVar($request1, XSD_ANYXML);
$result = $soapClient->__SoapCall(
'ExecuteRequest',
array($xmlVar)
);
// show result in xml-file
$f = fopen("./soap-request2.xml", "w");
xx = serialize($soapClient->__getLastRequest());
fwrite($f, $xx);
?>
Result:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="urn:UCoSoapDispatcherCustomLink-ICustomLinkSoap"
xmlns:ns2="http://xxx.xxx.xxx.xxx:yyy/wsdl/ICustomLinkSoap"
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:Header>
<ns2:TAuthenticationHeader>
<UserName>xxxx</UserName>
<Password>yyyy</Password>
</ns2:TAuthenticationHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:ExecuteRequest>
<ARequest>
<?xml version="1.0" encoding="windows-1252"?>
<EoCustomLinkRequestDateTime Type="TEoCustomLinkRequestDateTime" xsi:noNamespaceSchemaLocation="GdxEoStructures.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</EoCustomLinkRequestDateTime>
</ARequest>
</ns1:ExecuteRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Please help to how to do so?
Eric
But the problem is to get param in the header (like xmlns:NS1...) and
body (like xmlns:NS2...) tags With my script I get NS1 and NS2 swapped
in the first tag after header and body. results in
.... and .
It's not a problem, because swapped not only namespaces of elements but also its definitions at the head of SOAP-ENV:Envelope
Your first xml
xmlns:NS1="urn:UCoSoapDispatcherBase"
xmlns:NS2="urn:UCoSoapDispatcherCustomLink-ICustomLinkSoap"
Compare with generated by php
xmlns:ns1="urn:UCoSoapDispatcherCustomLink-ICustomLinkSoap"
xmlns:ns2="http://xxx.xxx.xxx.xxx:yyy/wsdl/ICustomLinkSoap"
Here's the xml structure that I want to achieve:
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:method>
<auth>
...
</auth>
<data>
...
</data>
</ns1:method>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</XML>
My code:
<?php
$client = new SoapClient(null, array('location' => "http://www.test.com/soap.php",
'uri' => "http://tempuri.org/",
'trace' => true,'exceptions' => true,'cache_wsdl' => WSDL_CACHE_NONE));
$request = new stdClass();
$request->auth = new stdClass();
$request->data = new stdClass();
$client->__soapCall("method", array($request));
Please note: SoapClient doesn't allow me to insert anything other than array in second param to the __soapCall method.
So here's what I'm getting:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:method>
<param0 xsi:type="SOAP-ENC:Struct">
<auth xsi:type="SOAP-ENC:Struct"/>
<data xsi:type="SOAP-ENC:Struct"/>
</param0>
</ns1:method>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
As you can see, php added a root tag for my request - param0. Is there a way I can escape this? I need to have 2 "root" elements in that request parameter. How can I achieve that?
did you try this way : $client->__soapCall("method", $request);?
Thanks all for answering. I solved the issue with the help of SoapParam:
$client->__soapCall("method", array(
new SoapParam($request->auth, "auth"),
new SoapParam($request->data, "data"),
));