Soap is really simple protocol specification, used for exchanging structured information in the implementation of web service.
It is depend on XML(Extensible Markup Language) for its message format.
To enable SOAP on windows server, open php.ini file , find “soap” & enable extension named “extension=php_soap.dll” , i mean , remove “;” before that statement, save file , restart WAMP server & you are done, SOAP is now enable , you can check in your phpinfo().
SOAP provides a way to communicate between applications running on different operating systems, with different technologies and programming languages.
Here , i am going to describe how you can use SOAP with PHP.
Download latest nusoap.php file
Create one server file named soap_server.php
<?php require_once("nusoap.php"); $server = new soap_server(); $server->configureWSDL("Testing WSDL ","urn:Testing WSDL "); $server->register("gethelloworld",array("name" => "xsd:string"),array("return" => "xsd:string"),"urn:helloworld","urn:helloworld#gethelloworld"); function gethelloworld($name) { $myname = "My Name Is <b>".$name . "</b>"; return $myname; } $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; $server->service($HTTP_RAW_POST_DATA); ?>
3. Create one client file named helloworld.php
<?php include("nusoap.php"); $client = new soapclient("http://localhost/soap/soap_server.php?wsdl"); $result = $client->gethelloworld("Milap Patel"); echo "<pre>"; print_r($result); echo "</pre>"; ?>
Hello ,
Any one implement nusoap in cake php. I am implementing it on cakephp it not working properly it return empty XML . Same code are working properly in Without using Cakephp.
If any one using it in cakephp please provide the solution for it. In Cakephp i have got following error.
error in msg parsing:
xml was empty, didn’t parse!
LikeLike
Can you show your code ? what you have tried ?
LikeLike
can you help me out ?
LikeLike
@Harish, Tell me !!!
LikeLike
Hello Milap
Nigam is here
I face one issue for SOAP as below
Fatal error: Uncaught SoapFault exception: [Client] Function (“gethelloworld”) is not a valid method for this service in C:\wamp\www\SOAP\client.php:4 Stack trace: #0 [internal function]: SoapClient->__call(‘gethelloworld’, Array) #1 C:\wamp\www\SOAP\client.php(4): SoapClient->gethelloworld(‘Milap Patel’) #2 {main} thrown in C:\wamp\www\SOAP\client.php on line 4
can you please help me out for it ?
Thanks
Nigam Mehta
LikeLike
Hello Nigambhai,
I resolved it.
Just check updated code.
Need to change the declaration of your client object. You have to pass complete path of your soap_server.php file as below.
$client = new soapclient(“http://localhost/soap/soap_server.php?wsdl”);
Done..!!! Let me know if its working or not…!!! 🙂
LikeLike
I dont know if you are going to read this but I just can’t
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn’t load from ‘localhost/server.php?wsdl’ : failed to load external entity
on the client side the server seems to be working but the client is killing me!
LikeLike
Hi Omar,
Where is server.php file? Is it at same directory level with client file? You can pass like this.
$client = new soapclient(“localhost/soap_server.php?wsdl”);
Let me know if you still have problem.
Thanks
LikeLike
yaar kamaal ka example h.. but kaafi googling krne k baad mila..
Great Thanks.
LikeLike
Client error.
PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn’t load from ‘soap_server.php?wsdl’ : failed to load external entity “soap_server.php?wsdl”
LikeLike
You have to create client as shown below.
$client = new soapclient(“http://127.0.0.1/soap_server.php?wsdl”);
You have to give complete URL before soap_server.php?wsdl”.
LikeLike
Really useful post,since am new to soap.i want to mention the small correction in ur code,
$client = new soapclient(“http://127.0.0.1/soap_server.php?wsdl”);
should be like this.hope it helps u
LikeLike
hey,
I think the argument in the soapclient is self-explanatory.
anyway, thanks for your feedback. 🙂
LikeLike
Array
(
[faultcode] => SOAP-ENV:Client
[faultactor] =>
[faultstring] => error in msg parsing:
xml was empty, didn’t parse!
[detail] =>
)
i am gettting this error please help me solve it. i am beginning to get frustrated.
LikeLike
please show me your sample code.. so i can help you..
LikeLike
the server instance
am using codeigniter framework
function index(){
require_once(APPPATH.’libraries/lib/nusoap’.EXT);
// $debug = 1;
$server=new nusoap_server;
$server->configureWSDL(“TMS web service “,”urn:Tms webservices “);
$server->register(“gethelloworld”,array(“name” => “xsd:string”),array(“return” => “xsd:string”),”urn:helloworld”,”urn:helloworld#gethelloworld”);
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ”;
$server->service($HTTP_RAW_POST_DATA);
}
the client
function test_soap(){
require_once(APPPATH.’libraries/lib/nusoap’.EXT); //includes nusoap
$client = new nusoap_client(“http://127.0.0.1/liveterminals/transrecord/?wsdl”);
$result = $client->call(“gethelloworld”,array(“name”=>”alex”));
echo “
“;
print_r($result);
echo ”
“;
echo ‘Request’;
echo ‘
‘ . htmlspecialchars($client->request, ENT_QUOTES) . ‘
‘;
echo ‘Response’;
echo ‘
‘ . htmlspecialchars($client->response, ENT_QUOTES) . ‘
‘;
}
so when i access the test_soap page i got something like this
Array
(
[faultcode] => SOAP-ENV:Client
[faultactor] =>
[faultstring] => error in msg parsing:
xml was empty, didn’t parse!
[detail] =>
)
pls help me
LikeLike
I think the client should look like this
$client = new soapclient(“http://localhost/soap/soap_server.php?wsdl”);
$result = $client->call(‘gethelloworld’, array(‘name’ => ‘alex’));
LikeLike
Yes Alex,
You have to pass the URL of your wsdl in argument of SOAP client.
LikeLike