REST POX WCF

[ServiceContract]
public
interface IRestPox
{

[OperationContract(Action = "*", ReplyAction = "*")]
Message Foo(Message m);
}
public
class Service : IRestPox
{
public Message Foo(Message m)
{
HttpRequestMessageProperty hrmp = m.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
Console.WriteLine("Received {0}: {1}", hrmp.Method, hrmp.QueryString);
return Message.CreateMessage(m.Version, "", "yadda");
}
}
public
class Gateway
{
public static void Main()
{
// pretty page with service information
Uri baseAddress = new Uri(http://localhost:8004/Service);
// programmatic endpoint
Uri endpointAddress = new Uri("http://localhost:8004/Service/Foo");
// launch service
Binding binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.None, Encoding.UTF8), new HttpTransportBindingElement());
ServiceHost service = new ServiceHost(typeof(Service), baseAddress);
service.AddServiceEndpoint(
typeof(IRestPox), binding, endpointAddress);
service.Open();
// console information
Console.WriteLine("Service open at {0} - press a key to continue", baseAddress);
Console.ReadKey();
service.Close();
}
}
Filed under: , ,

Comments

No Comments