Sunday, June 19, 2005

My Simple Indigo Service

Now onto some real infocard work. To begin with, I developed a simple webservice and client using Indigo. This service basically displays the raw SOAP which it is sent:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

//This is the Indigo namespace
using System.ServiceModel;
using System.Xml;

namespace InfoCardService
{
/**
Here, I'm using an interface to define the service contract.
Service contracts are explicit in Indigo, and can be distict
from application/class level contract as seen here.
*/
[ServiceContract]
interface ISimpleService
{
//A very raw service - interface accepts low level message type.
[OperationContract(IsOneWay = true)]
void Receive(System.ServiceModel.Message msg);
}


public partial class SimpleService : Form, ISimpleService
{
//selfhosting ServiceHost using generics to be types to my implementation
ServiceHost sh;

public SimpleService()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)
{
sh.Close();
Application.Exit();
}

public void Receive(System.ServiceModel.Message msg)
{
MessageBox.Show("New Message:\n\n" + msg.ToString());
}

private void Start()
{
sh = new ServiceHost();
sh.Open();
}

static void Main(string[] args)
{
SimpleService service = new SimpleService();
service.Start();
Application.EnableVisualStyles();
Application.Run(service);
}

}
}

No comments: