Imports System.ServiceModel
Imports System.ServiceModel.Activation
Imports System.Runtime.Serialization

<ServiceContract(Namespace:="http://websol.aut.uah.es/ServiciosWeb/")>
<SilverLightFaultBehavior()>
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)>
Public Class ServicioWCFConverTemps

  <OperationContract()>
  Public Function ConvCentAFahr(gCent As Double) As Double
    Dim grados As Double = Math.Round(9.0 / 5.0 * gCent + 32.0, 2)
    Return grados
  End Function

  <OperationContract()>
  Public Function ConvFahrACent(gFahr As Double) As Double
    Dim grados As Double = Math.Round(((gFahr - 32.0) * 5.0) / 9.0, 2)
    Return grados
  End Function

  <OperationContract()>
  Public Function ResultadoDetallado(detalle As Detalles) As Detalles
    If detalle Is Nothing Then
      Throw New ArgumentNullException("detalle")
    End If
    If detalle.SonCentigrados Then
      detalle.Literal = ConvCentAFahr(detalle.Grados) &
        " grados fahrenheit."
    Else
      detalle.Literal = ConvFahrACent(detalle.Grados) &
        " grados centígrados."
    End If
    Return detalle
  End Function

End Class

<DataContract(Namespace:="http://websol.aut.uah.es/ServiciosWeb/")>
Public Class Detalles
  Private _sonCentigrados As Boolean
  Private _literal As String
  Private _grados As Double

  <DataMember()>
  Public Property SonCentigrados() As Boolean
    Get
      Return _sonCentigrados
    End Get
    Set(value As Boolean)
      _sonCentigrados = value
    End Set
  End Property

  <DataMember()>
  Public Property Literal() As String
    Get
      Return _literal
    End Get
    Set(value As String)
      _literal = value
    End Set
  End Property

  <DataMember()>
  Public Property Grados() As Double
    Get
      Return _grados
    End Get
    Set(value As Double)
      _grados = value
    End Set
  End Property
End Class
