My First Indigo Sample
I've been reading up and playing with the recently released Indigo bits in order to catch up, so here's my very first Indigo Sample, which a is very simple, self-hosting indigo service with the corresponding client, and uses the data contract facilities. It's worth noting that as written, the samples require no app.config file configuration, which is something I was looking into trying to understand how it all fit together. So, here's the code:

Server.cs


//
// Server.cs
//
// Author:
// Tomas Restrepo (tomasr@mvps.org)
//
using System;
using System.Runtime.Serialization;
using System.ServiceModel;
namespace Winterdom.Samples.Indigo.FirstSample
{
[
DataContract(Name="CustomerInfo",
Namespace="urn:schemas-winterdom-com:indigo")
]
public class CustomerInfo
{
private string _name;
private DateTime _memberSince;
[ DataMember ]
public string Name {
get { return _name; }
set { _name = value; }
}
[ DataMember ]
public DateTime MemberSince {
get { return _memberSince; }
set { _memberSince = value; }
}
} // class CustomerInfo
[ ServiceContract ]
public interface ICustomerService
{
[ OperationContract ]
CustomerInfo GetCustomerInfo(int customerId);
} // interface ICustomerService
public class CustomerService : ICustomerService
{
public CustomerInfo GetCustomerInfo(int customerId)
{
CustomerInfo info = new CustomerInfo();
info.Name = "Tomas Restrepo";
info.MemberSince = DateTime.Now.AddYears(-1);
return info;
}
public static void Main()
{
try {
Uri uri = new Uri("http://localhost:8188/CustomerService");
ServiceHost host =
new ServiceHost(uri);
using ( host )
{
WSProfileBinding binding = new WSProfileBinding();
host.AddEndpoint(typeof(ICustomerService), binding);
host.Open();
Console.WriteLine("Hosting...");
Console.ReadLine();
}
} catch ( Exception e ) {
Console.WriteLine(e);
}
}
} // class CustomerService
} // namespace Winterdom.Samples.Indigo.FirstSample

Client.cs


//
// Client.cs
//
// Author:
// Tomas Restrepo (tomasr@mvps.org)
//
using System;
using System.Runtime.Serialization;
using System.ServiceModel;
namespace Winterdom.Samples.Indigo.FirstSample
{
[
DataContract(Name="CustomerInfo",
Namespace="urn:schemas-winterdom-com:indigo")
]
public class MembershipInfo
{
private string _memberName;
private DateTime _memberSince;
[ DataMember(Name="Name") ]
public string MemberName {
get { return _memberName; }
set { _memberName = value; }
}
[ DataMember ]
public DateTime MemberSince {
get { return _memberSince; }
set { _memberSince = value; }
}
} // class MembershipInfo
[ ServiceContract ]
public interface ICustomerService
{
[ OperationContract ]
MembershipInfo GetCustomerInfo(int customerId);
} // interface ICustomerService
public class CustomerServiceProxy :
ProxyBase,
ICustomerService
{
public CustomerServiceProxy(EndpointAddress epa, Binding binding)
: base(epa, binding)
{
}
public MembershipInfo GetCustomerInfo(int customerId)
{
return base.InnerProxy.GetCustomerInfo(customerId);
}
} // class CustomerServiceProxy
public class ClientApp
{
public static void Main()
{
try {
Uri uri = new Uri("http://localhost:8188/CustomerService");
EndpointAddress epa = new EndpointAddress(uri);
WSProfileBinding binding = new WSProfileBinding();
CustomerServiceProxy proxy =
new CustomerServiceProxy(epa, binding);
MembershipInfo info = proxy.GetCustomerInfo(12);
Console.WriteLine (
"Customer '{0}' is a member since '{1}'",
info.MemberName, info.MemberSince
);
} catch ( Exception e ) {
Console.WriteLine(e);
}
}
} // class ClientApp
} // namespace Winterdom.Samples.Indigo.FirstSample


Tomas Restrepo

Software developer located in Colombia. Sr. PFE at Microsoft.