I'll try to give step by step description on how to use the Frontur Webservice API. In this first tutorial I'll be using Visual C# Express to connect to the webservice. If you use VB.Net you should be familiar with what's happening.
The next tutorial I'll use Java and the Intellij IDEA from Jetbrains.com, this is the only IDE that I have ever liked so I recomend it.
The first step is to register on one of our websites. Since this is in english I'll go to babyworld.net and pick my self a username and password and type in my email. You don't have to write any baby. Then click Save. Next I click on API at the bottom of the page. There I'll get a litle description of what is possible. If needed I'll add more information.
Now click on My keys & Apps, this is where you can apply for a key. Type in your name and email. If you are going to write a web application you need to type in the Url. Select the application type, give it some name and description. The name of the application and description isn't important at this point. Right now we don't want to show the application on the public website since we are just trying this out. Check the terms box and click Save. [figure1]
This will give us a API key that we can use in our application, see [figure 2]
Now it's time to fire up Visual C# Express and create a new Window Application, I'll name it MyLatestPictures [figure 3]. I create a private variable called apiKey. [figure 4] Next we'll create a new web reference(Project -> Add Web Reference). We are going to use the the DataStorage webservice. This is where you can retrieve all files from our system. The path to the webservice is http://babyworld.net/dev/DataStorage.asmx as you can see if you go to http://babyworld.net/dev/ the WSDL file for that webservice is http://babyworld.net/dev/DataStorage.asmx?WSDL
So we will use that URL and paste it into the Add Web Reference window [figure 5]. We click the Add reference button.
Next we go into the Window Designer and setup few controls on that form. I have 3 pictureboxes, two buttons and one lable. [figure 6].
This is the code in form, the names of the controls are: lblTotalImages; button1; button2; currentPicture; prevPicture; nextPicture
public partial
class Form1
: Form {
//You'll need a new api key, this
one doesn't work
private
string
apiKey = "4717046c-9974-45ba-88b3-ad5a5d7fe6ca";
private
FolderFile[]
files = null;
private
int
currentPosition = 0;
public
Form1() {
InitializeComponent();
//Create
instance of the DataStorage object that the webservice provides
DataStorage
ds = new
DataStorage();
//We
retrieve 10 last files from websiteId 27733, the password is empty
//the
websiteId is the path to the website. E.g.
http://babyworld.net/baby/123,
//http://barnaland.is/barn/123.
WebsiteId should always be available to test
//this
application or others. If you don't know the websiteId you can use
//http://babyworld.net/dev/website.asmx
to look it up.
files
= ds.GetLatestFilesOnWebsite(27733, 10, "",
apiKey);
//Just
setting some text
lblTotalImages.Text = "There
are total of " + files.Length + "
files retrieved";
//Disable the
previous button, this is the first picture so there is
//no
previous picture
button2.Enabled = false;
//load
current picture (the big one)
for
(int i = 0;
i < files.Length; i++) {
if
(IsPicture(files[i].FileName)) {
LoadImage(currentPicture, files[i].Path);
currentPosition = i;
i = files.Length;
}
}
//lets load a
thumbnail into the nextPicture PictureBox
LoadNextPicture();
}
private
void
button1_Click(object
sender, EventArgs
e) {
if
(currentPosition+1 >= files.Length) button1.Enabled = false;
button2.Enabled = true;
//load
current picture (the big one)
for
(int i =
currentPosition + 1; i < files.Length; i++) {
if
(IsPicture(files[i].FileName)) {
LoadImage(currentPicture, files[i].Path);
currentPosition = i;
i = files.Length;
}
}
LoadNextPicture();
LoadPrevPicture();
}
private
void
button2_Click(object
sender, EventArgs
e) {
if
(currentPosition-1 <= 0) button2.Enabled = false;
button1.Enabled = true;
//load
current picture (the big one)
for
(int i =
currentPosition - 1; i > -1; i--) {
if
(IsPicture(files[i].FileName)) {
LoadImage(currentPicture, files[i].Path);
currentPosition = i;
i = -1;
}
}
LoadNextPicture();
LoadPrevPicture();
}
/**
* Loads the picture from the domain into the application
*/
private
void
LoadImage(PictureBox
box, string
path) {
WebRequest
wr = WebRequest.Create("http://babyworld.net/"
+ path);
using
(WebResponse
webResponse = wr.GetResponse()) {
box.Image =
Image.FromStream(webResponse.GetResponseStream(),
false);
}
}
/**
* Check if this fileName ends on a picture extension
*/
private
bool
IsPicture(string
fileName) {
return
(Path.GetExtension(fileName)
== ".jpg"
||
Path.GetExtension(fileName)
== ".jpeg"
||
Path.GetExtension(fileName)
== ".gif"
||
Path.GetExtension(fileName)
== ".png");
}
/***
* Loads the previous picture thumbnail into the previous
picture box
*/
private
void
LoadPrevPicture() {
//load prev
picture
for
(int i =
currentPosition - 1; i > -1; i--) {
if
(IsPicture(files[i].FileName)) {
LoadImage(prevPicture,
files[i].ThumbnailPath);
i = -1;
}
}
}
/***
* Loads the next picture thumbnail into the next picture
box
*/
private
void
LoadNextPicture() {
//load next
picture
for
(int i =
currentPosition + 1; i < files.Length; i++) {
if
(IsPicture(files[i].FileName)) {
LoadImage(nextPicture,
files[i].ThumbnailPath);
i = files.Length;
}
}
}
}
}
You can get the project here If you have any questions please post it into our forum on frontur.com or post in the comments below or send me an email. Also, you get a 16GB account if you are using any of our webservices for free for life (or at least while the application works)