Nusoap php request is empty - php

I am trying to populate a request using nusoap and php 5.3. Everything I have tried has left me with an empty request. Where am I going wrong?
This is what i'm trying to create…
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance">
<soap:Header>
<CardSoapHeader xmlns="https://service.pct.com/">
<Username>username</Username>
<Password>password</Password>
<Account>account</Account>
</CardSoapHeader>
</soap:Header>
<soap:Body>
<AddressLookup xmlns="https://service.pct.com/">
<request>
<CompanyReferenceGuid>00000000-0000-0000-0000</CompanyReferenceGuid>
<AdminUserIdentifier>00000000-0000-0000-0000</AdminUserIdentifier>
<MirrorRequest>false</MirrorRequest>
<Surname>surname</Surname>
<Postcode>postcode</Postcode>
<HouseName>1</HouseName>
<AuthenticateCardApplicants>false</AuthenticateCardApplicants>
</request>
</AddressLookup>
</soap:Body>
</soap:Envelope>
This is my php…
<?php
require_once('./soap/lib/nusoap.php');
$client = new nusoap_client('https://uat.service.efirstcard.co.uk/v3_1/SignupService.asmx?wsdl', 'wsdl');
$requestArray[] = array(
/*
'CardSoapHeader' => array('Username' => 'username',
'Password' => 'password',
'Account' => 'account'),
*/
'CompanyReferenceGuid' => '00000000-0000-0000-0000',
'AdminUserIdentifier' => '00000000-0000-0000-0000',
'MirrorRequest' =>'false',
'Surname' =>'surname',
'Postcode' =>'postcode',
'HouseName' =>'1',
'AuthenticateCardApplicants' =>'false');
// Doc/lit parameters get wrapped
$result = $client->call('AddressLookup', array('request' => array($requestArray)));
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
And this is what it generates…
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns9681="http://tempuri.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<AddressLookup xmlns="https://service.pct.com/">
<request></request>
</AddressLookup>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Related

How do I access XML Data

I am using PHP to connect to a SOAP API using GuzzleHttp.
Code
$client = new Client();
$headers = [
'Host' => 'server',
'Content-Type' => 'application/soap+xml; charset=utf-8',
'SOAPAction' => 'action'
];
$body = '<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetInventoryStatus xmlns="action">
<Credentials>
<Username></Username>
<Password></Password>
</Credentials>
<MaterialCode>' . $_GET['matcode'] . '</MaterialCode>
</GetInventoryStatus>
</soap12:Body>
</soap12:Envelope>';
$request = new Request('POST', 'web service here', $headers, $body);
$res = $client->sendAsync($request)->wait();
$xml1 = ($res->getBody());
After running the API, I get the result back in text but upon viewing the source code the below XML is getting returned back
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetInventoryStatusResponse
xmlns="http://localhost/EnterpriseWebService/Enterprise Connect">
<GetInventoryStatusResult>
<MaterialCode>10029</MaterialCode>
<MaterialDescription>12 PT TANGO C2S</MaterialDescription>
<QuantityOnHand>138000.00</QuantityOnHand>
<QuantityAllocated>20400.00</QuantityAllocated>
<QuantityAvailable>117600.00</QuantityAvailable>
<QuantityOnOrder>0.00</QuantityOnOrder>
<QuantityInProduction>0.00</QuantityInProduction>
<ReorderQuantity>0.00</ReorderQuantity>
<ReorderLevel>0.00</ReorderLevel>
<DesiredLevel>0.00</DesiredLevel>
</GetInventoryStatusResult>
</GetInventoryStatusResponse>
</soap:Body>
</soap:Envelope>
If I echo the $xml1, I get everything in text format.
How do I access the variables through the XML?
You need to parse it. I have used DOMDocument but one could use other techniques.
<?php
$str = '<' . '?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetInventoryStatusResponse
xmlns="http://localhost/EnterpriseWebService/EnterpriseConnect">
<GetInventoryStatusResult>
<MaterialCode>10029</MaterialCode>
<MaterialDescription>12 PT TANGO C2S</MaterialDescription>
<QuantityOnHand>138000.00</QuantityOnHand>
<QuantityAllocated>20400.00</QuantityAllocated>
<QuantityAvailable>117600.00</QuantityAvailable>
<QuantityOnOrder>0.00</QuantityOnOrder>
<QuantityInProduction>0.00</QuantityInProduction>
<ReorderQuantity>0.00</ReorderQuantity>
<ReorderLevel>0.00</ReorderLevel>
<DesiredLevel>0.00</DesiredLevel>
</GetInventoryStatusResult>
</GetInventoryStatusResponse>
</soap:Body>
</soap:Envelope>';
// $xml = simplexml_load_string($str);
$xml = new DOMDocument();
$xml->loadXML($str);
$xpath = new DOMXpath($xml);
$nodes = $xpath->query('//*');
$names = array();
foreach ($nodes as $node)
{
$names[] = [
'name' => $node->nodeName,
'value' => $node->textContent,
];
}
print_r($names);

Fetching Data Using SOAPUI work but Unable to get data using PHP . Why?

