• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] how to use SOAP?

Status
Not open for further replies.

Tok124

Respected Member
Hello,

Can anyone please teach me how to use SOAP? i do have some php experience but i have never used SOAP. I need to use it so i can execute GM Commands in worldserver console. All i have found so far is a complete registration script using SOAP. But that looked like a PDO script. I don't know PDO yet. I'm a beginner so i just know normal php code. Can anyone teach me how to setup SOAP from start? Step by step guide, Because i don't know anything at all. I just realized (thanks to rochet2) that it's a bad idea to send the information to database. For example, If i wanna ban a player and execute that from website the player will not be banned until he logout. So please help me out :D
 

Tok124

Respected Member
You need enable SOAP in worlf.conf, then restart the server (not sure is it mandatory). Then you implement your site to use SOAP: http://php.net/manual/en/book.soap.php
Thank you ! Great guide, However... It's a little advanced. But i will take my time to read through the whole page and then just try a littlebit. But is there any chance you could just make a very short and simple script that runs a command in worldserver? So i can get an idea how it should look like? Because i really don't think they explain in the guide how to connect it to my worldserver.exe :p
 

Skrbx

BETA Tester
Here you go:

Code:
//define required shit

$soapUsername = '';
$soapPassword = '';
$soapHost = '';
$soapPort = '';

// define soap instance

$client = new SoapClient(NULL, array(
    'location' => "http://$soapHost:$soapPort/",
    'uri'      => 'urn:SMTNG', //not sure do youneed this
    'style'    => SOAP_RPC,
    'login'    => $soapUsername,
    'password' => $soapPassword,
));

//define command 

$command = "character level Dinduks 70";

//execute

$result = $client->executeCommand(new SoapParam($command, 'command'));

PS: yea also you need a user which have access to the soap rpc.
 

Tok124

Respected Member
Here you go:

Code:
//define required shit

$soapUsername = '';
$soapPassword = '';
$soapHost = '';
$soapPort = '';

// define soap instance

$client = new SoapClient(NULL, array(
    'location' => "http://$soapHost:$soapPort/",
    'uri'      => 'urn:SMTNG', //not sure do youneed this
    'style'    => SOAP_RPC,
    'login'    => $soapUsername,
    'password' => $soapPassword,
));

//define command 

$command = "character level Dinduks 70";

//execute

$result = $client->executeCommand(new SoapParam($command, 'command'));

PS: yea also you need a user which have access to the soap rpc.
Oh, Thanks alot mate ! I really really appreciate it. But what is SOAP rpc?

I tried to run the code just as it is. And i enabled SOAP in worldserver .conf and i set SOAP host to 127.0.0.1 and then i used same account information as i use in database and then i tried to visit the page and i get this error

Code:
Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Client] Method 'ns1:executeCommand' not implemented: method name or namespace not recognized in C:\xampp\htdocs\testing\functions\SOAP.php:25 Stack trace: #0 C:\xampp\htdocs\testing\functions\SOAP.php(25): SoapClient->__call('executeCommand', Array) #1 C:\xampp\htdocs\testing\functions\SOAP.php(25): SoapClient->executeCommand(Object(SoapParam)) #2 {main} thrown in C:\xampp\htdocs\testing\functions\SOAP.php on line 25
 
Last edited:

Skrbx

BETA Tester
No no no, i believe that there is a special permission which have to be gained to the user which will be used fo SOAP connection.
SOAP RPC is SOAP, rpc comes from "Remote Procedure Calls". I am not sure is it correct to say "soap rcp" it just came out like this when i type it. On other hand what i am thinking now is that SOAP use client-server interactions over HTTP/S which is basically an rpc so maybe is not that wrong but this is another topic...
 

Hyperion

Founder
This is a function I had in CraftedWeb, but I only used RA.

Hope it helps
Code:
function sendSoap($command,$username,$password,$host,$soapport)
{
    $client = new SoapClient(NULL,
    array(
    "location" => "http://$host:$soapport/",
    "uri" => "urn:TC",
    "style" => SOAP_RPC,
    'login' => $username,
    'password' => $password
    ));
    try
    {
        $result = $this->$client->executeCommand(new SoapParam($command, "command"));
        echo "Command succeeded! Output:<br />\n";
        echo $result;
    }
    catch (Exception $e)
    {
        echo "Command failed! Reason:<br />\n";
        echo $e->getMessage();
    }
}
 

Tok124

Respected Member
This is a function I had in CraftedWeb, but I only used RA.

