Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home PHP PHP Call Web Service WSDL Example

PHP Call Web Service WSDL Example

I will show you a simple example about How to use PHP to call an API Web service.

For a demonstration, I use the MessageNetAPI which allows you to send an SMS one way via the MessageNet SMS Gateway.

1. .NET/SOAP information

  • Location: www.messagenet.com.au/dotnet
  • Function: LodgeSMSMessage
  • Description: Lodge SMS message into the MessageNet system. Phonenumber may be nnnn;nnnn;nnnn for multiple messages
  • Arguments:
    • username as string
    • pwd as string
    • phonenumber as string
    • phonemessage as string
  • Returns: <string xmlns=”http://www.messagenet.com.au/dotnet”>Message sent successfully.</string>. Anything else is error.
  • Example: LodgeSMSMessage(user1,password1,61412123456,Test MessageNet)

2. SOAP 1.2 request and response.

Request:

POST /dotnet/lodge.asmx HTTP/1.1
Host: www.messagenet.com.au
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
 
<?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>
    <LodgeSMSMessage xmlns="http://www.messagenet.com.au/dotnet">
      <Username>string</Username>
      <Pwd>string</Pwd>
      <PhoneNumber>string</PhoneNumber>
      <PhoneMessage>string</PhoneMessage>
    </LodgeSMSMessage>
  </soap12:Body>
</soap12:Envelope>

POST /dotnet/lodge.asmx HTTP/1.1 Host: www.messagenet.com.au Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?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> <LodgeSMSMessage xmlns="http://www.messagenet.com.au/dotnet"> <Username>string</Username> <Pwd>string</Pwd> <PhoneNumber>string</PhoneNumber> <PhoneMessage>string</PhoneMessage> </LodgeSMSMessage> </soap12:Body> </soap12:Envelope>

Response:

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
 
<?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>
    <LodgeSMSMessageResponse xmlns="http://www.messagenet.com.au/dotnet">
      <LodgeSMSMessageResult>string</LodgeSMSMessageResult>
    </LodgeSMSMessageResponse>
  </soap12:Body>
</soap12:Envelope>

HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?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> <LodgeSMSMessageResponse xmlns="http://www.messagenet.com.au/dotnet"> <LodgeSMSMessageResult>string</LodgeSMSMessageResult> </LodgeSMSMessageResponse> </soap12:Body> </soap12:Envelope>

3. PHP call MessageNet API Web Service

<?php
	$client = new SoapClient("http://www.messagenet.com.au/dotnet/Lodge.asmx?WSDL");
 
	$phone = "your-mobile-number"; //include country code and area code
 
	$message = "Your SMS message here ...";
 
	$result = $client->LodgeSMSMessage(array(
		"Username" => "your-username",
		"Pwd" => "your-password",
		"PhoneNumber" => $phone,
		"PhoneMessage" => $message
	));
 
	$response_arr = objectToArray($result);
 
	echo "return_code= " . str_replace(";", "", $response_arr["LodgeSMSMessageResult"]);
 
	function objectToArray($d)
	{
		if (is_object($d))
		{
			$d = get_object_vars($d);
		}
 
		if (is_array($d))
		{
			return array_map(__FUNCTION__, $d);
		}
		else
		{
			return $d;
		}
	}
?>

<?php $client = new SoapClient("http://www.messagenet.com.au/dotnet/Lodge.asmx?WSDL"); $phone = "your-mobile-number"; //include country code and area code $message = "Your SMS message here ..."; $result = $client->LodgeSMSMessage(array( "Username" => "your-username", "Pwd" => "your-password", "PhoneNumber" => $phone, "PhoneMessage" => $message )); $response_arr = objectToArray($result); echo "return_code= " . str_replace(";", "", $response_arr["LodgeSMSMessageResult"]); function objectToArray($d) { if (is_object($d)) { $d = get_object_vars($d); } if (is_array($d)) { return array_map(__FUNCTION__, $d); } else { return $d; } } ?>

Note:

  • We’re using PHP SoapClient to call the API Web Service, so you need to enable the libxml PHP extension.
  • As its response is an object (not string) so you need to convert it to an array by using objectToArray function.

Download the PHP call api web service source code.

Jul 26, 2011Hoan Huynh
PHP Convert stdClass Object To Array And Array To stdClass ObjectFind PID (Publisher ID) In Commission Junction
You Might Also Like:
  • Facebook Publish To Wall With Popup Or Dialog And Call Back
  • Call Or Open a web page url by using Windows Task Scheduler or CronJob
  • String To Upper Case In PHP, JavaScript And .Net (CSharp)
  • String To Lower Case In PHP, JavaScript And .Net (CSharp)
  • Get File Mime Type Using PHP
  • Jquery checkbox checked
  • PHP Convert stdClass Object To Array And Array To stdClass Object
  • Get Image Width Height With JQuery And JavaScript
  • Uninstall Windows Service
  • How To Track Website With Multiple Google Analytisc Accounts
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

9 years ago PHPAPI, libxml, LodgeSMSMessage, MessageNetAPI, soap, SoapClient, web service8,353
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
22,485 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
20,284 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
16,043 views
JQuery Allow only numeric characters or only alphabet characters in textbox
13,519 views
C# Read Json From URL And Parse/Deserialize Json
10,066 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Online Payday Loans – Learn How To Make the Most of A Alternative Lending Option
  • Strategies For Buying Photo Editor Software
  • Where to Find the Greatest Free Photo Editor on the Web
  • Custom Research Paper – What’s it So Useful?

  • Getting Bad Credit Paydayloans From a Reputable Source
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (27)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (247)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development