send xml using nusoap - php

my soap requestformat should look 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>< WsAbcMobileAcctInq xmlns="http://tempuri.org/"><xml_var><HCMSG xmlns="">
<ABC><ABCTRANSID>MOBL</ABCTRANSID></ABC><REF><TXNTYPE>INQ</TXNTYPE><SC_CD>000ACD</SC_CD>
< REFNO>MOBL0000000060018987941MAT</REFNO></REF><FIXPART><TXNDATE>20110105</TXNDATE>
<TXNTIME>11464178</TXNTIME><AGN_CD>000000006001</ AGN_CD ></FIXPART><VARPART>
<AC_NO TYP="N">0000000000008946565</AC_NO>
<IC_NO TYP="N">0008956466546</ IC_NO>
<ID_CD TYP="S">IN</ ID_CD>
</VARPART></HCMSG></xml_var></ WsAbcMobileAcctInq></soap:Body></soap:Envelope>
but the problem is i don't know how to put it using nusoap. here's what i've been doing:
require_once('lib/nusoap.php');
$client = new nusoap_client('http://domain.my/MobileData/Service.asmx', false);
$params = '<?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>< WsAbcMobileAcctInq xmlns="http://tempuri.org/"><xml_var><HCMSG xmlns="">
<ABC><ABCTRANSID>MOBL</ABCTRANSID></ABC><REF><TXNTYPE>INQ</TXNTYPE><SC_CD>000ACD</SC_CD>
< REFNO>MOBL0000000060018987941MAT</REFNO></REF><FIXPART><TXNDATE>20110105</TXNDATE>
<TXNTIME>11464178</TXNTIME><AGN_CD>000000006001</ AGN_CD ></FIXPART><VARPART>
<AC_NO TYP="N">0000000000008946565</AC_NO>
<IC_NO TYP="N">0008956466546</ IC_NO>
<ID_CD TYP="S">IN</ ID_CD>
</VARPART></HCMSG></xml_var></ WsAbcMobileAcctInq></soap:Body></soap:Envelope>';
$answer = $client->call('WsAbcMobileAcctInq', array('WsAbcMobile' => $params), '', 'http://tempuri.org/WsAbcMobileAcctInq');
$error = $client->getError();
if ($error){
print_r($client->response);
print_r($client->getDebug());
print_r($client->getError());
die();
}
and basically i got this error:
HTTP/1.1 500 Internal Server Error Connection: close Date: Thu, 24 Nov 2011 05:47:47 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private Content-Type: text/xml; charset=utf-8 Content-Length: 441 soap:ServerServer was unable to process request. ---> Object reference not set to an instance of an object
any clue?

Related

PHP soap response return with NaN

i'm sorry if the title might misleading, i'm kinda dumb but could you give me a little hint for me.
i'm trying for bmi web service
soap request
POST /webservices/bmiservice.asmx HTTP/1.1
Host: www.beetledev.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.beetledev.com/getBmiValue"
<?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>
<getBmiValue xmlns="http://www.beetledev.com">
<w>double</w>
<h>double</h>
</getBmiValue>
</soap:Body>
</soap:Envelope>
soap response
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?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>
<getBmiValueResponse xmlns="http://www.beetledev.com">
<getBmiValueResult>double</getBmiValueResult>
</getBmiValueResponse>
</soap:Body>
</soap:Envelope>
PHP coding
<?php
require_once "lib/nusoap.php";
$client = new nusoap_client("http://www.beetledev.com/webservices/bmiservice.asmx");
$error = $client->getError();
if ($error) {
echo "<h2>Constructor error</h2><pre>" . $error . "</pre>";
}
$result = $client->call('getBmiValue',array('w' => 62, 'h' =>167),null, 'http://www.beetledev.com/getBmiValue');
if ($client->fault) {
echo "<h2>Fault</h2><pre>";
print_r($result);
echo "</pre>";
}
else {
$error = $client->getError();
if ($error) {
echo "<h2>Error</h2><pre>" . $error . "</pre>";
}
else {
echo "<h2>BMI</h2><pre>";
echo $result;
echo "</pre>";
}
}
echo "<h2>Request</h2>";
echo "<pre>" . htmlspecialchars($client->request, ENT_QUOTES) . "</pre>";
echo "<h2>Response</h2>";
echo "<pre>" . htmlspecialchars($client->response, ENT_QUOTES) . "</pre>";
?>
result
BMI
NaN
Request
POST /webservices/bmiservice.asmx HTTP/1.0
Host: www.beetledev.com
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=UTF-8
SOAPAction: "http://www.beetledev.com/getBmiValue"
Content-Length: 476
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="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" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><getBmiValue><w xsi:type="xsd:int">62</w><h xsi:type="xsd:int">167</h></getBmiValue></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/8.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Sun, 27 Apr 2014 14:26:40 GMT
Connection: close
Content-Length: 364
<?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><getBmiValueResponse xmlns="http://www.beetledev.com"><getBmiValueResult>NaN</getBmiValueResult></getBmiValueResponse></soap:Body></soap:Envelope>
i dont know where i do wrong, i'm hoping for a little hint
Thank you
i found the solution to my problem
first
$client = new nusoap_client("http://www.beetledev.com/webservices/bmiservice.asmx");
change to
$client = new nusoap_client('http://www.beetledev.com/webservices/bmiservice.asmx?WSDL',TRUE);
second
$result = $client->call('getBmiValue',array('w' => 62, 'h' =>167),null, 'http://www.beetledev.com/getBmiValue');
change to
$result = $client->call('getBmiValue',array('w' => 62,'h' => 167));
third
the thing is because there are two variable? (not sure with term), so it was kept in an array
please dont mind the variable name
$fConversionRate = (float) $result['getBmiValueResult'];
and done and i get my bmi result.

SOAP response by given request and response structure in PHP

As I am pretty new to SOAP I really need some help to get started. I have been given this structur:
request:
POST /NumbriParing/NumbriParing.asmx HTTP/1.1
Host: nba.tja.ee
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://nba.sa.ee/NumriomanikuParing"
<?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>
<NumriomanikuParing xmlns="http://nba.sa.ee/">
<number>long</number>
</NumriomanikuParing>
</soap:Body>
</soap:Envelope>
Response:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?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>
<NumriomanikuParingResponse xmlns="http://nba.sa.ee/">
<NumriomanikuParingResult>
<Number>long</Number>
<OmanikuRegNumber>string</OmanikuRegNumber>
<Omanik>string</Omanik>
<VastusKood>NumberLeitud or NumbritEiLeitud</VastusKood>
</NumriomanikuParingResult>
</NumriomanikuParingResponse>
</soap:Body>
</soap:Envelope>
I need to replace the "long" placeholder in the request with a numeric variable to get the request for that number.
The asmx is located in https://nba.tja.ee/NumbriParing/NumbriParing.asmx
How Can it be done using php?
Best regards,
Martti
Use SoapClient and WSDL of the service you need.
Something like:
try {
$client = new SoapClient('https://nba.tja.ee/NumbriParing/NumbriParing.asmx?WSDL');
$param = new stdClass();
$param->number = 123;
$result = $client->NumriomanikuParing($param);
var_dump($result);
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}

how to call web services using soap in php

The following is a sample SOAP 1.1 request and response.:
POST /atservices/1.5/atws.asmx HTTP/1.1
Host: webservices2.autotask.net
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://autotask.net/ATWS/v1_5/getZoneInfo"
<?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>
<getZoneInfo xmlns="http://autotask.net/ATWS/v1_5/">
<UserName>string</UserName>
</getZoneInfo>
</soap:Body>
</soap:Envelope>
we want to call web services of autotask using soap in php.can we get example for it
how we should call soap client.
Its output should be like this :
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?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>
<getZoneInfoResponse xmlns="http://autotask.net/ATWS/v1_5/">
<getZoneInfoResult>
<URL>string</URL>
<ErrorCode>int</ErrorCode>
<DataBaseType>string</DataBaseType>
<CI>int</CI>
</getZoneInfoResult>
</getZoneInfoResponse>
</soap:Body>
</soap:Envelope>
Use the PHP native SoapClient along with the service WSDL, like so:
$atservices_wsdl = "https://www.autotask.net/atservices/1.5/atws.wsdl";
$atservices_client = new SoapClient($atservices_wsdl);
$zone_info = $atservices_client->getZoneInfo("SomeUserName");
print_r($zone_info); // review the returned object converted from SOAP response.
echo $zone_info->DataBaseType; // this might work if it's not behind a Response object.
At the very least, you should be aiming for something like this. More can be found here.
$soap = new SoapClient('link/to/.wsdl');
$result = $soap->__soapCall('getZoneInfo', array('UserName' => $username));
var_dump($result);

HTTP Request with PHP + NuSoap