Hope it helps
Code:
function sendSoap($command,$username,$password,$host,$soapport)
{
    $client = new SoapClient(NULL,
    array(
    "location" => "http://$host:$soapport/",
    "uri" => "urn:TC",
    "style" => SOAP_RPC,
    'login' => $username,
    'password' => $password
    ));
    try
    {
        $result = $this->$client->executeCommand(new SoapParam($command, "command"));
        echo "Command succeeded! Output:<br />\n";
        echo $result;
    }
    catch (Exception $e)
    {
        echo "Command failed! Reason:<br />\n";
        echo $e->getMessage();
    }
}
Thanks faded, Your script gives no error atleast. But what username and pass do i use? I use same account as i use ingame or i use same account as i use in database or what is soap username and password?

The page is just blank when i visit the page. And yes i made variables and values for the variables for host username pass and command
 
Last edited:

Hyperion

Founder
Thanks faded, Your script gives no error atleast. But what username and pass do i use? I use same account as i use ingame or i use same account as i use in database or what is soap username and password?

The page is just blank when i visit the page. And yes i made variables and values for the variables for host username pass and command

Well yeah, it's just an example. Not to be just copy/pasted and used.
You would define the info like Skrbx showed you above.

Code:
$username = "blah";
$password = "blah";
$host = "127.0.0.1";
$soapport = "soapport";

function sendSoap($command)
{
    $client = new SoapClient(NULL,
    array(
    "location" => "http://$host:$soapport/",
    "uri" => "urn:TC",
    "style" => SOAP_RPC,
    'login' => $username,
    'password' => $password
    ));
    try
    {
        $result = $this->$client->executeCommand(new SoapParam($command, "command"));
        echo "Command succeeded! Output:<br />\n";
        echo $result;
    }
    catch (Exception $e)
    {
        echo "Command failed! Reason:<br />\n";
        echo $e->getMessage();
    }
}

Then you can call the function in your script by using sendSoap(".whatever command");
 

Tok124

Respected Member
Well yeah, it's just an example. Not to be just copy/pasted and used.
You would define the info like Skrbx showed you above.

Code:
$username = "blah";
$password = "blah";
$host = "127.0.0.1";
$soapport = "soapport";

function sendSoap($command)
{
    $client = new SoapClient(NULL,
    array(
    "location" => "http://$host:$soapport/",
    "uri" => "urn:TC",
    "style" => SOAP_RPC,
    'login' => $username,
    'password' => $password
    ));
    try
    {
        $result = $this->$client->executeCommand(new SoapParam($command, "command"));
        echo "Command succeeded! Output:<br />\n";
        echo $result;
    }
    catch (Exception $e)
    {
        echo "Command failed! Reason:<br />\n";
        echo $e->getMessage();
    }
}

Then you can call the function in your script by using sendSoap(".whatever command");
Aah alright. But i still think something is missing since i got those errors

Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Client] Method 'ns1:executeCommand' not implemented: method name or namespace not recognized in C:\xampp\htdocs\testing\functions\SOAP.php:25 Stack trace: #0 C:\xampp\htdocs\testing\functions\SOAP.php(25): SoapClient->__call('executeCommand', Array) #1 C:\xampp\htdocs\testing\functions\SOAP.php(25): SoapClient->executeCommand(Object(SoapParam)) #2 {main} thrown in C:\xampp\htdocs\testing\functions\SOAP.php on line 25

if i go to http://127.0.0.1:7878 i see this
<SOAP-ENV:Fault xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:ns1="urn:TC">
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>HTTP GET method not implemented</faultstring>
</SOAP-ENV:Fault>

I'm not sure if something is wrong there or why i'm getting the error. Like i said. I really don't know anything at all about SOAP :p
 
Last edited:

Hyperion

Founder
What are you using the SOAP for exactly? Because the example I gave you is just for executing commands to the server. It's not a page to display..
 

Tok124

Respected Member
What are you using the SOAP for exactly? Because the example I gave you is just for executing commands to the server. It's not a page to display..
Yeah. I know that it doesnt display a website. But it should atleast display the echo values. I mean like this echo "Command succeeded! Output:<br />\n"; it should atleast show that if the script works or not. I am using SOAP to run commands such as ticket close, ticket del, .ban char, .ban account, .ban ip etc. And i wanna use it in an acp. So when i figure out how all works then i make a html form and set the action to the soap script and then set the variables like this in the soap script
$command = $_POST['command'];
 
Last edited:

Tok124

Respected Member
Webserver meaning Apache
Oh, Well webserver sounds more like a host hehe but alright, Well i'm just using standard configurations that comes when downloading xampp so i don't think i have php-soap setup, How would i fix that?
 

Skrbx

BETA Tester
Apache is HTTP Server (web server).
Xammp uses apache.
Check in phpinfo() from http://localhost that SOAP is indeed included and also the Loaded Configuration File is the one in the apache\bin folder.
<DRIVE>\xampp\php\pear\SOAP is included in XAMPP.
<DRIVE> Could be c: d: or whatever
 

Tok124

Respected Member
phpinfo() page
8XgRRFM.jpg

SOAP Folder
16O4OB3.jpg
 
Last edited:
Status
Not open for further replies.
Top