Bonjour,
J'ai créé un service web d'un coté et une application cliente de l'autre.
En cas d'erreur du service j'aimerai lancer un exception SOAP, que je puisse 'catcher' dans mon application cliente.
voilà ce que je fais côté service :
et côté clientCode:
1
2
3
4
5
6
7
8 [WebMethod] public string Test(string str) { if (string.IsNullOrEmpty(str)) throw new SoapException("str null or empty", SoapException.ClientFaultCode); else return str; }
Le problème c'est que je ne passe jamais dans le premier catch alors que je lève bien une exception SOAP...Code:
1
2
3
4
5
6
7
8
9
10
11
12
13 string str = ""; try { myWS.Test(str) } catch (SoapException soapEx) { //[...] } catch (Exception ex) { //[...] }
Pour info le message de ex (System.Exception {System.ServiceModel.FaultException})
et la réponse du webservice (récupéréé via l'appli test client WCF)Code:
1
2 ex.message = "System.Web.Services.Protocols.SoapException: str null or empty à WebService1.Service1.Test(String str) dans [...]/Service1.asmx.cs:ligne 25"
Code:
1
2
3
4
5
6
7
8
9
10
11 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" /> <soap:Body> <soap:Fault> <faultcode>soap:Client</faultcode> <faultstring>System.Web.Services.Protocols.SoapException: str null or empty à WebService1.Service1.Test(String str) dans ...\Service1.asmx.cs:ligne 25</faultstring> <detail /> </soap:Fault> </soap:Body> </soap:Envelope>