I'm trying to create a http request to our web service, my test XML works when directly inputted into the webservices test input field and I click "Invoke", but when trying to use the same data with PHP + NuSoap, I get a peculiar error which I've been unable to solve, I've tried to google for it but nothing relevant shows up for this case.
Here is the Request:
POST /iInterface_pc2/service.asmx HTTP/1.0
Host: 10.10.86.55
User-Agent: NuSOAP/0.9.6dev (1.137)
Content-Type: text/xml; charset=UTF-8
SOAPAction: "http://www.xxxx.com.cn/TransferMaterialInfo"
Content-Length: 722
<?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>
<TransferMaterialInfo xmlns="http://www.xxxx.com.cn/">
<Materiallist>
<Materialinfo>
<id>123456</id>
<title>Hello word</title>
<datetime>2011-04-23 12:12:12</datetime>
<contributor>Some One</contributor>
<materialurl>www.website.com/path/audio1.mp3</materialurl>
<duration>10000</duration>
<status>0</status>
<remark></remark>
</Materialinfo>
</Materiallist>
</TransferMaterialInfo>
</soap:Body>
</soap:Envelope>
And the Response:
HTTP/1.1 500 Internal Server Error
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Thu, 28 Apr 2011 11:04:11 GMT
Connection: close
Content-Length: 428
<?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>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Server was unable to process request. ---> Value cannot be null.
Parameter name: s</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
And finally the PHP I use to generate the request
<?php
// include soap file
require_once('lib/nusoap.php');
// set end point
$endpoint = "http://10.10.86.55/iInterface_pc2/service.asmx";
// create client
$client = new nusoap_client($endpoint);
if ( $client->getError() ) {
print "Soap Constructor Error: ";
print_r($client->getError());
}
// Human readable
$request = <<<HEREDOC
<TransferMaterialInfo xmlns="http://www.xxxx.com.cn/">
<Materiallist>
<Materialinfo>
<id>123456</id>
<title>Hello word</title>
<datetime>2011-04-23 12:12:12</datetime>
<contributor>Some One</contributor>
<materialurl>www.website.com/path/audio1.mp3</materialurl>
<duration>10000</duration>
<status>0</status>
<remark></remark>
</Materialinfo>
</Materiallist>
</TransferMaterialInfo>
HEREDOC;
$action = "http://www.xxxx.com.cn/TransferMaterialInfo";
$msg = $client->serializeEnvelope($request, '', array(), 'document', 'encoded', '');
$result = $client->send($msg, $action);
if ( $client->fault ) { //soap_fault
print "Soap Fault :";
print_r($client->fault->faultcode);
print_r($client->fault->faultstring);
}
elseif ( $client->getError() ) {
print "Soap Error :";
print_r($client->getError());
}
else {
print "Result: ";
print_r($result);
}
..print stuff
?>
Any insights and guesses GREATLY appreciated. I've been banging my head against a brick wall for a good while now. :/
I believe the server is seeing the < and > characters and decoding it to >
You may need to urlencode the data before sending
i am not sure , if that will help you or not , but check it any way
http://mohammed-magdy.blogspot.com/2011/04/creating-web-services-using-php.html
The problem has been solved and was actually caused by faulty ASP code expecting only whitespaces to be html-encoded, resulting in faulty response.

using nusoap returns fault code

making a call to a web service method with nusoap returns an error
array(3) { ["faultcode"]=> string(11) "soap:Client" ["faultstring"]=> string(516) "System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: . at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest() at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message) at System.Web.Services.Protocols.SoapServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)" ["detail"]=> string(0) "" }
is the fault in my calling or with the soap server?
$response = $qes->call('GetXhtml',$url);
var_dump($response);
Above is the call to the function, which accepts 1 parameter ($url) which I have checked as valid.
-------FULL CODE-----
<?php
//include nusoap class
require 'extensions/nusoap/lib/nusoap.php';
//connect to QES
$qes = new nusoap_client("https://www.qes24.com/swindon/ppa/uat/contentserver/contentserver/contentserver.asmx");
$qes->useHTTPPersistentConnection();
$qes->soap_defencoding = 'utf-8';
//check connection
$error = $qes->getError();
//get current page
$curl = curPageURL();//function derives current URL
$furl = $curl."?Type=8AFCCCB9-93DC-421E-A617-92A990EC99A7";
$param = array('url' => $furl);
$response = $qes->call('getXhtml', $param, '','http://tempuri.org/GetXhtml', array('content-type' => 'UTF-8'), true,null,'rpc','literal');
fb::log($response);
// Display the request and response
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($qes->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($qes->response, ENT_QUOTES) . '</pre>';
//*/
The request SHOULD look like this (according to the company providing the service)
POST /swindon/ppa/uat/ContentServer/ContentServer/ContentServer.asmx HTTP/1.1
Host: www.qes24.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/GetXhtml"
<?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>
<GetXhtml xmlns="http://tempuri.org/">
<url> http://localhost/waggleb/?Type=8AFCCCB9-93DC-421E-A617-92A990EC99A7</url>
</GetXhtml>
</soap:Body>
</soap:Envelope>
?>
Actual Full Request made by Nusoap:
POST /swindon/ppa/uat/contentserver/contentserver/contentserver.asmx HTTP/1.1
Host: www.qes24.com
User-Agent: NuSOAP/0.9.5 (1.123)
Connection: close
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tempuri.org/GetXhtml"
Content-Length: 516
<?xml version="1.0" encoding="utf-8"?><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><content-type xsi:type="xsd:string">UTF-8</content-type></SOAP-ENV:Header><SOAP-ENV:Body><url xsi:type="xsd:string">http://localhost/waggleb/?Type=8AFCCCB9-93DC-421E-A617-92A990EC99A7</url></SOAP-ENV:Body></SOAP-ENV:Envelope>
Full response:
HTTP/1.1 200 OK
Date: Mon, 07 Feb 2011 10:50:25 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 329
<?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><GetXhtmlResponse xmlns="http://tempuri.org/"><GetXhtmlResult /></GetXhtmlResponse></soap:Body></soap:Envelope>
From the error that's being returned, I'd guess (but I can't be certain without knowing which API you're trying to use) that the problem is the method name. Perhaps it's cased incorrectly? Either way, this means that the server can't direct your SOAP request to the correct module.

Categories