Vous ne pouvez pas le faire:
- services Web SOAP font défauts. Les exceptions sont spécifiques à la plate-forme.
- Lorsqu'une exception n'est pas gérée dans un service Web ASMX, .NET la traduira en une erreur SOAP. Les détails de l'exception ne sont pas sérialisés.
- Dans un client ASMX, une erreur SOAP sera traduite en exception SoapException.
Les services Web ASMX ne prennent pas correctement en charge les pannes SOAP. Il n'y a aucun moyen d'obtenir une exception autre qu'une exception SoapException du côté client.
Encore une autre raison de passer à WCF.
À titre d'exemple de ce que vous ne pouvez pas faire avec ASMX, voici comment fonctionne WCF. WCF vous permet de spécifier, pour chaque opération de service Web qui défauts qu'il peut retourner:
[ServiceContract]
public interface IMyServiceContract
{
[FaultContract(typeof(IntegerZeroFault))]
[FaultContract(typeof(SomeOtherFault))]
[OperationContract]
public string GetSomeString(int someInteger);
}
[DataContract]
public class IntegerZeroFault
{
[DataMember]
public string WhichInteger {get;set;}
}
[DataContract]
public class SomeOtherFault
{
[DataMember]
public string ErrorMessage {get;set;}
}
public class MyService : IMyServiceContract
{
public string GetSomeString(int someInteger)
{
if (someInteger == 0)
throw new FaultException<IntegerZeroFault>(
new IntegerZeroFault{WhichInteger="someInteger"});
if (someInteger != 42)
throw new FaultException<SomeOtherFault>(
new SomeOtherFault{ErrorMessage ="That's not the anaswer"});
return "Don't panic";
}
}
Un client WCF peut alors prendre FaultException<SomeOtherFault>
, par exemple. Lorsque j'ai essayé cela avec un client Java, il a été capable de capturer SomeOtherFault
, que IBM Rational Web Developer a créé pour dériver de la classe Java Exception
.
Il utilise ASMX. Il l'appelle "ASP.NET Web Services" –
Ah ok .. je pensais qu'il utilisait WCF –