Archive

Archive for the ‘Programming’ Category

Trend API coming soon

November 19th, 2009 Jon Smith No comments

A while back I started getting interested in site’s that used API’s from several different sources to create what is known as a web mashup. “A mashup is a web page or application that combines data or functionality from two or more external sources to create a new service”Wikipedia. There are plenty of really good examples of web mashups out there, if you are interested check out ProgrammableWeb’s site.

At this time I wrote my own craptacular mashup called The Gob Shite, this site was a mashup of Google’s YouTube, Google’s News feeds and a new API of my own called the TrendEngine. TrendEngine was developed using Google Hot Trends information and provided some level of stability to the constantly changing trend list. It does this by detecting reoccuring trends in the list and applying a weighting formula to them.

Read more…

APNS error – No Valid aps-environment entitlement

July 22nd, 2009 Jon Smith 4 comments

If you get the following error when trying to register for a device token, firstly ensure you have correctly followed the directions within the iPhone Developers Portal.

Error Domain=NSCocoaErrorDomain "no valid 'aps-environment' entitlement string found for application"

Read more…

APNS Send Device Token to Provider

July 14th, 2009 Jon Smith 10 comments

I am currently in the middle of designing and developing an application based on the Apple Push Notification Service. There is alot of information about the client side registration and plenty of server side code examples, but I haven’t found anything that simple demonstrates how to send your device token to the provider service.

Read more…

iPhone Development

July 9th, 2009 Jon Smith 8 comments

For some strange, but unknown reason I decided to purchase a Mac Mini to try some iPhone Development. I have a few apps that I would like on my iPhone that are currently not available.

My first app will be for a Nagios Pager service that will utilise the Push Notification features just released in iPhone OS 3.0. There will be two versions, Nagios Pager and Nagios Pager Pro. Nagios Pager will be a stand alone application that will talk to a backend service for delivering Push Notifications for Nagios alerts, Nagios Pager Pro will contain all the features of Nagios Pager as well as an iPhone based Nagios client.

Read more…

Simple .NET XML Tutorial

May 7th, 2009 Jon Smith No comments

I needed to build an application the other day that used XML to talk to a web service, but I wanted to deal with raw XML rather then using anything based on WSDL and RPC. This was the first time I had written anything that used XML before so I started googling for code examples and tutorials.

There wasn’t much clear documentation out there on exactly what I wanted to do so I ended up using a couple of code examples I found in the end (links provided below for original source) and modifying them for my needs.

The end result is extremely simple to understand (however the information was not easy to find) so I thought I would post the details here in hopes that someone else wanting to do the same thing ends up finding this article rather than searching for hours and not finding exactly what is required. (As an a-side, most of what I found online was regarding using premade XML files, and the generation of XML files and not generating and sending the XML request on the fly). Also I wasted a bit of time because of my lack of knowledge on how various Streams work together, but that is another issue entirely.

The following is code for C# but should apply to other .NET based languages (with an appropriate change of syntax).

Required Namespace Imports

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.IO;
using System.Net;
using System.Threading;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;

Code

WebRequest req = WebRequest.Create("http://URLHERE/WebService");
req.Method = "POST";
req.ContentType = "text/xml";
Stream requestStream = req.GetRequestStream();

XmlTextWriter xml = new XmlTextWriter(requestStream, null);

xml.WriteStartDocument();

// The DocType will be different for most situations, this
// is what works for me.
xml.WriteDocType("Request", null, "somefile.dtd", null);
xml.WriteStartElement("Request");
xml.WriteStartElement("InfoRequest");

// These values could come from any source
xml.WriteElementString("Username", "<>");
xml.WriteElementString("Password", "<
>");
xml.WriteElementString("Info", "something");
xml.WriteEndElement();
xml.WriteEndElement();

// When Close() is called the request is sent to the server
xml.Close();

// Use a WebResponse Component to retrieve the response
WebResponse rsp = req.GetResponse();
XmlTextReader xmlin = new XmlTextReader(rsp.GetResponseStream());

while (xmlin.Read())
{
  if (xmlin.NodeType == XmlNodeType.Element)
  {
    if (xmlin.Name == "Info")
    {
      String info = xmlin.ReadString();

      // Do something with returned data

    }
  }
}

xmlin.Close();
rsp.Close();

There are plenty of useful tutorials out there based on XmlTextReader and XmlTextWriter that can explain how to use them to read and write XML. So I wont cover that here. My biggest problem was finding out how to generate the XML and send it straight to the server without having to save to a file.

References:

Categories: .NET, Programming Tags: , ,