I am Trying to get the same data which I got using SOAPUI in PHP as I can't export in PHP.
See My WSDL file. The function I am calling is AUXTableAdminstration.
If I am fetching the whole table the PHP code works but if I use anything between <web:xDoc> </web:xDoc> then I am having trouble.
Input SOAP Request in SOAPUI
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webcominc.com/">
<soapenv:Header/>
<soapenv:Body>
<web:AUXTableAdministration>
<!--Optional:-->
<web:userName>UserName</web:userName>
<!--Optional:-->
<web:password>Password</web:password>
<!--Optional:-->
<web:action>EXPORTROWS</web:action>
<!--Optional:-->
<web:tableName>ContactData</web:tableName>
<web:xDoc>
<Root>
<Columns>
<Column>ContactInternalId</Column>
<Column>ContactName</Column>
</Columns>
<SearchCriteria>
<Value>12345</Value>
<Value>TestName</Value>
</SearchCriteria >
</Root>
</web:xDoc>
</web:AUXTableAdministration>
</soapenv:Body>
</soapenv:Envelope>
I am searching the row values using the above Request
OUTPUT for SOAPUI
<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>
<AUXTableAdministrationResponse xmlns="http://webcominc.com/">
<AUXTableAdministrationResult>
<Result>
<Status>OK</Status>
<Message>action 'EXPORT' for ContactData succeeded</Message>
<Root>
<Columns>
<Column>CpqTableEntryId</Column>
<Column>ContactInternalId</Column>
<Column>ContactName</Column>
<Column>CustomerInternalId</Column>
<Column>Company</Column>
</Columns>
<Rows>
<Row>
<Value>1234</Value>
<Value>1234</Value>
<Value>Test Value</Value>
<Value>86392</Value>
<Value>Erin Test2</Value>
</Row>
</Rows>
</Root>
</Result>
</AUXTableAdministrationResult>
</AUXTableAdministrationResponse>
</soap:Body>
</soap:Envelope>
PHP file I am using with WSDL:
<?php
header('Content-Type: application/xml; charset=utf-8');
ini_set('soap.wsdl_cache_enable', '0');
$username ="username";
$password = "password";
$action = "EXPORTROWS";
$tablename= "ContactData";
$xml ="<Root><Columns><Column>ContactInternalId</Column><Column>ContactName</Column></Columns><SearchCriteria><Value>86393</Value><Value>Erin Hensz</Value></SearchCriteria></Root>";
$parameters= array('userName' => $username,'password' => $password,'action' => $action,'tableName' => $tablename,xDoc => $xml);
$options = array('soap_version'=>SOAP_1_1,'exceptions'=>true,'trace'=>1,'cache_wsdl'=>WSDL_CACHE_NONE);
$client = new SoapClient('https://sandbox.webcomcpq.com/wsAPI/wssrv.asmx?WSDL' , $options);
$data = $client->AUXTableAdministration($parameters);
echo $result= $client->__getLastResponse();
?>
PHP OUTPUT
<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>
<AUXTableAdministrationResponse xmlns="http://webcominc.com/">
<AUXTableAdministrationResult>
<Result xmlns="http://webcominc.com/">
<Status>NOK</Status>
<Message>EXPORTROWS failed</Message>
<Error>
<ErrorCode>100000</ErrorCode>
<Description>
Object reference not set to an instance of an object.
</Description>
</Error>
</Result>
</AUXTableAdministrationResult>
</AUXTableAdministrationResponse>
</soap:Body>
</soap:Envelope>

PHP SOAP:How to get param inside xml header and body tag

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"

SOAP PHP is converting '<' to '<'

Our SOAP request doesn't work because it seems that SOAP is converting our XML string into < and >
$client = new SoapClient("https://some-test-url/xxx.asmx?wsdl", array('trace' => true) );
$soapparams = array (
"UserName" => 'uname',
"Password" => 'pword',
"GroupID" => 1,
"xmlstring" => '
<![CDATA[
<DocumentElement>
<tbl>
<var1>Q</var1>
<var2>W</var2>
<var3>E</var3>
</tbl>
</DocumentElement>
]]>
'
);
$response = $client->__soapCall('functionHere', array($soapparams));
$raw_request_header = $client->__getLastRequestHeaders();
$raw_request_body = $client->__getLastRequest();
$raw_response_body = $client->__getLastResponse();
echo "<br /><br />Raw Request: ";
echo "<code>";
print htmlentities($raw_request_body);
echo "</code>";
Im getting this:
<?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:functionHere>
<ns1:UserName>uname</ns1:UserName>
<ns1:Password>pword</ns1:Password>
<ns1:GroupID>1</ns1:GroupID>
<ns1:xmlstring>
<![CDATA[
<DocumentElement>
<tbl>
<var1>Q</var1>
<var2>W</var2>
<var3>E</var3>
</tbl>
</DocumentElement>
]]>
</ns1:xmlstring>
</ns1:functionHere>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
How can I prevent this to happen? I hope someone can help us with this.

Print specific element consuming SOAP with XML

I'm using the integrated SOAP client in PHP 5.3 and I've tested with this web service: http://www.webservicex.net/globalweather.asmx
I'm calling this method 'GetWeather' and the XML request looks like this:
<?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>
<GetWeather xmlns="http://www.webserviceX.NET">
<CityName>string</CityName>
<CountryName>string</CountryName>
</GetWeather>
</soap:Body>
</soap:Envelope>
and response XML is like this:
<?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>
<GetWeatherResponse xmlns="http://www.webserviceX.NET">
<GetWeatherResult>string</GetWeatherResult>
</GetWeatherResponse>
</soap:Body>
</soap:Envelope>
So far I'm getting successfully the array with this code:
<?php
$client = new SoapClient('http://www.webservicex.net/globalweather.asmx?WSDL');
$result = $client->GetWeather(array('CityName' => 'Barcelona', 'CountryName' => 'Spain'));
print_r ($result);
How can I print specific element, let's say the value of the CityName?
So when I want to print the city like this:
echo '<div> ' . $city . '</div>';
How do I get the value of the CityName?

Categories