Migrar de Servicios Web a WCF
Imaginemos que tenemos desarrollados una serie de servicios web que estan siendo consumidos por una gran diversidad de clientes y quiero realizar la migración de estos servicios a WCF, como puedo hacerlo sin que afecten a esos clientes.
La manera es modficar nuestro servicio web decorandolo con los atributos de WCF pero manteniendo los atributos de Web Services.
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ServiceModel;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ServiceContract(Namespace="http://tempuri.org")]
public class WebService : System.Web.Services.WebService
{
[WebMethod]
[OperationContract]
public string Hola(string nombre)
{
return string.Format("Hola, {0}",nombre);
}
}
En nuestro fichero de configuracion deberemos introducir la sección de WCF.
<system.serviceModel>
<services>
<service name="WebService" behaviorConfiguration="returnFaults">
<endpoint binding="basicHttpBinding" contract="WebService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="returnFaults">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Ahora debemos remapear el BuilProvider de asmx para que use System.ServiceModel.
<system.web>
<compilation debug="true">
<buildProviders>
<remove extension=".asmx"/>
<add extension=".asmx" type="System.ServiceModel.Activation.ServiceBuildProvider, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</buildProviders>
</compilation>
</system.web>
Y ya lo tenemos funcionando con WCF