Home > Uncategorized > Web services with PHP (NuSOAP) & C# Mobile Client

Web services with PHP (NuSOAP) & C# Mobile Client

Hello,
The blog is about how to create web services ? how to make use of those services
by having a mobile client as consumer of those services.

Hoping to start with that reader understand web service if not why not to read it
from here -> http://en.wikipedia.org/wiki/Web_service

Ok hoping! that reader understand about web service and wanted to know how
to create one yet with this simple NuSOAP lib in PHP.
More information about NuSOAP is available here.
-> http://www.scottnichol.com/nusoapintro.htm

After downloading the NuSOAP lib from here
-> http://sourceforge.net/projects/nusoap/
extract it to a place easily remembered path, to later include in your web service.
! Remember to include SOAP in php.ini file.

Soo, here we go on the code part directly. Hey but i forgot to mention my scenario
I have J2SE application collecting information from sensors. The idea is that mobile client can view the selected sensor information. By having web serivce it was really easy to process the request via SOAP/WSDL.

Well the code Part is yet so simple that it doesn’t need any explanation.

webservices.phpcannot find the file (do write me a message; i will try to dig the file from old machine)

save this in your web directory with somename.php The things happen now is that the web service is ready. Now i will go to the mobile interface and actions part
again assuming the reader is known to Visual Studio and Windows Mobile development.

the mobile interface looks like this:
Add the reference to the web service in your .NET project and give it a name. In my case
its Sensorinfo.

E.g adding the web reference it goes like this http://192.168.1.12/somename.php?wsdl
The Mobile code goes like below calling the string value result from web service.

code below for windows mobile
========================================

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace mobile_client
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void menuItem2_Click(object sender, EventArgs e)
{
Application.Exit();
}

private void menuItem1_Click(object sender, EventArgs e)
{
Form1 f1 = new Form1();
f1.Show();

}

private void btnweb1_Click(object sender, EventArgs e)
{
string res = "b";

Cursor.Current = Cursors.WaitCursor;

WebReference.Sensorinfo wasup = new WebReference.Sensorinfo();

//MessageBox.Show(wasup.getNodedata(re));

string reply = wasup.getNodedata(res);

if (reply != null)
{
string s = reply;

string[] srs = reply.Split(new char[] { ',' });

foreach (string t in srs)
{
//display result
tempbox.Text = srs[0];
nodebox.Text = srs[1];
resultbox.Text = srs[2];
lightbox.Text = srs[3];
xdegbox.Text = srs[4];
ydegbox.Text = srs[5];
zdegbox.Text = srs[6];

} //foreach

} //if

Cursor.Current = Cursors.Default;

} //btnweb1

private void textBox2_TextChanged(object sender, EventArgs e)
{

}

private void btnweb3_Click(object sender, EventArgs e)
{
string res = "a";
Cursor.Current = Cursors.WaitCursor;

WebReference.Sensorinfo wasup = new WebReference.Sensorinfo();

//MessageBox.Show(wasup.getNodedata(re));

string reply = wasup.getNodedata(res);

if (reply != null)
{
string s = reply;

string[] srs = reply.Split(new char[] { ',' });

foreach (string t in srs)
{

double d = Double.Parse(srs[0]);
//d = -38.4 +0.0098 (*srs[0]);
double a = -38.4;
double b = 0.0098;
double c = a + b * d;

//display result
tempbox.Text = c.ToString("0.0");

nodebox.Text = srs[1];
resultbox.Text = srs[2];

double valueorg = Double.Parse(srs[3]);
double value1 = 408;
double valuefinal = value1 * valueorg;

//textBox4.Text = srs[3];
lightbox.Text = valuefinal.ToString("00.0000");

//lightbox.Text = srs[3];

xdegbox.Text = srs[4];
ydegbox.Text = srs[5];

zdegbox.Text = srs[6];

} //foreach
} //if

Cursor.Current = Cursors.Default;
}

private void btnweb4_Click(object sender, EventArgs e)
{
string res = "a1";
Cursor.Current = Cursors.WaitCursor;

WebReference.Sensorinfo wasup = new WebReference.Sensorinfo();

//MessageBox.Show(wasup.getNodedata(re));

string reply = wasup.getNodedata(res);

if (reply != null)
{
string s = reply;

string[] srs = reply.Split(new char[] { ',' });

foreach (string t in srs)
{

double d = Double.Parse(srs[0]);
//d = -38.4 +0.0098 (*srs[0]);
double a = -38.4;
double b = 0.0098;
double c = a + b * d;

//display result
tempbox.Text = c.ToString("0.0");

nodebox.Text = srs[1];
resultbox.Text = srs[2];

double valueorg = Double.Parse(srs[3]);
double value1 = 408;
double valuefinal = value1 * valueorg;

//textBox4.Text = srs[3];
lightbox.Text = valuefinal.ToString("00.0000");

//lightbox.Text = srs[3];
xdegbox.Text = srs[4];
ydegbox.Text = srs[5];
zdegbox.Text = srs[6];

} //foreach
} //if
Cursor.Current = Cursors.Default;
}

private void btnweb2_Click(object sender, EventArgs e)
{
string res = "b1";
Cursor.Current = Cursors.WaitCursor;

WebReference.Sensorinfo wasup = new WebReference.Sensorinfo();
//MessageBox.Show(wasup.getNodedata(re));

string reply = wasup.getNodedata(res);
if (reply != null)
{
string s = reply;

string[] srs = reply.Split(new char[] { ',' });

foreach (string t in srs)
{

//display result
tempbox.Text = srs[0];
nodebox.Text = srs[1];
resultbox.Text = srs[2];
lightbox.Text = srs[3];
xdegbox.Text = srs[4];
ydegbox.Text = srs[5];
zdegbox.Text = srs[6];

} //foreach
} //if

Cursor.Current = Cursors.Default;
} //button
}
}

Well nothing more to tell and explain at this moment. NuSOAP was handy and simple to use and it took rather less hours to put my web services as compared with other web service framework.

Have Fun Happy Coding !
 

  1. No comments yet.
  1. No trackbacks yet.

Leave a comment