HTTP Request with PHP + NuSoap - php

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.

Related

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);

Transport level information does not match with SOAP Message namespace URI in PHP nusoap

I'm getting following error response while I subscribe to service. Transport level information does not match with SOAP Message namespace URI
Response :
HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
X-Powered-By: Servlet 2.4; JBoss-4.0.5.GA (build: CVSTag=Branch_4_0 date=200610162339)/Tomcat-5.5
X-UA-Compatible: IE=EmulateIE7
Set-Cookie: JSESSIONID=ED9D677679699927EC1C9CBACE00B7BA.server2; Path=/
Content-Type: text/xml;charset=utf-8
Transfer-Encoding: chunked
Date: Fri, 25 Oct 2013 07:17:58 GMT
Connection: close
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsa:ReplyTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/none</wsa:Address>
</wsa:ReplyTo>
<wsa:MessageID>urn:uuid:C8F752B9E879AE5333138268547859511312499</wsa:MessageID>
<wsa:Action>http://www.w3.org/2005/08/addressing/soap/fault</wsa:Action>
</soapenv:Header>
<soapenv:Body>
<soapenv:Fault>
<faultcode/>
<faultstring>Transport level information does not match with SOAP Message namespace URI</faultstring>
<detail/>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
Here is my php code. I have used nusoap
require_once('lib/nusoap.php');
// Load SOAP URL
$client = new nusoap_client('http://192.168.1.34:1212/services/MYInterfaceTestingMgrService?wsdl','wsdl');
$client->soap_defencoding = 'utf-8';
$client->useHTTPPersistentConnection(); // Uses http 1.1 instead of 1.0
$soapaction = 'RemoveAppendantProduct'; // Load SOAP Action
// soap message
$request_xml = <<<SOAPXML
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:bus="http://www.xyz.com/bme/cbsinterface/cbs/businessmgrmsg"
xmlns:com="http://www.xyz.com/bme/cbsinterface/common"
xmlns:bus1="http://www.xyz.com/bme/cbsinterface/cbs/businessmgr">
<soap:Header/>
<soap:Body>
<bus:RemoveAppendantProductRequestMsg>
<RequestHeader>
<com:CommandId>RemoveAppendantProduct</com:CommandId>
<com:Version>xx</com:Version>
<com:TransactionId/>
<com:SequenceId>xx</com:SequenceId>
<com:RequestType>Event</com:RequestType>
<com:SessionEntity>
<com:Name>$xyz_Name</com:Name>
<com:Password>$xyz_Password</com:Password>
<com:RemoteAddress/>
</com:SessionEntity>
<com:SerialNo>$xyz_ser_no</com:SerialNo>
</RequestHeader>
<RemoveAppendantProductRequest>
<bus1:SubscriberNo>$xyzr_sub_id</bus1:SubscriberNo>
<bus1:Product>
<bus1:ProductID>$xyz_id</bus1:ProductID>
<bus1:ValidMode>123456</bus1:ValidMode>
<bus1:ExpireDate>$xyz_eff_date</bus1:ExpireDate>
</bus1:Product>
</RemoveAppendantProductRequest>
</bus:RemoveAppendantProductRequestMsg>
</soap:Body>
</soap:Envelope>
SOAPXML;
$err = $client->getError();
if ($err) {
echo 'Constructor error' . $err;
}
$result = $client->send($request_xml, $soapaction, ''); // passing soap message via soap php client
Pls let me know how to resolve this issue.

send xml using nusoap

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?

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