2006-11-30

WS-AT en .Net framework v3

WS-AT forma parte de “Windows Communication Foundation” (WCF). Por lo visto el soporte de WS-AT debe habilitarse y configurarse en Windows. Para ello hay un panelito que explican en http://blogs.msdn.com/distilled/archive/2006/05/15/598257.aspx

La documentación sobre “Windows Communication Foundation” está en http://msdn2.microsoft.com/en-us/library/aa388579.aspx y, en concreto, la parte en la que hablan de ws-at es http://msdn2.microsoft.com/en-us/library/ms729784.aspx

Al parecer, crear un “servicio” con este nuevo modelo de programación es algo tan sencillo como esto:

El código:

using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;

[ServiceContract]
public interface IEcho
{
[OperationContract]
string Echo(string s);
}

public class MyService : IEcho
{
public string Echo(string s)
{
return s;
}
}

class Program
{
static void Main(string[] args)
{
string baseAddress = "http://localhost:8080/wcfselfhost/";
ServiceHost host = new ServiceHost(typeof(MyService), new Uri(baseAddress));

// Create a BasicHttpBinding instance
BasicHttpBinding binding = new BasicHttpBinding();

// Add a service endpoint using the created binding
host.AddServiceEndpoint(typeof(IEcho), binding, "echo1");

host.Open();
Console.WriteLine("Service listening on {0} . . .", baseAddress);
Console.ReadLine();
host.Close();
}
}

La configuración (web.config o app.config)

<configuration>
<system.serviceModel>
<services>
<service name="MyService" behaviorConfiguration="HttpGetMetadata">
<endpoint address="echo2" contract="IEcho" binding="basicHttpBinding" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="HttpGetMetadata">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

Por cierto, MS ha tenido la amabilidad de desarrollar unas “Visual Studio 2005 extensions for .Net framework 3.0” que supongo que facilitarán el desarrollo de estos “servicios”